-
Notifications
You must be signed in to change notification settings - Fork 0
/
anyorderedmap_test.go
59 lines (42 loc) · 1.25 KB
/
anyorderedmap_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package orderedmapjson
import (
"encoding/json"
"testing"
)
func TestAnyOrderedMap(t *testing.T) {
const input = `{"foo":"bar","123":true,"abc":null,"_obj":{"foo":"bar"},"_array":[{"b":"b","a":"a","0":null,"123":{"q":"","w":"","e":"","r":"","t":"","y":""}}],"q":"","w":"","e":"","r":"","t":"","y":""}`
m := NewAnyOrderedMap()
if err := json.Unmarshal([]byte(input), m); err != nil {
t.Fatalf("unexpected error: %v", err)
}
data, err := json.Marshal(m)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
output := string(data)
if output != input {
t.Fatalf("expected %s, got %s", input, output)
}
}
func TestUnmarshalArrayWithAnyOrderedMap(t *testing.T) {
const input = `[{"c":"c","a":"a","b":"b"},"test",123,{"3":"3","2":"2","1":"1"}]`
values, err := UnmarshalArrayWithAnyOrderedMap([]byte(input))
data, err := json.Marshal(values)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
output := string(data)
if output != input {
t.Fatalf("expected %s, got %s", input, output)
}
}
func TestAnyOrderedMapCopy(t *testing.T) {
m := NewAnyOrderedMap()
m.Set("foo", "bar")
m.Set("123", true)
m.Set("abc", nil)
mm := m.Copy()
if mm.String() != m.String() {
t.Fatalf("expected %s, got %s", m.String(), mm.String())
}
}