From a5e2979a5f3d9fcbdcc9ba0f4042f8f604921774 Mon Sep 17 00:00:00 2001 From: Arthur Diniz Date: Fri, 15 Nov 2024 16:59:35 +0000 Subject: [PATCH] fix: enforce int64 for large integer values in tests - Updated test cases in `goyaml.v2` and `goyaml.v3` `decode_test.go` to explicitly use `int64` for representing large integer values. - Adjusted `yaml_test.go` to: - Use `int64` for `math.MaxInt64` in marshaling tests. - Decode integers greater than `2^53` into `int64` instead of `int` to ensure proper handling of large values. These changes address potential issues with integer overflow and ensure compatibility across platforms with differing integer size representations. Signed-off-by: Arthur Diniz --- goyaml.v2/decode_test.go | 2 +- goyaml.v3/decode_test.go | 2 +- yaml_test.go | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/goyaml.v2/decode_test.go b/goyaml.v2/decode_test.go index ce3ae0b..37a7d9f 100644 --- a/goyaml.v2/decode_test.go +++ b/goyaml.v2/decode_test.go @@ -131,7 +131,7 @@ var unmarshalTests = []struct { map[string]interface{}{"bin": -42}, }, { "bin: -0b1000000000000000000000000000000000000000000000000000000000000000", - map[string]interface{}{"bin": -9223372036854775808}, + map[string]interface{}{"bin": int64(-9223372036854775808)}, }, { "decimal: +685_230", map[string]int{"decimal": 685230}, diff --git a/goyaml.v3/decode_test.go b/goyaml.v3/decode_test.go index c2f7888..930fe1f 100644 --- a/goyaml.v3/decode_test.go +++ b/goyaml.v3/decode_test.go @@ -177,7 +177,7 @@ var unmarshalTests = []struct { map[string]interface{}{"bin": -42}, }, { "bin: -0b1000000000000000000000000000000000000000000000000000000000000000", - map[string]interface{}{"bin": -9223372036854775808}, + map[string]interface{}{"bin": int64(-9223372036854775808)}, }, { "decimal: +685_230", map[string]int{"decimal": 685230}, diff --git a/yaml_test.go b/yaml_test.go index 00cb371..489d5f0 100644 --- a/yaml_test.go +++ b/yaml_test.go @@ -183,7 +183,7 @@ type MarshalTest struct { func TestMarshal(t *testing.T) { f32String := strconv.FormatFloat(math.MaxFloat32, 'g', -1, 32) s := MarshalTest{"a", math.MaxInt64, math.MaxFloat32} - e := []byte(fmt.Sprintf("A: a\nB: %d\nC: %s\n", math.MaxInt64, f32String)) + e := []byte(fmt.Sprintf("A: a\nB: %d\nC: %s\n", int64(math.MaxInt64), f32String)) y, err := Marshal(s) if err != nil { @@ -411,8 +411,8 @@ func TestUnmarshal(t *testing.T) { // decoding integers "decode 2^53 + 1 into int": { encoded: []byte("9007199254740993"), - decodeInto: new(int), - decoded: 9007199254740993, + decodeInto: new(int64), + decoded: int64(9007199254740993), }, "decode 2^53 + 1 into interface": { encoded: []byte("9007199254740993"),