Skip to content

Commit 6444c27

Browse files
committed
Update compliance suite, test located expectations
1 parent 1506641 commit 6444c27

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ All notable changes to this project will be documented in this file. It uses the
2222
for Go core numeric types. This should allow for transparent handling of
2323
values marshaled with [json.Decoder.UseNumber] enabled.
2424

25+
### 📔 Notes
26+
27+
* Upgraded the [compliance test suite] and integrated its located path test
28+
expectations. All tests passed, no changes required.
29+
2530
[v0.4.1]: https://github.com/theory/jsonpath/compare/v0.4.1...v0.10.0
2631
[json.Number]: https://pkg.go.dev/encoding/json#Number
2732
[json.Decoder.UseNumber]: https://pkg.go.dev/encoding/json#Decoder.UseNumber
2833
[PR #14]: https://github.com/theory/jsonpath/pull/14
34+
[compliance test suite]: https://github.com/jsonpath-standard/jsonpath-compliance-test-suite
2935

3036
## [v0.4.1] — 2025-05-02
3137

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ submodules:
5757
git submodule update --init
5858

5959
update-submodules:
60-
git pull --recurse-submodules
60+
git submodule update --recursive --remote --init

path_test.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,23 @@ func TestParseCompliance(t *testing.T) {
203203

204204
//nolint:tagliatelle
205205
type testCase struct {
206-
Name string
207-
Selector string
208-
Document any
209-
Result NodeList
210-
Results []NodeList
211-
InvalidSelector bool `json:"invalid_selector"`
206+
Name string `json:"name"`
207+
Selector string `json:"selector"`
208+
Document any `json:"document"`
209+
Result NodeList `json:"result"`
210+
Results []NodeList `json:"results"`
211+
ResultPaths []string `json:"result_paths"`
212+
ResultsPaths [][]string `json:"results_paths"`
213+
InvalidSelector bool `json:"invalid_selector"`
212214
}
213215

214216
rawJSON, err := os.ReadFile(
215217
filepath.Join("jsonpath-compliance-test-suite", "cts.json"),
216218
)
217219
r.NoError(err)
218-
var ts struct{ Tests []testCase }
219-
//nolint:musttag
220+
var ts struct {
221+
Tests []testCase `json:"tests"`
222+
}
220223
if err := json.Unmarshal(rawJSON, &ts); err != nil {
221224
t.Fatal(err)
222225
}
@@ -243,6 +246,23 @@ func TestParseCompliance(t *testing.T) {
243246
case tc.Results != nil:
244247
a.Contains(tc.Results, res, description)
245248
}
249+
250+
// Assemble and test located nodes.
251+
nodes := NodeList{}
252+
paths := []string{}
253+
for l := range p.SelectLocated(tc.Document).All() {
254+
nodes = append(nodes, l.Node)
255+
paths = append(paths, l.Path.String())
256+
}
257+
258+
switch {
259+
case tc.ResultPaths != nil:
260+
a.Equal(tc.ResultPaths, paths, description)
261+
a.Equal(tc.Result, nodes, description)
262+
case tc.ResultsPaths != nil:
263+
a.Contains(tc.Results, nodes, description)
264+
a.Contains(tc.ResultsPaths, paths, description)
265+
}
246266
})
247267
}
248268
}

0 commit comments

Comments
 (0)