Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document intentional behavior difference #82

Open
MiSawa opened this issue Feb 26, 2022 · 12 comments
Open

Document intentional behavior difference #82

MiSawa opened this issue Feb 26, 2022 · 12 comments
Labels
documentation Improvements or additions to documentation

Comments

@MiSawa
Copy link
Owner

MiSawa commented Feb 26, 2022

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
Copy link
Owner Author

MiSawa commented Feb 28, 2022

#93

@MiSawa
Copy link
Owner Author

MiSawa commented Mar 6, 2022

$ 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
Copy link
Owner Author

MiSawa commented Mar 6, 2022

Though I might change the group_by behavior.

@MiSawa
Copy link
Owner Author

MiSawa commented Mar 12, 2022

#111

@MiSawa MiSawa added the documentation Improvements or additions to documentation label Mar 12, 2022
@MiSawa
Copy link
Owner Author

MiSawa commented Mar 13, 2022

// I'd want this to return a-1 b-234 c but this is what jq does.

@MiSawa
Copy link
Owner Author

MiSawa commented Mar 13, 2022

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

@MiSawa
Copy link
Owner Author

MiSawa commented Mar 15, 2022

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
Copy link
Owner Author

MiSawa commented Apr 24, 2022

$ 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

@itchyny
Copy link
Collaborator

itchyny commented Apr 24, 2022

❯ 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
Copy link
Collaborator

itchyny commented Apr 24, 2022

❯ 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
Copy link
Collaborator

itchyny commented Apr 24, 2022

❯ 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
Copy link
Collaborator

itchyny commented Apr 25, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants