aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/root.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/root.zig')
-rw-r--r--src/root.zig21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/root.zig b/src/root.zig
index b612d89..7aee514 100644
--- a/src/root.zig
+++ b/src/root.zig
@@ -254,3 +254,24 @@ test "or operator" {
try testRun("true", "{\"a\":false,\"b\":true}", ".a or .b");
try testRun("false", "{\"a\":false,\"b\":false}", ".a or .b");
}
+
+test "alternative operator" {
+ try testRun("\"default\"", "null", ". // \"default\"");
+ try testRun("\"hello\"", "\"hello\"", ". // \"default\"");
+
+ try testRun("\"default\"", "false", ". // \"default\"");
+ try testRun("true", "true", ". // \"default\"");
+
+ try testRun("123", "{\"a\":123}", ".a // \"default\"");
+ try testRun("\"default\"", "{\"a\":123}", ".b // \"default\"");
+ try testRun("\"default\"", "{\"a\":null}", ".a // \"default\"");
+
+ try testRun("\"third\"", "null", "null // false // \"third\"");
+ try testRun("\"first\"", "null", "\"first\" // \"second\" // \"third\"");
+
+ try testRun("0", "0", ". // 42");
+ try testRun("\"\"", "\"\"", ". // \"default\"");
+
+ try testRun("[]", "[]", ". // \"default\"");
+ try testRun("{}", "{}", ". // \"default\"");
+}