From b4fe0c2a1d4fb5600e149168ae4fcc80626ac915 Mon Sep 17 00:00:00 2001 From: Julien Rische Date: Fri, 29 Apr 2022 19:26:42 +0200 Subject: [PATCH] Fix large literals type inference on 32 bits Some tests are failing because some large literal integers are meant to be stored on 64 bits, but are stored on 32 on 32 bits architectures. This causes the value to overflow. This commit fixes this issue by using explicit int64 typing. Signed-off-by: Julien Rische --- decode_test.go | 9 ++++++--- encode_test.go | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/decode_test.go b/decode_test.go index fb13b9a..fee8e7b 100644 --- a/decode_test.go +++ b/decode_test.go @@ -27,6 +27,9 @@ type Child struct { } func TestDecoder(t *testing.T) { + var in9223372036854775808 int64 = -9223372036854775808 + var u4294967296 uint64 = 4294967296 + var i4294967296 int64 = 4294967296 tests := []struct { source string value interface{} @@ -89,7 +92,7 @@ func TestDecoder(t *testing.T) { }, { "v: -0b1000000000000000000000000000000000000000000000000000000000000000", - map[string]interface{}{"v": -9223372036854775808}, + map[string]interface{}{"v": in9223372036854775808}, }, { "v: 0xA", @@ -109,7 +112,7 @@ func TestDecoder(t *testing.T) { }, { "v: 4294967296\n", - map[string]int{"v": 4294967296}, + map[string]int64{"v": i4294967296}, }, { "v: 0.1\n", @@ -200,7 +203,7 @@ func TestDecoder(t *testing.T) { map[string]uint{"v": 42}, }, { "v: 4294967296", - map[string]uint64{"v": 4294967296}, + map[string]uint64{"v": u4294967296}, }, // int diff --git a/encode_test.go b/encode_test.go index 0a6f1fe..274ea5a 100644 --- a/encode_test.go +++ b/encode_test.go @@ -18,6 +18,7 @@ var zero = 0 var emptyStr = "" func TestEncoder(t *testing.T) { + var i4294967296 int64 = 4294967296 tests := []struct { source string value interface{} @@ -65,7 +66,7 @@ func TestEncoder(t *testing.T) { }, { "v: 4294967296\n", - map[string]int{"v": 4294967296}, + map[string]int64{"v": i4294967296}, nil, }, {