test: add support for non-strict-equality decode tests
Future work will enable us to decode structures containing deeply nested
pointers, which will fail strict equality checks.
diff --git a/common_data_for_test.go b/common_data_for_test.go
index 4fedd04..d71d996 100644
--- a/common_data_for_test.go
+++ b/common_data_for_test.go
@@ -8,12 +8,13 @@
)
type TestData struct {
- Name string
- Value interface{}
- DecodeValue interface{} // used when the document cannot encode parts of Value
- Documents map[int][]byte
- SkipDecode map[int]bool
- SkipEncode map[int]bool
+ Name string
+ Value interface{}
+ DecodeValue interface{} // used when the document cannot encode parts of Value
+ TestDecodedValue func(interface{}) error
+ Documents map[int][]byte
+ SkipDecode map[int]bool
+ SkipEncode map[int]bool
}
type SparseBundleHeader struct {
diff --git a/decode_test.go b/decode_test.go
index adccbcb..32ef355 100644
--- a/decode_test.go
+++ b/decode_test.go
@@ -126,11 +126,11 @@
expVal = expReflect.Interface()
results := make(map[int]interface{})
- for fmt, doc := range test.Documents {
- if test.SkipDecode[fmt] {
+ for format, doc := range test.Documents {
+ if test.SkipDecode[format] {
return
}
- subtest(t, FormatNames[fmt], func(t *testing.T) {
+ subtest(t, FormatNames[format], func(t *testing.T) {
val := reflect.New(expReflect.Type()).Interface()
_, err := Unmarshal(doc, val)
if err != nil {
@@ -144,9 +144,18 @@
val = valReflect.Interface()
}
- results[fmt] = val
- if !reflect.DeepEqual(expVal, val) {
- t.Logf("Expected: %#v\n", expVal)
+ results[format] = val
+ var passErr error
+ if test.TestDecodedValue == nil {
+ if !reflect.DeepEqual(expVal, val) {
+ passErr = fmt.Errorf("Expected: %#v", expVal)
+ }
+ } else {
+ passErr = test.TestDecodedValue(val)
+ }
+
+ if passErr != nil {
+ t.Logf("%v\n", passErr)
t.Logf("Received: %#v\n", val)
t.Fail()
}