(t *testing.T)
| 40 | } |
| 41 | |
| 42 | func 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 | |
| 67 | func TestMarshalDeterministic_Slice(t *testing.T) { |
| 68 | s := []map[string]int{ |
nothing calls this directly
no test coverage detected