MCPcopy Create free account
hub / github.com/astercloud/aster / TestMarshalDeterministic_NestedMap

Function TestMarshalDeterministic_NestedMap

pkg/util/json_test.go:42–65  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestMarshalDeterministic_NestedMap(t *testing.T) {
43 m := map[string]any{
44 "z": map[string]int{
45 "c": 3,
46 "a": 1,
47 "b": 2,
48 },
49 "a": map[string]string{
50 "y": "why",
51 "x": "ex",
52 },
53 }
54
55 data, err := MarshalDeterministic(m)
56 if err != nil {
57 t.Fatalf("MarshalDeterministic failed: %v", err)
58 }
59
60 // 外层和内层 map 都应该按字典序排列
61 expected := `{"a":{"x":"ex","y":"why"},"z":{"a":1,"b":2,"c":3}}`
62 if string(data) != expected {
63 t.Errorf("Expected:\n%s\nGot:\n%s", expected, string(data))
64 }
65}
66
67func TestMarshalDeterministic_Slice(t *testing.T) {
68 s := []map[string]int{

Callers

nothing calls this directly

Calls 1

MarshalDeterministicFunction · 0.85

Tested by

no test coverage detected