summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChance Zibolski <czibolsk@redhat.com>2019-02-14 19:59:59 -0800
committerNico Williams <nico@cryptonector.com>2019-02-20 20:03:26 -0600
commit4f6045a94e0519ec58210bbd58ece442c32468e1 (patch)
treef25f29a668901b784ac78ed46223c145ab662c46 /tests
parent1ef90acb3814d85d59e5d1502d0ced6287b83408 (diff)
Support "if" without "else" clause
Defaults the else clause to the identity filter "." if an else clause is missing. The following two jq programs are considered equivalent: ``` if .foo then .foo = "bar" else . end ``` ``` if .foo then .foo = "bar" end ```
Diffstat (limited to 'tests')
-rw-r--r--tests/jq.test13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/jq.test b/tests/jq.test
index cbdc0bf0..c027f538 100644
--- a/tests/jq.test
+++ b/tests/jq.test
@@ -1036,6 +1036,19 @@ null
null
[5,6]
+[if true then 3 end]
+7
+[3]
+
+[if false then 3 end]
+7
+[7]
+
+[if false then 3 else . end]
+7
+[7]
+
+
[.[] | [.foo[] // .bar]]
[{"foo":[1,2], "bar": 42}, {"foo":[1], "bar": null}, {"foo":[null,false,3], "bar": 18}, {"foo":[], "bar":42}, {"foo": [null,false,null], "bar": 41}]
[[1,2], [1], [3], [42], [41]]