@@ -50,8 +50,6 @@ import (
50
50
"sync/atomic"
51
51
"testing"
52
52
"time"
53
-
54
- gocmp "github.com/google/go-cmp/cmp"
55
53
)
56
54
57
55
func init () {
@@ -533,6 +531,10 @@ func testSetupWithChecks(t *testing.T, _ *Handle, allowParallel bool) (fn func()
533
531
return
534
532
}
535
533
534
+ func testEqualFlex (v1 , v2 interface {}) error {
535
+ return testEqualOpts (v1 , v2 , false , testStructsWithStructInfoField )
536
+ }
537
+
536
538
func testCodecEncode (ts interface {}, bsIn []byte , fn func ([]byte ) * bytes.Buffer , h Handle , useMust bool ) (bs []byte , err error ) {
537
539
return testSharedCodecEncode (ts , bsIn , fn , h , useMust )
538
540
}
@@ -550,7 +552,7 @@ func testCheckErr(t *testing.T, err error) {
550
552
551
553
func testCheckEqual (t * testing.T , v1 interface {}, v2 interface {}, desc string ) {
552
554
t .Helper ()
553
- if err := testEqual (v1 , v2 ); err != nil {
555
+ if err := testEqualFlex (v1 , v2 ); err != nil {
554
556
t .Logf ("Not Equal: %s: %v" , desc , err )
555
557
if testv .Verbose {
556
558
t .Logf ("\t v1: %v, v2: %v" , v1 , v2 )
@@ -922,7 +924,7 @@ func testUnmarshalErr(v interface{}, data []byte, h Handle, t *testing.T, name s
922
924
923
925
func testDeepEqualErr (v1 , v2 interface {}, t * testing.T , name string ) {
924
926
t .Helper ()
925
- testDeepEqual4Err (v1 , v2 , t , name , testEqual (v1 , v2 ))
927
+ testDeepEqual4Err (v1 , v2 , t , name , testEqualFlex (v1 , v2 ))
926
928
}
927
929
928
930
func testDeepEqualErrHandle (v1 , v2 interface {}, h Handle , t * testing.T , name string ) {
@@ -1092,7 +1094,7 @@ func testCodecTableOne(t *testing.T, testNil bool, h Handle,
1092
1094
}
1093
1095
continue
1094
1096
}
1095
- if err = testEqual (v0check , v1 ); err == nil {
1097
+ if err = testEqualFlex (v0check , v1 ); err == nil {
1096
1098
if testv .Verbose {
1097
1099
t .Logf ("++++++++ Before and After marshal matched\n " )
1098
1100
}
@@ -1242,15 +1244,15 @@ func doTestCodecMiscOne(t *testing.T, h Handle) {
1242
1244
1243
1245
testCheckEqual (t , p , p2 , "p=p2" )
1244
1246
testCheckEqual (t , m , m2 , "m=m2" )
1245
- if err = testEqual (p , p2 ); err == nil {
1247
+ if err = testEqualFlex (p , p2 ); err == nil {
1246
1248
if testv .Verbose {
1247
1249
t .Logf ("p and p2 match" )
1248
1250
}
1249
1251
} else {
1250
1252
t .Logf ("Not Equal: %v. p: %v, p2: %v" , err , p , p2 )
1251
1253
t .FailNow ()
1252
1254
}
1253
- if err = testEqual (m , m2 ); err == nil {
1255
+ if err = testEqualFlex (m , m2 ); err == nil {
1254
1256
if testv .Verbose {
1255
1257
t .Logf ("m and m2 match" )
1256
1258
}
@@ -1396,7 +1398,7 @@ func doTestCodecChan(t *testing.T, h Handle) {
1396
1398
for j := range ch2 {
1397
1399
sl2 = append (sl2 , j )
1398
1400
}
1399
- if err := testEqual (sl1 , sl2 ); err != nil {
1401
+ if err := testEqualFlex (sl1 , sl2 ); err != nil {
1400
1402
t .Logf ("FAIL: Not Match: %v; len: %v, %v" , err , len (sl1 ), len (sl2 ))
1401
1403
if testv .Verbose {
1402
1404
t .Logf ("sl1: %#v, sl2: %#v" , sl1 , sl2 )
@@ -1429,7 +1431,7 @@ func doTestCodecChan(t *testing.T, h Handle) {
1429
1431
// t.Logf(">>>> from chan: is nil? %v, %v", j == nil, j)
1430
1432
sl2 = append (sl2 , j )
1431
1433
}
1432
- if err := testEqual (sl1 , sl2 ); err != nil {
1434
+ if err := testEqualFlex (sl1 , sl2 ); err != nil {
1433
1435
t .Logf ("FAIL: Not Match: %v; len: %v, %v" , err , len (sl1 ), len (sl2 ))
1434
1436
if testv .Verbose {
1435
1437
t .Logf ("sl1: %#v, sl2: %#v" , sl1 , sl2 )
@@ -1460,7 +1462,7 @@ func doTestCodecChan(t *testing.T, h Handle) {
1460
1462
for j := range ch2 {
1461
1463
sl2 = append (sl2 , j )
1462
1464
}
1463
- if err := testEqual (sl1 , sl2 ); err != nil {
1465
+ if err := testEqualFlex (sl1 , sl2 ); err != nil {
1464
1466
t .Logf ("FAIL: Not Match: %v; len: %v, %v" , err , len (sl1 ), len (sl2 ))
1465
1467
t .FailNow ()
1466
1468
}
@@ -1488,7 +1490,7 @@ func doTestCodecChan(t *testing.T, h Handle) {
1488
1490
for j := range ch2 {
1489
1491
sl2 = append (sl2 , j )
1490
1492
}
1491
- if err := testEqual (sl1 , sl2 ); err != nil {
1493
+ if err := testEqualFlex (sl1 , sl2 ); err != nil {
1492
1494
t .Logf ("FAIL: Not Match: %v; len: %v, %v" , err , len (sl1 ), len (sl2 ))
1493
1495
t .FailNow ()
1494
1496
}
@@ -1724,7 +1726,7 @@ func doTestStdEncIntf(t *testing.T, h Handle) {
1724
1726
e .MustEncode (a [0 ])
1725
1727
d := NewDecoderBytes (b , h )
1726
1728
d .MustDecode (a [1 ])
1727
- if err := testEqual (a [0 ], a [1 ]); err == nil {
1729
+ if err := testEqualFlex (a [0 ], a [1 ]); err == nil {
1728
1730
if testv .Verbose {
1729
1731
t .Logf ("++++ Objects match" )
1730
1732
}
@@ -1957,7 +1959,7 @@ func doTestPythonGenStreams(t *testing.T, h Handle) {
1957
1959
}
1958
1960
//no need to indirect, because we pass a nil ptr, so we already have the value
1959
1961
//if v1 != nil { v1 = reflect.Indirect(reflect.ValueOf(v1)).Interface() }
1960
- if err = testEqual (v , v1 ); err == nil {
1962
+ if err = testEqualFlex (v , v1 ); err == nil {
1961
1963
if testv .Verbose {
1962
1964
t .Logf ("++++++++ Objects match: %T, %v" , v , v )
1963
1965
}
@@ -1976,7 +1978,7 @@ func doTestPythonGenStreams(t *testing.T, h Handle) {
1976
1978
t .FailNow ()
1977
1979
continue
1978
1980
}
1979
- if err = testEqual (bsb , bss ); err == nil {
1981
+ if err = testEqualFlex (bsb , bss ); err == nil {
1980
1982
if testv .Verbose {
1981
1983
t .Logf ("++++++++ Bytes match" )
1982
1984
}
@@ -3194,8 +3196,8 @@ func doTestStrucEncDec(t *testing.T, h Handle) {
3194
3196
name := h .Name ()
3195
3197
3196
3198
{
3197
- var ts1 = newTestStruc (2 , testv .NumRepeatString , false , ! testv .SkipIntf , testv .MapStringKeyOnly )
3198
- var ts2 TestStruc
3199
+ var ts1 = newTestStrucPlus (2 , testv .NumRepeatString , false , ! testv .SkipIntf , testv .MapStringKeyOnly )
3200
+ var ts2 TestStrucPlus
3199
3201
bs := testMarshalErr (ts1 , h , t , name )
3200
3202
testUnmarshalErr (& ts2 , bs , h , t , name )
3201
3203
testDeepEqualErrHandle (ts1 , & ts2 , h , t , name )
@@ -3501,7 +3503,7 @@ func doTestNextValueBytes(t *testing.T, h Handle) {
3501
3503
[]string {"1" , "22" , "333" , "4444" },
3502
3504
// use *TestStruc, not *TestStrucFlex, as *TestStrucFlex is harder to compare with deep equal
3503
3505
// Remember: *TestStruc was separated for this reason, affording comparing against other libraries
3504
- newTestStruc (testv .Depth , testv .NumRepeatString , false , false , true ),
3506
+ newTestStrucPlus (testv .Depth , testv .NumRepeatString , false , false , true ),
3505
3507
"1223334444" ,
3506
3508
}
3507
3509
var out []byte
@@ -4169,12 +4171,5 @@ func testEqualH(v1, v2 interface{}, h Handle) (err error) {
4169
4171
if v1 != nil {
4170
4172
v1 = deepcopy (v1 ).Interface ()
4171
4173
}
4172
- if ! reflect .DeepEqual (v1 , v2 ) {
4173
- if testv .UseDiff {
4174
- err = errors .New (gocmp .Diff (v1 , v2 ))
4175
- } else {
4176
- err = errDeepEqualNotMatch
4177
- }
4178
- }
4179
- return
4174
+ return testEqualOpts (v1 , v2 , false , []interface {}{v1 })
4180
4175
}
0 commit comments