Skip to content

Commit

Permalink
Define examples in the "examples" field instead of "example"
Browse files Browse the repository at this point in the history
Only examples defined in the "examples" field are generated, if they are
defined in "example", they are just ignored.

Also fix a bunch of incorrect tests.
  • Loading branch information
emanuele6 authored and nicowilliams committed Jul 18, 2023
1 parent 01dfd8b commit 15fd31d
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 16 deletions.
27 changes: 11 additions & 16 deletions docs/content/manual/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1721,10 +1721,10 @@ sections:
Emit a copy of the input string with its alphabetic characters (a-z and A-Z)
converted to the specified case.
example:
examples:
- program: 'ascii_upcase'
input: '"useful but not for é"'
output: '"USEFUL BUT NOT FOR é"'
output: ['"USEFUL BUT NOT FOR é"']

- title: "`while(cond; update)`"
body: |
Expand Down Expand Up @@ -2500,15 +2500,11 @@ sections:
To capture all the matches for each input string, use the idiom
`[ expr ]`, e.g. `[ scan(regex) ]`.
example:
examples:
- program: 'scan("c")'
input: '"abcdefabc"'
output: ['"c"', '"c"']

- program: 'scan("b")'
input: ("", "")
output: ['[]', '[]']

- title: "`split(regex; flags)`"
body: |
Expand All @@ -2517,10 +2513,10 @@ sections:
For backwards compatibility, when called with a single argument,
`split` splits on a string, not a regex.
example:
examples:
- program: 'split(", *"; null)'
input: '"ab,cd, ef"'
output: ['"ab","cd","ef"']
output: ['["ab","cd","ef"]']


- title: "`splits(regex)`, `splits(regex; flags)`"
Expand All @@ -2529,10 +2525,10 @@ sections:
These provide the same results as their `split` counterparts,
but as a stream instead of an array.
example:
examples:
- program: 'splits(", *")'
input: '("ab,cd", "ef, gh")'
output: ['"ab"', '"cd"', '"ef"', '"gh"']
input: '"ab,cd, ef, gh"'
output: ['"ab"','"cd"','"ef"','"gh"']

- title: "`sub(regex; tostring)`, `sub(regex; tostring; flags)`"
body: |
Expand All @@ -2546,9 +2542,8 @@ sections:
`tostring`, so a reference to a captured variable named "x"
would take the form: `"\(.x)"`.
example:

- program: 'sub("[^a-z]*(?<x>[a-z]*)"; "Z\(.x)"; "g")'
examples:
- program: 'sub("[^a-z]*(?<x>[a-z]+)"; "Z\(.x)"; "g")'
input: '"123abc456def"'
output: ['"ZabcZdef"']

Expand All @@ -2563,7 +2558,7 @@ sections:
replaced by `tostring`, after interpolation. If the second argument is a stream
of jq strings, then `gsub` will produce a corresponding stream of JSON strings.
example:
examples:
- program: 'gsub("(?<x>.)[^a]*"; "+\(.x)-")'
input: '"Abcabc"'
output: ['"+A-+a-"']
Expand Down
80 changes: 80 additions & 0 deletions jq.1.prebuilt

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

4 changes: 4 additions & 0 deletions tests/man.test

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

32 changes: 32 additions & 0 deletions tests/manonig.test

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

0 comments on commit 15fd31d

Please sign in to comment.