-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jg-rp/operator-precedence
Fix JSONPath filter operator precedence.
- Loading branch information
Showing
4 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,44 @@ | ||
import { JSONPathSyntaxError, compile, query } from "../../src/path"; | ||
import { | ||
JSONPathEnvironment, | ||
JSONPathSyntaxError, | ||
compile, | ||
query, | ||
} from "../../src/path"; | ||
|
||
type TestCase = { | ||
description: string; | ||
path: string; | ||
want: string; | ||
}; | ||
|
||
const TEST_CASES: TestCase[] = [ | ||
{ | ||
description: "not binds more tightly than and", | ||
path: "$[[email protected] && [email protected]]", | ||
want: "$[?(!@['a'] && !@['b'])]", | ||
}, | ||
{ | ||
description: "not binds more tightly than or", | ||
path: "$[[email protected] || [email protected]]", | ||
want: "$[?(!@['a'] || !@['b'])]", | ||
}, | ||
{ | ||
description: "control precedence with parens", | ||
path: "$[?!(@.a && [email protected])]", | ||
want: "$[?!(@['a'] && !@['b'])]", | ||
}, | ||
]; | ||
|
||
describe("parse", () => { | ||
const env = new JSONPathEnvironment(); | ||
|
||
test.each<TestCase>(TEST_CASES)( | ||
"$description", | ||
({ path, want }: TestCase) => { | ||
expect(env.compile(path).toString()).toBe(want); | ||
}, | ||
); | ||
|
||
test("well-typed nested functions", () => { | ||
const data = { | ||
regex: "a.*", | ||
|