Skip to content

Commit

Permalink
test key map MarshalText with std
Browse files Browse the repository at this point in the history
  • Loading branch information
brongineers committed Nov 14, 2022
1 parent 705f517 commit 6bca989
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,19 +1022,28 @@ func (u *unmarshalerText) UnmarshalText(b []byte) error {
}

func TestTextMarshalerMapKeysAreSorted(t *testing.T) {
b, err := json.Marshal(map[unmarshalerText]int{
data := map[unmarshalerText]int{
{"x", "y"}: 1,
{"y", "x"}: 2,
{"a", "z"}: 3,
{"z", "a"}: 4,
})
}
b, err := json.Marshal(data)
if err != nil {
t.Fatalf("Failed to Marshal text.Marshaler: %v", err)
}
const want = `{"a:z":3,"x:y":1,"y:x":2,"z:a":4}`
if string(b) != want {
t.Errorf("Marshal map with text.Marshaler keys: got %#q, want %#q", b, want)
}

b, err = stdjson.Marshal(data)
if err != nil {
t.Fatalf("Failed to std Marshal text.Marshaler: %v", err)
}
if string(b) != want {
t.Errorf("std Marshal map with text.Marshaler keys: got %#q, want %#q", b, want)
}
}

// https://golang.org/issue/33675
Expand Down

0 comments on commit 6bca989

Please sign in to comment.