diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-01-25 20:27:34 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-01-25 20:27:34 +0900 |
| commit | 797ceeaa2b01070cf31c8d24ce440b8ee5feff7f (patch) | |
| tree | 0c2bf8c3517f7512645f41acbca0dbf206b7c1b8 /src/root.zig | |
| parent | 8b8bc79d647285a170aa928ff31a0989c9ef6e33 (diff) | |
| download | zgjq-797ceeaa2b01070cf31c8d24ce440b8ee5feff7f.tar.gz zgjq-797ceeaa2b01070cf31c8d24ce440b8ee5feff7f.tar.zst zgjq-797ceeaa2b01070cf31c8d24ce440b8ee5feff7f.zip | |
implement optional index access
Diffstat (limited to 'src/root.zig')
| -rw-r--r-- | src/root.zig | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/root.zig b/src/root.zig index f2cc29a..b1f8614 100644 --- a/src/root.zig +++ b/src/root.zig @@ -124,6 +124,18 @@ test "comma operator" { try testRunMultiple(&.{ "12", "34", "56" }, "{\"a\":12,\"b\":34,\"c\":56}", ".a,.b,.c"); } +test "optional index" { + try testRun("1", "[1,2,3]", ".[0]?"); + try testRun("null", "[1,2,3]", ".[5]?"); + try testRun("null", "null", ".[0]?"); + try testRun("null", "123", ".[0]?"); + + try testRun("123", "{\"a\":123}", ".a?"); + try testRun("null", "{\"a\":123}", ".b?"); + try testRun("null", "null", ".a?"); + try testRun("null", "[1,2,3]", ".a?"); +} + test "comparison operators" { try testRun("true", "null", "1 == 1"); try testRun("false", "null", "1 == 2"); |
