aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/root.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/root.zig')
-rw-r--r--src/root.zig60
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");