]> granicus.if.org Git - jq/commitdiff
If-then-else documentation for forking conditional (fix #942)
authorDavid Tolnay <dtolnay@gmail.com>
Sun, 18 Oct 2015 04:15:24 +0000 (21:15 -0700)
committerDavid Tolnay <dtolnay@gmail.com>
Sun, 18 Oct 2015 04:15:24 +0000 (21:15 -0700)
docs/content/3.manual/manual.yml
docs/content/3.manual/v1.3/manual.yml
docs/content/3.manual/v1.4/manual.yml
docs/content/3.manual/v1.5/manual.yml
tests/jq.test

index d9dd3b185380f4563e6354534739545117d60b0a..f7fd9381308dc08f215bf9056d8af15df7428e55 100644 (file)
@@ -1863,9 +1863,9 @@ sections:
           need something more like `if (.name | length) > 0 then A else
           B end` instead.
 
-          If the condition A produces multiple results, it is
-          considered "true" if any of those results is not false or
-          null. If it produces zero results, it's considered false.
+          If the condition `A` produces multiple results, then `B` is evaluated
+          once for each result that is not false or null, and `C` is evaluated
+          once for each false or null.
 
           More cases can be added to an if using `elif A then B` syntax.
 
index aaedf37704f374bfeff88d9791cbdb2c44a157b6..08603207630a7be1fcf6d7a8452e4bbf53b27cb8 100644 (file)
@@ -913,9 +913,9 @@ sections:
           need something more like `if (.name | count) > 0 then A else
           B end` instead.
 
-          If the condition A produces multiple results, it is
-          considered "true" if any of those results is not false or
-          null. If it produces zero results, it's considered false.
+          If the condition `A` produces multiple results, then `B` is evaluated
+          once for each result that is not false or null, and `C` is evaluated
+          once for each false or null.
 
           More cases can be added to an if using `elif A then B` syntax.
 
index 841764acc6ba04f167a59a1e3eed592f97fc27d9..41745888a3ab9b3e517000e88055ca6b34417147 100644 (file)
@@ -1315,9 +1315,9 @@ sections:
           need something more like `if (.name | length) > 0 then A else
           B end` instead.
 
-          If the condition A produces multiple results, it is
-          considered "true" if any of those results is not false or
-          null. If it produces zero results, it's considered false.
+          If the condition `A` produces multiple results, then `B` is evaluated
+          once for each result that is not false or null, and `C` is evaluated
+          once for each false or null.
 
           More cases can be added to an if using `elif A then B` syntax.
 
index f676e52d0f0140a2494c6b2d34508568a523e9ca..1b37e79924cf67091d33cecec72303fa332f6009 100644 (file)
@@ -1794,9 +1794,9 @@ sections:
           need something more like `if (.name | length) > 0 then A else
           B end` instead.
 
-          If the condition A produces multiple results, it is
-          considered "true" if any of those results is not false or
-          null. If it produces zero results, it's considered false.
+          If the condition `A` produces multiple results, then `B` is evaluated
+          once for each result that is not false or null, and `C` is evaluated
+          once for each false or null.
 
           More cases can be added to an if using `elif A then B` syntax.
 
index 879de1620e4804b22a0d5853a35c39df29854bfc..46a7bc29fd2766d1b45a34932b74331d87cce47f 100644 (file)
@@ -867,8 +867,21 @@ try (def x: reverse; x=10) catch .
 [{"foo":0},{"foo":1},{"foo":[]},{"foo":true},{"foo":false},{"foo":null},{"foo":"foo"},{}]
 ["yep","yep","yep","yep","nope","nope","yep","nope"]
 
+[if 1,null,2 then 3 else 4 end]
+null
+[3,4,3]
+
+[if empty then 3 else 4 end]
+null
+[]
 
-# FIXME: define/test behaviour of 'if (.foo,.bar) then A else B end'
+[if 1 then 3,4 else 5 end]
+null
+[3,4]
+
+[if null then 3 else 5,6 end]
+null
+[5,6]
 
 [.[] | [.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}]