summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoritchyny <itchyny@cybozu.co.jp>2023-06-30 07:45:29 +0900
committerGitHub <noreply@github.com>2023-06-30 07:45:29 +0900
commitf88c4e5888d6d125695444d044df4bb55ad75888 (patch)
treef3053a37a7196e564d8c209b6bdae36714eae40e
parent03db5509cb46131321132df1bfa452155152617a (diff)
Move an example to the manual and regenerate man.test (#2639)
-rw-r--r--docs/content/manual/manual.yml6
-rw-r--r--docs/content/manual/v1.6/manual.yml6
-rw-r--r--tests/man.test60
3 files changed, 55 insertions, 17 deletions
diff --git a/docs/content/manual/manual.yml b/docs/content/manual/manual.yml
index 68cc091f..bfbde896 100644
--- a/docs/content/manual/manual.yml
+++ b/docs/content/manual/manual.yml
@@ -2301,10 +2301,12 @@ sections:
The `?` operator, used as `EXP?`, is shorthand for `try EXP`.
examples:
- - program: '[.[]|(.a)?]'
+ - program: '[.[] | .a?]'
input: '[{}, true, {"a":1}]'
output: ['[null, 1]']
-
+ - program: '[.[] | tonumber?]'
+ input: '["1", "invalid", "3", 4]'
+ output: ['[1, 3, 4]']
- title: Regular expressions
body: |
diff --git a/docs/content/manual/v1.6/manual.yml b/docs/content/manual/v1.6/manual.yml
index 09ced514..ba5c0c66 100644
--- a/docs/content/manual/v1.6/manual.yml
+++ b/docs/content/manual/v1.6/manual.yml
@@ -2200,10 +2200,12 @@ sections:
The `?` operator, used as `EXP?`, is shorthand for `try EXP`.
examples:
- - program: '[.[]|(.a)?]'
+ - program: '[.[] | .a?]'
input: '[{}, true, {"a":1}]'
output: ['[null, 1]']
-
+ - program: '[.[] | tonumber?]'
+ input: '["1", "invalid", "3", 4]'
+ output: ['[1, 3, 4]']
- title: Regular expressions
body: |
diff --git a/tests/man.test b/tests/man.test
index 1c6ff67e..b535362f 100644
--- a/tests/man.test
+++ b/tests/man.test
@@ -2,6 +2,18 @@
"Hello, world!"
"Hello, world!"
+. | tojson
+12345678909876543212345
+"12345678909876543212345"
+
+map([., . == 1]) | tojson
+[1, 1.000, 1.0, 100e-2]
+"[[1,true],[1.000,true],[1.0,true],[1.00,true]]"
+
+. as $big | [$big, $big + 1] | map(. > 10000000000000000000000000000000)
+10000000000000000000000000000001
+[true, false]
+
.foo
{"foo": 42, "bar": "less interesting data"}
42
@@ -163,11 +175,12 @@ null
-1
.[] | length
-[[1,2], "string", {"a":2}, null]
+[[1,2], "string", {"a":2}, null, -5]
2
6
1
0
+5
utf8bytelength
"\u03bc"
@@ -343,12 +356,12 @@ flatten
[{"foo": "bar"}, [{"foo": "baz"}]]
[{"foo": "bar"}, {"foo": "baz"}]
-range(2;4)
+range(2; 4)
null
2
3
-[range(2;4)]
+[range(2; 4)]
null
[2,3]
@@ -356,15 +369,15 @@ null
null
[0,1,2,3]
-[range(0;10;3)]
+[range(0; 10; 3)]
null
[0,3,6,9]
-[range(0;10;-1)]
+[range(0; 10; -1)]
null
[]
-[range(0;-5;-1)]
+[range(0; -5; -1)]
null
[0,-1,-2,-3,-4]
@@ -551,6 +564,10 @@ join(" ")
1
[1,2,4,8,16,32,64]
+[repeat(.*2, error)?]
+1
+[2]
+
[.,1]|until(.[0] < 1; [.[0] - 1, .[1] * .[0]])|.[1]
4
24
@@ -658,7 +675,7 @@ true
false
false
-if . == 0 then "zero" elif . == 1 then "one" else "many" end
+if . == 0 then "zero" elif . == 1 then "one" else "many" end
2
"many"
@@ -706,10 +723,14 @@ try error("some exception") catch .
true
"some exception"
-[.[]|(.a)?]
+[.[] | .a?]
[{}, true, {"a":1}]
[null, 1]
+[.[] | tonumber?]
+["1", "invalid", "3", 4]
+[1, 3, 4]
+
test("foo")
"foo"
true
@@ -841,8 +862,21 @@ true
{"foo": 42}
{"foo": 43}
-.[]|tonumber?
-["1", "hello", "3", 4]
-1
-3
-4
+.a = .b
+{"a": {"b": 10}, "b": 20}
+{"a":20,"b":20}
+
+.a |= .b
+{"a": {"b": 10}, "b": 20}
+{"a":10,"b":20}
+
+(.a, .b) = range(3)
+null
+{"a":0,"b":0}
+{"a":1,"b":1}
+{"a":2,"b":2}
+
+(.a, .b) |= range(3)
+null
+{"a":0,"b":0}
+