deep icon indicating copy to clipboard operation
deep copied to clipboard

support for json.RawMessage?

Open dionysius opened this issue 1 year ago • 0 comments


import "encoding/json"

func TestJsonRawMessage(t *testing.T) {
	type T json.RawMessage

	a := T(`{"foo":1,"bar":2}`)
	b := T(`{"bar":2,"foo":1}`)

	// just informative begin
	aI := map[string]interface{}{}
	bI := map[string]interface{}{}

	_ = json.Unmarshal(a, &aI)
	_ = json.Unmarshal(b, &bI)

	fmt.Println(aI)
	fmt.Println(bI)
	// end

	diff := deep.Equal(a, b)
	if len(diff) != 0 {
		t.Fatalf("expected 0 diff, got %d: %s", len(diff), diff)
	}
}
go test -run ^TestJsonRawMessage$ github.com/go-test/deep

map[bar:2 foo:1]
map[bar:2 foo:1]
--- FAIL: TestJsonRawMessage (0.00s)
    .../deep/deep_test.go:1603: expected 0 diff, got 8: [slice[2]: 102 != 98 slice[3]: 111 != 97 slice[4]: 111 != 114 slice[7]: 49 != 50 slice[10]: 98 != 102 slice[11]: 97 != 111 slice[12]: 114 != 111 slice[15]: 50 != 49]
FAIL
FAIL	github.com/go-test/deep	0.002s
FAIL

might be tricky tho, since the actual type within there can be any json supported type

dionysius avatar Mar 22 '24 15:03 dionysius