diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-01-31 15:53:23 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-01-31 15:57:48 +0900 |
| commit | 7712c1d10ec45349c1cd6e66281b7d602350065d (patch) | |
| tree | 92208e7fb1955fd9847d91affa25ec096012ab9b /src/root.zig | |
| parent | 617ddc62aa4d3153850362526069b85bfaf5e59e (diff) | |
| download | zgjq-7712c1d10ec45349c1cd6e66281b7d602350065d.tar.gz zgjq-7712c1d10ec45349c1cd6e66281b7d602350065d.tar.zst zgjq-7712c1d10ec45349c1cd6e66281b7d602350065d.zip | |
implement slice expression
Diffstat (limited to 'src/root.zig')
| -rw-r--r-- | src/root.zig | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/root.zig b/src/root.zig index e2152d3..ac9c21c 100644 --- a/src/root.zig +++ b/src/root.zig @@ -118,6 +118,66 @@ test "index access" { try testRun("5", "[1,2,3,4,5]", ".[2 * 2]"); } +test "slice" { + // [begin:end] + try testRun("[]", "[1,2,3]", ".[1:1]"); + try testRun( + \\[ + \\ 2, + \\ 3 + \\] + , "[1,2,3]", ".[1:3]"); + try testRun( + \\[ + \\ 2 + \\] + , "[1,2,3]", ".[1:2]"); + + // [begin:] + try testRun( + \\[ + \\ 2, + \\ 3 + \\] + , "[1,2,3]", ".[1:]"); + try testRun( + \\[ + \\ 1, + \\ 2, + \\ 3 + \\] + , "[1,2,3]", ".[0:]"); + + // [:end] + try testRun( + \\[ + \\ 1 + \\] + , "[1,2,3]", ".[:1]"); + try testRun( + \\[ + \\ 1, + \\ 2 + \\] + , "[1,2,3]", ".[:2]"); + + try testRun( + \\[ + \\ 1, + \\ 2, + \\ 3 + \\] + , "[1,2,3]", ".[0:10]"); + try testRun("[]", "[1,2,3]", ".[5:10]"); + + try testRun( + \\[ + \\ 2, + \\ 3 + \\] + , "[[1,2,3],[4,5,6]]", ".[0] | .[1:]"); +} + test "arithmetic operations" { try testRun("579", "null", "123 + 456"); try testRun("35", "{\"a\":12,\"b\":23}", ".a + .b"); |
