diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-01-25 20:38:36 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-01-25 20:38:36 +0900 |
| commit | 7e516e5e083518f11a7399e895718572f7c7fb79 (patch) | |
| tree | 33a6e2f1c43f721203bb2bb1a45a6c6b2831c93a /src/root.zig | |
| parent | ee8a2e3b7b475c1b9ec5ca4ed787e42fd14457a5 (diff) | |
| download | zgjq-7e516e5e083518f11a7399e895718572f7c7fb79.tar.gz zgjq-7e516e5e083518f11a7399e895718572f7c7fb79.tar.zst zgjq-7e516e5e083518f11a7399e895718572f7c7fb79.zip | |
implement arbitrary query in index access
Diffstat (limited to 'src/root.zig')
| -rw-r--r-- | src/root.zig | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/root.zig b/src/root.zig index b1f8614..6cdc276 100644 --- a/src/root.zig +++ b/src/root.zig @@ -65,7 +65,7 @@ test "identity filter" { try testRun("{\"a\":123}", "{\"a\":123}", "."); } -test "array index filter" { +test "index access" { try testRun("null", "[]", ".[0]"); try testRun("1", "[1,2,3]", ".[0]"); try testRun("null", "[1,2,3]", ".[5]"); @@ -77,14 +77,23 @@ test "array index filter" { \\ 61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80, \\ 81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100] , ".[100]"); -} -test "object key filter" { try testRun("123", "{\"a\":123}", ".a"); try testRun("null", "{\"a\":123}", ".b"); try testRun("\"hello\"", "{\"foo\":\"hello\"}", ".foo"); try testRun("[1,2,3]", "{\"arr\":[1,2,3]}", ".arr"); try testRun("{\"bar\":true}", "{\"foo\":{\"bar\":true}}", ".foo"); + + try testRun("123", "{\"a\":123}", ".[\"a\"]"); + try testRun("null", "{\"a\":123}", ".[\"b\"]"); + try testRun("\"hello\"", "{\"foo\":\"hello\"}", ".[\"foo\"]"); + + try testRun("42", "{\"foo bar\":42}", ".[\"foo bar\"]"); + try testRun("\"value\"", "{\"key with spaces\":\"value\"}", ".[\"key with spaces\"]"); + + try testRun("\"world\"", "{\"key\":\"hello\",\"hello\":\"world\"}", ".[.key]"); + try testRun("3", "[1,2,3,4,5]", ".[1 + 1]"); + try testRun("5", "[1,2,3,4,5]", ".[2 * 2]"); } test "arithmetic operations" { |
