]> granicus.if.org Git - jq/commitdiff
Add more destructuring tests
authorNicolas Williams <nico@cryptonector.com>
Tue, 21 Feb 2017 01:15:05 +0000 (19:15 -0600)
committerNicolas Williams <nico@cryptonector.com>
Sun, 26 Mar 2017 10:36:22 +0000 (05:36 -0500)
tests/jq.test

index 2882d9c4681941bb63fa1d287347ffa97b2ec6d6..48def7c8ac8589542797c1ead4d579afa24389b4 100644 (file)
@@ -715,6 +715,18 @@ reduce . as $n (.; .)
 null
 null
 
+# Destructuring
+. as {$a, b: [$c, {$d}]} | [$a, $c, $d]
+{"a":1, "b":[2,{"d":3}]}
+[1,2,3]
+
+# Destructuring with alternation
+.[] | . as {$a, b: [$c, {$d}]} ?// [$a, {$b}, $e] ?// $f | [$a, $b, $c, $d, $e, $f]
+[{"a":1, "b":[2,{"d":3}]}, [4, {"b":5, "c":6}, 7, 8, 9], "foo"]
+[1, null, 2, 3, null, null]
+[4, 5, null, null, 7, null]
+[null, null, null, null, null, "foo"]
+
 . as $dot|any($dot[];not)
 [1,2,3,4,true,false,1,2,3,4,5]
 true