-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_test.go
47 lines (38 loc) · 1.47 KB
/
json_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 jsonassert
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestJSONNodeArray(t *testing.T) {
json, _ := NewJSONNodeFromString(`["a","b"]`)
assert.True(t, json.IsArray(), "Should be an array")
assert.False(t, json.IsMap(), "Should not be a map")
assert.Equal(t, 2, json.GetSize())
}
func TestJSONNodeArrayWhenSetProgramatically(t *testing.T) {
array := make([]interface{}, 2)
array[0] = "a"
array[1] = "b"
json := NewJSONNodeFromArray(array)
assert.True(t, json.IsArray(), "Should be an array")
assert.False(t, json.IsMap(), "Should not be a map")
assert.Equal(t, "a", json.GetArray()[0])
assert.Equal(t, 2, json.GetSize())
}
func TestJSONNodeCheckGetForArrays(t *testing.T) {
json, _ := NewJSONNodeFromString(`{"id":1,"array":["a","b"]}`)
array, found := json.CheckGet("array")
assert.True(t, found, "Should be found")
assert.True(t, array.IsArray(), "Should be an array")
assert.False(t, array.IsMap(), "Should not be a map")
assert.Equal(t, 2, array.GetSize())
}
func TestJSONNodeCheckGetForString(t *testing.T) {
json, _ := NewJSONNodeFromString(`{"id":1,"string":"a"}`)
testString, found := json.CheckGet("string")
assert.True(t, found, "Should be found")
assert.False(t, testString.IsArray(), "Should not be an array")
assert.False(t, testString.IsMap(), "Should not be a map")
assert.Equal(t, 0, testString.GetSize())
assert.Equal(t, "a", testString.GetData())
}