| 88 | } |
| 89 | |
| 90 | func testFailJSONPath(tests []jsonpathTest, t *testing.T) { |
| 91 | for _, test := range tests { |
| 92 | j := New(test.name) |
| 93 | err := j.Parse(test.template) |
| 94 | if err != nil { |
| 95 | t.Errorf("in %s, parse %s error %v", test.name, test.template, err) |
| 96 | } |
| 97 | buf := new(bytes.Buffer) |
| 98 | err = j.Execute(buf, test.input) |
| 99 | var out string |
| 100 | if err == nil { |
| 101 | out = "nil" |
| 102 | } else { |
| 103 | out = err.Error() |
| 104 | } |
| 105 | if out != test.expect { |
| 106 | t.Errorf("in %s, expect to get error %q, got %q", test.name, test.expect, out) |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | type book struct { |
| 112 | Category string |