-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflat_test.go
47 lines (41 loc) · 964 Bytes
/
flat_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
package jnode
import (
"testing"
)
func TestFromFlat(t *testing.T) {
n, err := FromFlatString("a=b,c=5")
if err != nil {
t.Error(err)
}
if !n.IsObject() || n.Size() != 2 || n.Path("a").AsText() != "b" {
t.Fail()
}
}
func TestFromFlatNested(t *testing.T) {
n, err := FromFlatString("obj={b=1,c=2}")
if err != nil {
t.Error(err)
}
if !n.IsObject() || n.Size() != 1 || n.Path("obj").Size() != 2 || n.Path("obj").Path("c").AsInt() != 2 {
t.Error(n)
}
}
func TestFromFlatArray(t *testing.T) {
n, err := FromFlatString("a=[hello]")
if err != nil {
t.Error(err)
}
if !n.IsObject() || n.Size() != 1 ||
!n.Path("a").IsArray() || n.Path("a").Size() != 1 || n.Path("a").Get(0).AsText() != "hello" {
t.Error(n)
}
}
func TestComplex(t *testing.T) {
n, err := FromFlatString("containers=[{image=perl}]")
if err != nil {
t.Error(err)
}
if !n.IsObject() || n.Path("containers").Get(0).Path("image").AsText() != "perl" {
t.Error(n)
}
}