aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/root.zig
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-01-25 16:23:13 +0900
committernsfisis <nsfisis@gmail.com>2026-01-25 16:23:13 +0900
commit20ff09460371b07d7e9683757657a5a3ead005a8 (patch)
tree327089640d923a4bf44d340d584cf3378f654728 /src/root.zig
parent7e5382e6eac497f6be55a7d947a8c6e6c2ecb390 (diff)
downloadzgjq-20ff09460371b07d7e9683757657a5a3ead005a8.tar.gz
zgjq-20ff09460371b07d7e9683757657a5a3ead005a8.tar.zst
zgjq-20ff09460371b07d7e9683757657a5a3ead005a8.zip
implement comparison operators
Diffstat (limited to 'src/root.zig')
-rw-r--r--src/root.zig52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/root.zig b/src/root.zig
index 782f078..cce3ce5 100644
--- a/src/root.zig
+++ b/src/root.zig
@@ -112,3 +112,55 @@ test "pipe operator" {
test "comma operator" {
try testRunMultiple(&.{ "12", "34", "56" }, "{\"a\":12,\"b\":34,\"c\":56}", ".a,.b,.c");
}
+
+test "comparison operators" {
+ try testRun("true", "null", "1 == 1");
+ try testRun("false", "null", "1 == 2");
+ try testRun("false", "null", "1 != 1");
+ try testRun("true", "null", "1 != 2");
+
+ try testRun("true", "null", "1.5 == 1.5");
+ try testRun("false", "null", "1.5 == 2.5");
+
+ try testRun("true", "null", "1 == 1.0");
+ try testRun("false", "null", "1 == 1.5");
+
+ try testRun("true", "{\"a\":\"foo\",\"b\":\"foo\"}", ".a == .b");
+ try testRun("false", "{\"a\":\"foo\",\"b\":\"bar\"}", ".a == .b");
+ try testRun("true", "{\"a\":\"foo\",\"b\":\"bar\"}", ".a != .b");
+
+ try testRun("true", "null", ". == null");
+ try testRun("false", "null", ". != null");
+
+ try testRun("true", "true", ". == true");
+ try testRun("false", "true", ". == false");
+ try testRun("true", "false", ". != true");
+
+ try testRun("true", "null", "1 < 2");
+ try testRun("false", "null", "2 < 1");
+ try testRun("false", "null", "1 < 1");
+
+ try testRun("true", "null", "2 > 1");
+ try testRun("false", "null", "1 > 2");
+ try testRun("false", "null", "1 > 1");
+
+ try testRun("true", "null", "1 <= 2");
+ try testRun("true", "null", "1 <= 1");
+ try testRun("false", "null", "2 <= 1");
+
+ try testRun("true", "null", "2 >= 1");
+ try testRun("true", "null", "1 >= 1");
+ try testRun("false", "null", "1 >= 2");
+
+ try testRun("true", "null", "1.5 < 2.5");
+ try testRun("false", "null", "2.5 < 1.5");
+
+ try testRun("true", "null", "1 < 1.5");
+ try testRun("false", "null", "2 < 1.5");
+
+ try testRun("true", "{\"a\":\"abc\",\"b\":\"abd\"}", ".a < .b");
+ try testRun("false", "{\"a\":\"abd\",\"b\":\"abc\"}", ".a < .b");
+ try testRun("true", "{\"a\":\"abc\",\"b\":\"abc\"}", ".a <= .b");
+ try testRun("true", "{\"a\":\"abd\",\"b\":\"abc\"}", ".a > .b");
+ try testRun("true", "{\"a\":\"abc\",\"b\":\"abc\"}", ".a >= .b");
+}