xq icon indicating copy to clipboard operation
xq copied to clipboard

Document intentional behavior difference

Open MiSawa opened this issue 3 years ago • 12 comments

TODO:

  • Consider changing % behavior and document it. (jq performs / as a floating-point-number operation, but % is something like (x as int) % (y as int).)
  • Consider making both isfinite and isinfinite return false for NaN
  • Document about comparisons including NaN. Maybe also report it to jq.

MiSawa avatar Feb 26 '22 14:02 MiSawa

#93

MiSawa avatar Feb 28 '22 10:02 MiSawa

$ 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]

MiSawa avatar Mar 06 '22 09:03 MiSawa

Though I might change the group_by behavior.

MiSawa avatar Mar 06 '22 09:03 MiSawa

#111

MiSawa avatar Mar 12 '22 06:03 MiSawa

https://github.com/MiSawa/xq/blob/e25fa19baff073d0b563bbbe50ce5f819df3f988/tests/hand_written/regex.rs#L138

MiSawa avatar Mar 13 '22 03:03 MiSawa

Also -- we currently use oniguruma (via onig crate), but we might want to use regex crate instead.

MiSawa avatar Mar 13 '22 03:03 MiSawa

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

MiSawa avatar Mar 15 '22 09:03 MiSawa

$ 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

MiSawa avatar Apr 24 '22 01:04 MiSawa

❯ 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)

itchyny avatar Apr 24 '22 02:04 itchyny

❯ 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)

itchyny avatar Apr 24 '22 03:04 itchyny

❯ jq -n '[39] | implode | @html'
"&apos;"

❯ xq -n '[39] | implode | @html'
"&#x27;"

❯ jq -n '"aGVsbG8====" | @base64d'
"hello"

❯ xq -n '"aGVsbG8====" | @base64d'
Error: InvalidAsBase64(InvalidByte(7, 61))

itchyny avatar Apr 24 '22 03:04 itchyny

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"
}

itchyny avatar Apr 25 '22 01:04 itchyny