diff --git a/cli/test.yaml b/cli/test.yaml index d27616f..3b77647 100644 --- a/cli/test.yaml +++ b/cli/test.yaml @@ -2407,6 +2407,29 @@ "/a,b/c/d/e,f/" ",/ /a/,/b/,/ /c/,/ /d/,/ /e/,/f/,/ " +- name: split/1 function against empty string + args: + - -c + - '.[] as $t | .[] as $s | $s | split($t)' + input: '["abc", "a", "b", ""]' + expected: | + ["",""] + ["a"] + ["b"] + [] + ["","bc"] + ["",""] + ["b"] + [] + ["a","c"] + ["a"] + ["",""] + [] + ["a","b","c"] + ["a"] + ["b"] + [] + - name: join function args: - 'join(",")' @@ -3585,6 +3608,16 @@ expected: | 8 +- name: reduce with assignment of multiple paths in update + args: + - -c + - 'reduce (1,2) as $i (.; (.[0], .[.[0]]) = $i), + reduce (1,2) as $i (.; (.[0], .[.[0]]) |= $i)' + input: '[0,0,0]' + expected: | + [2,2,0] + [2,2,0] + - name: reduce with query in start args: - 'reduce range(5) as $x (range(3); . + $x)' @@ -3609,68 +3642,6 @@ expected: | [[1,1],[1]] -- name: reduce with assignment in update - args: - - -c - - 'reduce range(3) as $i ({}; .[$i|tostring] = {}), - reduce range(3) as $i ({}; .a[$i|tostring] = $i), - reduce range(3) as $i ([]; .[$i] = $i), - reduce range(3) as $i ({}; .[$i|tostring] += 1)' - input: 'null' - expected: | - {"0":{},"1":{},"2":{}} - {"a":{"0":0,"1":1,"2":2}} - [0,1,2] - {"0":1,"1":1,"2":1} - -- name: reduce with assignment of the accumulated value - args: - - -c - - 'reduce range(3) as $i ({}; .a = .), - reduce range(3) as $i ({}; .a = {v: .}), - reduce range(3) as $i ({}; . as $p | .a = $i | .b = $p)' - input: 'null' - expected: | - {"a":{"a":{"a":{}}}} - {"a":{"v":{"a":{"v":{"a":{"v":{}}}}}}} - {"a":2,"b":{"a":1,"b":{"a":0,"b":{}}}} - -- name: reduce with assignment of multiple values - args: - - -c - - 'reduce range(2) as $i ({"k":"k"}; .[.k] = ("x","y")), - reduce range(2) as $i ({}; (.a = 1), (.b = 2))' - input: 'null' - expected: | - {"k":"y","y":"y"} - {"b":2} - -- name: reduce with assignment of a shared value - args: - - -c - - '{"a":1} as $x | reduce range(2) as $i ({}; .[$i|tostring] = $x) | - [(.["0"].a = 9), $x]' - input: 'null' - expected: | - [{"0":{"a":9},"1":{"a":1}},{"a":1}] - -- name: reduce with assignment result reused - args: - - -c - - 'reduce range(3) as $i ({}; .[$i|tostring] = $i) as $r | - [($r | .["0"] = 9), $r]' - input: 'null' - expected: | - [{"0":9,"1":1,"2":2},{"0":0,"1":1,"2":2}] - -- name: foreach with assignment in update - args: - - -c - - '[foreach range(3) as $i ({}; .[$i|tostring] = $i)]' - input: 'null' - expected: | - [{"0":0},{"0":0,"1":1},{"0":0,"1":1,"2":2}] - - name: foreach iterator args: - 'foreach range(5) as $item (0; $item)' @@ -5051,6 +5022,46 @@ expected: | {"a":[{},{"b":[1,2,3]}]} +- name: getpath function against string + args: + - -c + - '[getpath([{"start":1,"end":3}]), getpath([{"start":-2,"end":null}]), getpath([1]), getpath([])]' + input: '"abcde"' + expected: | + ["bc","de","b","abcde"] + +- name: getpath function against string in a container + args: + - -c + - 'getpath(["a",{"start":0,"end":2}]), getpath(["a",1])' + input: '{"a":"abc"}' + expected: | + "ab" + "b" + +- name: getpath function against string round trip with path function + args: + - -c + - '[getpath(path(.[1:3])), getpath(path(.[1]))]' + input: '"abcde"' + expected: | + ["bc","b"] + +- name: getpath function against string round trip in a container + args: + - -c + - '. as $d | [path(.a[0:2]), path(.b[1])] | map(. as $p | $d | getpath($p))' + input: '{"a":"abc","b":"xyz"}' + expected: | + ["ab","y"] + +- name: getpath function against string with object key + args: + - 'getpath(["k"])' + input: '"abc"' + error: | + getpath(["k"]) cannot be applied to "abc": expected an object but got: string ("abc") + - name: getpath function error args: - 'getpath(["a",1,"b","c"])' @@ -5083,9 +5094,9 @@ expected: | {"a":[{"b":5}]} {"a":[{"b":5}],"b":0} - "getpath([\"a\",0,\"b\"]) cannot be applied to: object ({\"a\":0})" + "getpath([\"a\",0,\"b\"]) cannot be applied to {\"a\":0}: expected an array but got: number (0)" {"a":[{"b":5}]} - "getpath([\"a\",0,\"b\"]) cannot be applied to: object ({\"a\":[0,1]})" + "getpath([\"a\",0,\"b\"]) cannot be applied to {\"a\":[0,1]}: expected an object but got: number (0)" "getpath([\"a\",0,\"b\"]) cannot be applied to {\"a\":{\"b\":1}}: expected an array but got: object ({\"b\":1})" {"a":[{"b":5}]} {"a":[{"b":5,"c":3}]}