-
Notifications
You must be signed in to change notification settings - Fork 4
/
collections_test.go
93 lines (82 loc) · 1.88 KB
/
collections_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package jsony_test
import (
"testing"
"github.com/orsinium-labs/jsony"
)
func TestObject(t *testing.T) {
obj := jsony.Object{
jsony.Field{"name", jsony.String("aragorn")},
jsony.Field{"age", jsony.Int(82)},
}
got := jsony.EncodeString(obj)
want := `{"name":"aragorn","age":82}`
if got != want {
t.Fatalf("got `%s`, want `%s`", got, want)
}
}
func TestObject_Empty(t *testing.T) {
obj := jsony.Object{}
got := jsony.EncodeString(obj)
want := `{}`
if got != want {
t.Fatalf("got `%s`, want `%s`", got, want)
}
}
func TestMap(t *testing.T) {
obj := jsony.Map{
jsony.SafeString("name"): jsony.String("aragorn"),
}
got := jsony.EncodeString(obj)
want := `{"name":"aragorn"}`
if got != want {
t.Fatalf("got `%s`, want `%s`", got, want)
}
}
func TestMap_Empty(t *testing.T) {
obj := jsony.Map{}
got := jsony.EncodeString(obj)
want := `{}`
if got != want {
t.Fatalf("got `%s`, want `%s`", got, want)
}
}
func TestMap_Null(t *testing.T) {
obj := jsony.Map(nil)
got := jsony.EncodeString(obj)
want := `null`
if got != want {
t.Fatalf("got `%s`, want `%s`", got, want)
}
}
func TestArray(t *testing.T) {
obj := jsony.Array[jsony.Int]{13, 7, -5}
got := jsony.EncodeString(obj)
want := `[13,7,-5]`
if got != want {
t.Fatalf("got `%s`, want `%s`", got, want)
}
}
func TestMixedArray(t *testing.T) {
obj := jsony.MixedArray{jsony.String("aragorn"), jsony.Int(82), jsony.Null}
got := jsony.EncodeString(obj)
want := `["aragorn",82,null]`
if got != want {
t.Fatalf("got `%s`, want `%s`", got, want)
}
}
func TestMixedArray_Empty(t *testing.T) {
obj := jsony.MixedArray{}
got := jsony.EncodeString(obj)
want := `[]`
if got != want {
t.Fatalf("got `%s`, want `%s`", got, want)
}
}
func TestMixedArray_Null(t *testing.T) {
obj := jsony.MixedArray(nil)
got := jsony.EncodeString(obj)
want := `null`
if got != want {
t.Fatalf("got `%s`, want `%s`", got, want)
}
}