@@ -37,6 +37,26 @@ func strPtr(str string) *string {
3737 return & str
3838}
3939
40+ // newIntPtr returns a pointer to a new int or int64 based on architecture.
41+ // On 64-bit platforms, it returns *int to test unsized int behavior.
42+ // On 32-bit platforms, it returns *int64 to test the large value that doesn't fit in 32-bit int.
43+ func newIntPtr () interface {} {
44+ if strconv .IntSize == 64 {
45+ return new (int )
46+ }
47+ return new (int64 )
48+ }
49+
50+ // expectedIntValue returns the expected decoded value for architecture-specific int tests.
51+ // On 64-bit platforms, it returns the value as int.
52+ // On 32-bit platforms, it returns the value as int64 since the large value doesn't fit in 32-bit int.
53+ func expectedIntValue (value int64 ) interface {} {
54+ if strconv .IntSize == 64 {
55+ return int (value )
56+ }
57+ return value
58+ }
59+
4060type errorType int
4161
4262const (
@@ -183,7 +203,7 @@ func TestMarshal(t *testing.T) {
183203 f32String := strconv .FormatFloat (math .MaxFloat32 , 'g' , - 1 , 32 )
184204 f64String := strconv .FormatFloat (math .MaxFloat64 , 'g' , - 1 , 64 )
185205 s := MarshalTest {"a" , math .MaxInt64 , math .MaxFloat32 , math .MaxFloat64 }
186- e := []byte (fmt .Sprintf ("A: a\n B: %d\n C: %s\n D: %s\n " , math .MaxInt64 , f32String , f64String ))
206+ e := []byte (fmt .Sprintf ("A: a\n B: %d\n C: %s\n D: %s\n " , int64 ( math .MaxInt64 ) , f32String , f64String ))
187207
188208 y , err := Marshal (s )
189209 if err != nil {
@@ -409,10 +429,15 @@ func TestUnmarshal(t *testing.T) {
409429 },
410430
411431 // decoding integers
412- "decode 2^53 + 1 into int" : {
432+ "decode 2^53 + 1 into int64" : {
433+ encoded : []byte ("9007199254740993" ),
434+ decodeInto : new (int64 ),
435+ decoded : int64 (9007199254740993 ),
436+ },
437+ "decode 2^53 + 1 into int (architecture-specific)" : {
413438 encoded : []byte ("9007199254740993" ),
414- decodeInto : new ( int ),
415- decoded : 9007199254740993 ,
439+ decodeInto : newIntPtr ( ),
440+ decoded : expectedIntValue ( 9007199254740993 ) ,
416441 },
417442 "decode 2^53 + 1 into interface" : {
418443 encoded : []byte ("9007199254740993" ),
0 commit comments