From c2a92de7fa1af4fc058f8e5e8317fb67a6df18ef Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 26 Jan 2026 23:39:48 +0900 Subject: implement // operator --- src/root.zig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/root.zig') 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\""); +} -- cgit v1.3-1-g0d28