Document intentional behavior difference
TODO:
- Consider changing
%behavior and document it. (jqperforms/as a floating-point-number operation, but%is something like(x as int) % (y as int).) - Consider making both
isfiniteandisinfinitereturnfalseforNaN - Document about comparisons including
NaN. Maybe also report it tojq.
#93
$ xq -nc '[nan, nan] | group_by(.)'
[[null,null]]
$ jq -nc '[nan, nan] | group_by(.)'
[[null],[null]]
$ xq -nc '[nan < nan, nan > nan]'
[false,false]
$ jq -nc '[nan < nan, nan > nan]'
[true,false]
Though I might change the group_by behavior.
#111
https://github.com/MiSawa/xq/blob/e25fa19baff073d0b563bbbe50ce5f819df3f988/tests/hand_written/regex.rs#L138
Also -- we currently use oniguruma (via onig crate), but we might want to use regex crate instead.
Maybe make flatten(0.1) mean flatten(0) or flatten(1) again? ref: https://twitter.com/itchyny/status/1503660699762913280
Edit: Be consistent about whether or not to handle objects https://twitter.com/itchyny/status/1503756509771354113
$ cargo run -- -nc '[1,2,3] | (.[{start:1}], .[{end:2}])'
Finished dev [unoptimized + debuginfo] target(s) in 0.16s
Running `target/debug/xq -nc '[1,2,3] | (.[{start:1}], .[{end:2}])'`
[2,3]
[1,2]
$ cargo run -- -nc '[1,2,3] | getpath([{start:1}])'
Finished dev [unoptimized + debuginfo] target(s) in 0.09s
Running `target/debug/xq -nc '[1,2,3] | getpath([{start:1}])'`
[2,3]
$ jq -nc '[1,2,3] | getpath([{start:1}])'
jq: error (at <unknown>): Start and end indices of an array slice must be numbers
[1] 1878799 exit 5 jq -nc '[1,2,3] | getpath([{start:1}])'
$ jq -nc '[1,2,3] | (.[{start:1}], .[{end:2}])'
jq: error (at <unknown>): Start and end indices of an array slice must be numbers
[1] 1878822 exit 5 jq -nc '[1,2,3] | (.[{start:1}], .[{end:2}])'
or change it to match the behavior of jq
❯ jq -n '0/0'
null
❯ xq -n '0/0'
Error: DivModByZero
❯ jq -n '1,"",1 | normals'
1
1
❯ xq -n '1,"",1 | normals'
1
Error: InvalidArgType("is_normal", "")
❯ jq -n 'isfinite'
false
❯ xq -n 'isfinite'
Error: InvalidArgType("is_infinite", null)
❯ jq -n 'ltrimstr("")'
null
❯ xq -n 'ltrimstr("")'
Error: InvalidArgType("startswith", null)
❯ jq -n 'rtrimstr("")'
null
❯ xq -n 'rtrimstr("")'
Error: InvalidArgType("endswith", null)
❯ jq -n '[{"Key":"x","Value":0},{"Name":"y","Value":1}] | from_entries'
{
"x": 0,
"y": 1
}
❯ xq -n '[{"Key":"x","Value":0},{"Name":"y","Value":1}] | from_entries'
Error: ObjectIndexByNonString(null)
❯ jq -n '[39] | implode | @html'
"'"
❯ xq -n '[39] | implode | @html'
"'"
❯ jq -n '"aGVsbG8====" | @base64d'
"hello"
❯ xq -n '"aGVsbG8====" | @base64d'
Error: InvalidAsBase64(InvalidByte(7, 61))
The behavior of ltrimstr, rtrimstr is useful when trimming all the strings recursively, but not sure how many people notice this behavior.
❯ jq -n '{a:{b:"hello world",c:["hello test"]},d:"hello sample"} | .. |= ltrimstr("hello ")'
{
"a": {
"b": "world",
"c": [
"test"
]
},
"d": "sample"
}
❯ xq -n '{a:{b:"hello world",c:["hello test"]},d:"hello sample"} | .. |= ltrimstr("hello ")'
Error: InvalidArgType("startswith", {"d": "hello sample", "a": {"c": ["hello test"], "b": "hello world"}})
When we use gsub, we need to filter by strings after all.
❯ jq -n '{a:{b:"hello world",c:["hello test"]},d:"hello sample"} | .. |= gsub("hello "; "")'
jq: error (at <unknown>): object ({"a":{"b":"...) cannot be matched, as it is not a string
❯ jq -n '{a:{b:"hello world",c:["hello test"]},d:"hello sample"} | (.. | strings) |= gsub("hello "; "")'
{
"a": {
"b": "world",
"c": [
"test"
]
},
"d": "sample"
}