1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Fix manual source code to follow the schema definition

This commit is contained in:
itchyny
2023-07-22 15:38:25 +09:00
committed by Nico Williams
parent 9044f540bb
commit 34629ed223
5 changed files with 108 additions and 125 deletions

View File

@@ -329,13 +329,13 @@ sections:
examples:
- program: '.foo'
input: '{"foo": 42, "bar": "less interesting data"}'
output: [42]
output: ['42']
- program: '.foo'
input: '{"notfoo": true, "alsonotfoo": false}'
output: ['null']
- program: '.["foo"]'
input: '{"foo": 42}'
output: [42]
output: ['42']
- title: "Optional Object Identifier-Index: `.foo?`"
body: |
@@ -346,13 +346,13 @@ sections:
examples:
- program: '.foo?'
input: '{"foo": 42, "bar": "less interesting data"}'
output: [42]
output: ['42']
- program: '.foo?'
input: '{"notfoo": true, "alsonotfoo": false}'
output: ['null']
- program: '.["foo"]?'
input: '{"foo": 42}'
output: [42]
output: ['42']
- program: '[.foo?]'
input: '[1,2]'
output: ['[]']
@@ -506,7 +506,7 @@ sections:
examples:
- program: '(. + 2) * 5'
input: '1'
output: [15]
output: ['15']
- title: Types and Values
body: |
@@ -713,8 +713,8 @@ sections:
examples:
- program: '10 / . * 3'
input: 5
output: [6]
input: '5'
output: ['6']
- program: '. / ", "'
input: '"a, b,c,d, e"'
output: ['["a","b,c,d","e"]']
@@ -749,7 +749,7 @@ sections:
examples:
- program: '.[] | length'
input: '[[1,2], "string", {"a":2}, null, -5]'
output: [2, 6, 1, 0, 5]
output: ['2', '6', '1', '0', '5']
- title: "`utf8bytelength`"
@@ -761,7 +761,7 @@ sections:
examples:
- program: 'utf8bytelength'
input: '"\u03bc"'
output: [2]
output: ['2']
- title: "`keys`, `keys_unsorted`"
body: |
@@ -1003,7 +1003,7 @@ sections:
examples:
- program: '1, empty, 2'
input: 'null'
output: [1, 2]
output: ['1', '2']
- program: '[1,2,empty,3]'
input: 'null'
output: ['[1,2,3]']
@@ -1084,7 +1084,7 @@ sections:
output: ['"abc"']
- program: add
input: '[1, 2, 3]'
output: [6]
output: ['6']
- program: add
input: '[]'
output: ["null"]
@@ -1233,7 +1233,7 @@ sections:
examples:
- program: '.[] | tonumber'
input: '[1, "1"]'
output: [1, 1]
output: ['1', '1']
- title: "`tostring`"
body: |
@@ -1583,10 +1583,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: |
@@ -1683,11 +1683,8 @@ sections:
- '1'
- program: 'recurse(. * .; . < 20)'
input: 2
output:
- 2
- 4
- 16
input: '2'
output: ['2', '4', '16']
- title: "`walk(f)`"
body: |
@@ -2062,7 +2059,7 @@ sections:
else
"many"
end
input: 2
input: '2'
output: ['"many"']
- title: "`>`, `>=`, `<=`, `<`"
@@ -2077,7 +2074,7 @@ sections:
examples:
- program: '. < 5'
input: 2
input: '2'
output: ['true']
- title: "`and`, `or`, `not`"
@@ -2133,10 +2130,10 @@ sections:
examples:
- program: '.foo // 42'
input: '{"foo": 19}'
output: [19]
output: ['19']
- program: '.foo // 42'
input: '{}'
output: [42]
output: ['42']
- title: try-catch
body: |
@@ -2306,7 +2303,7 @@ sections:
- program: '[ match("."; "g")] | length'
input: '"abc"'
output: [3]
output: ['3']
- title: "`capture(val)`, `capture(regex; flags)`"
@@ -2330,24 +2327,20 @@ 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: |
For backwards compatibility, `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)`"
@@ -2356,10 +2349,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; string; flags)`"
body: |
@@ -2371,10 +2364,10 @@ sections:
constructed by `capture`) to `tostring`, so a reference to a captured
variable named "x" would take the form: `"\(.x)"`.
example:
- program: 'sub("^[^a-z]*(?<x>[a-z]*).*")'
input: '"123abc456"'
output: '"ZabcZabc"'
examples:
- program: 'sub("[^a-z]*(?<x>[a-z]+)"; "Z\(.x)"; "g")'
input: '"123abc456def"'
output: ['"ZabcZdef"']
- title: "`gsub(regex; string)`, `gsub(regex; string; flags)`"
@@ -2383,10 +2376,10 @@ sections:
`gsub` is like `sub` but all the non-overlapping occurrences of the regex are
replaced by the string, after interpolation.
example:
examples:
- program: 'gsub("(?<x>.)[^a]*"; "+\(.x)-")'
input: '"Abcabc"'
output: '"+A-+a-"'
output: ['"+A-+a-"']
- title: Advanced features