-
Notifications
You must be signed in to change notification settings - Fork 4
/
del_test.go
57 lines (45 loc) · 923 Bytes
/
del_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
package main
import (
"testing"
"github.com/Jeffail/gabs/v2"
)
func TestDelKeySimple(t *testing.T) {
input := []byte(`{"foo":"bar"}`)
correctResult := `{}`
j, err := gabs.ParseJSON(input)
if err != nil {
t.Error(err)
}
options := delKeyOptions{
json: j,
path: "foo",
delimiter: ".",
}
result, err := delKey(options)
if err != nil {
t.Error(err)
}
if result.String() != correctResult {
t.Errorf("Wanted %s\nGot %s", correctResult, result)
}
}
func TestDelKeyNested(t *testing.T) {
input := []byte(`{"foo":{"bar":"baz"}}`)
correctResult := `{"foo":{}}`
j, err := gabs.ParseJSON(input)
if err != nil {
t.Error(err)
}
options := delKeyOptions{
json: j,
path: "foo.bar",
delimiter: ".",
}
result, err := delKey(options)
if err != nil {
t.Error(err)
}
if result.String() != correctResult {
t.Errorf("Wanted %s\nGot %s", correctResult, result)
}
}