From 797ceeaa2b01070cf31c8d24ce440b8ee5feff7f Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 25 Jan 2026 20:27:34 +0900 Subject: implement optional index access --- src/root.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/root.zig') 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"); -- cgit v1.3-1-g0d28