diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-01-25 16:14:57 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-01-25 16:14:57 +0900 |
| commit | 3e78bb75c4b431b0a4d07892aba6a64f11da2210 (patch) | |
| tree | b7a8d2a5412c75cd3ace1032db38e6535d3d0a1d /src/root.zig | |
| parent | 448c28d596184f39783f8a7813ae73901fce240a (diff) | |
| download | zgjq-3e78bb75c4b431b0a4d07892aba6a64f11da2210.tar.gz zgjq-3e78bb75c4b431b0a4d07892aba6a64f11da2210.tar.zst zgjq-3e78bb75c4b431b0a4d07892aba6a64f11da2210.zip | |
implement arithmetic operations
Diffstat (limited to 'src/root.zig')
| -rw-r--r-- | src/root.zig | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/root.zig b/src/root.zig index 0d2a3ce..782f078 100644 --- a/src/root.zig +++ b/src/root.zig @@ -76,11 +76,31 @@ test "object key filter" { try testRun("{\"bar\":true}", "{\"foo\":{\"bar\":true}}", ".foo"); } -test "addition" { +test "arithmetic operations" { try testRun("579", "null", "123 + 456"); try testRun("35", "{\"a\":12,\"b\":23}", ".a + .b"); try testRun("12", "[1,2,3]", ".[1] + 10"); try testRun("6", "null", "1 + 2 + 3"); + + try testRun("333", "null", "456 - 123"); + try testRun("-11", "{\"a\":12,\"b\":23}", ".a - .b"); + try testRun("-8", "[1,2,3]", ".[1] - 10"); + try testRun("-4", "null", "1 - 2 - 3"); + + try testRun("56088", "null", "123 * 456"); + try testRun("276", "{\"a\":12,\"b\":23}", ".a * .b"); + try testRun("20", "[1,2,3]", ".[1] * 10"); + try testRun("6", "null", "1 * 2 * 3"); + + try testRun("3", "null", "456 / 123"); + try testRun("0", "{\"a\":12,\"b\":23}", ".a / .b"); + try testRun("5", "[10,20,30]", ".[1] / 4"); + try testRun("2", "null", "12 / 2 / 3"); + + try testRun("87", "null", "456 % 123"); + try testRun("12", "{\"a\":12,\"b\":23}", ".a % .b"); + try testRun("0", "[1,2,3]", ".[1] % 2"); + try testRun("0", "null", "12 % 2 % 3"); } test "pipe operator" { |
