diff options
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) + } + } +} |
