diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-01-26 23:39:48 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-01-26 23:39:48 +0900 |
| commit | c2a92de7fa1af4fc058f8e5e8317fb67a6df18ef (patch) | |
| tree | b9a423eb1c4be33baf4f2f386afb0e2adc7a96f9 /src/root.zig | |
| parent | c524ef71e6e33495ec682558d3e4eb05648a72c9 (diff) | |
| download | zgjq-c2a92de7fa1af4fc058f8e5e8317fb67a6df18ef.tar.gz zgjq-c2a92de7fa1af4fc058f8e5e8317fb67a6df18ef.tar.zst zgjq-c2a92de7fa1af4fc058f8e5e8317fb67a6df18ef.zip | |
implement // operator
Diffstat (limited to 'src/root.zig')
| -rw-r--r-- | src/root.zig | 21 |
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\""); +} |
