diff options
| author | Felix Hanley <felix@userspace.com.au> | 2018-11-16 06:35:28 +0000 |
|---|---|---|
| committer | Felix Hanley <felix@userspace.com.au> | 2018-11-16 06:35:28 +0000 |
| commit | 44da796e192961b614e3540c4c1ec52f4bc0a290 (patch) | |
| tree | c0dcc69363c401d123bfdba0662d990d6804df77 /jsonpath/parse_test.go | |
| parent | d6882bd9403c588415c1906a7015d16e92aa1ad3 (diff) | |
| download | query-44da796e192961b614e3540c4c1ec52f4bc0a290.tar.gz query-44da796e192961b614e3540c4c1ec52f4bc0a290.tar.bz2 | |
Add start of jsonpath parser
Diffstat (limited to 'jsonpath/parse_test.go')
| -rw-r--r-- | jsonpath/parse_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/jsonpath/parse_test.go b/jsonpath/parse_test.go new file mode 100644 index 0000000..db41efe --- /dev/null +++ b/jsonpath/parse_test.go @@ -0,0 +1,39 @@ +package jsonpath + +import ( + "strings" + "testing" + + "src.userspace.com.au/query/json" +) + +func TestParse(t *testing.T) { + tests := []struct { + path, src, expect string + }{ + { + path: "$.test", + src: `{"test":"one"}`, + expect: "one", + }, + } + + p := Parser{} + + for _, tt := range tests { + doc, err := json.Parse(strings.NewReader(tt.src)) + if err != nil { + t.Errorf("json.Parse(%q) failed: %s", tt.src, err) + } + + sel, err := p.Parse(tt.path) + if err != nil { + t.Errorf("Parse(%q) failed: %s", tt.path, err) + } + actual := sel.MatchFirst(doc) + actualText := actual.InnerText() + if actualText != tt.expect { + t.Errorf("MatchFirst(%s) => %s, expected %s", tt.src, actualText, tt.expect) + } + } +} |
