From 7e516e5e083518f11a7399e895718572f7c7fb79 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 25 Jan 2026 20:38:36 +0900 Subject: implement arbitrary query in index access --- src/root.zig | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/root.zig') 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" { -- cgit v1.3-1-g0d28