Skip to content

Commit

Permalink
Add a regression test for negative indices and fix a pick/1 test
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Aug 16, 2023
1 parent d0ab9f7 commit 6766203
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions docs/content/manual/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1048,10 +1048,11 @@ sections:
- title: "`pick(pathexps)`"
body: |
Emit the projection of the input object or array defined by the specified
sequence of path expressions, such that if p is any one of these specifications,
then `(. | p)` will evaluate to the same value as `(. | pick(pathexps) | p)`.
For arrays, negative indices and .[m:n] specifications should not be used.
Emit the projection of the input object or array defined by the
specified sequence of path expressions, such that if `p` is any
one of these specifications, then `(. | p)` will evaluate to the
same value as `(. | pick(pathexps) | p)`. For arrays, negative
indices and `.[m:n]` specifications should not be used.
examples:
- program: 'pick(.a, .b.c, .x)'
Expand Down
2 changes: 1 addition & 1 deletion jq.1.prebuilt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ null
2
3

.[-2]
[.[-4,-3,-2,-1,0,1,2,3]]
[1,2,3]
2
[null,1,2,3,1,2,3,null]

[range(0;10)]
null
Expand Down Expand Up @@ -1052,9 +1052,9 @@ pick(first|first)
[[10]]

# negative indices in path expressions (since last/1 is .[-1])
pick(last)
[[10,20],30]
[null,30]
try pick(last) catch .
[1,2]
"Out of bounds negative array index"

#
# Assignment
Expand Down

0 comments on commit 6766203

Please sign in to comment.