forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshortcuts_test.go
30 lines (24 loc) · 981 Bytes
/
shortcuts_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
package json
import (
"testing"
"github.com/Velocidex/ordereddict"
"github.com/sebdah/goldie"
)
func TestJsonlShortcuts(t *testing.T) {
result := ordereddict.NewDict().
Set("Simple", string(AppendJsonlItem([]byte("{\"foo\":1}\n"), "bar", 2))).
Set("Nested", string(AppendJsonlItem([]byte("{\"foo\":1}\n"), "bar",
ordereddict.NewDict().Set("F", 1).Set("B", 2)))).
// Handle malformed JSON
Set("Empty String", string(AppendJsonlItem([]byte(""), "bar", 2))).
Set("Malformed", string(AppendJsonlItem([]byte("}"), "bar", 2))).
Set("Malformed2", string(AppendJsonlItem([]byte("}\n"), "bar", 2)))
goldie.Assert(t, "TestJsonlShortcuts", MustMarshalIndent(result))
}
func TestJsonFormat(t *testing.T) {
obj := ordereddict.NewDict().Set("Foo", "Bar")
subquery := Format(`{"Foo": %q}`, "Bar")
query := Format(`{"a": %q, "b": %q, "integer": %q, "string": %q, "subquery": %s}`,
obj, obj, 1, "hello", subquery)
goldie.Assert(t, "TestJsonFormat", []byte(query))
}