mirror of
https://github.com/wader/fq.git
synced 2024-12-18 02:41:44 +03:00
Merge pull request #62 from wader/bitops-doc-err-tests
interp: Document bit opts funcs and add some error tests
This commit is contained in:
commit
0bad0ae27d
@ -250,7 +250,6 @@ fq can be used as a scrip interpreter:
|
|||||||
- [gojq's differences to jq](https://github.com/itchyny/gojq#difference-to-jq),
|
- [gojq's differences to jq](https://github.com/itchyny/gojq#difference-to-jq),
|
||||||
notable is support for arbitrary-precision integers.
|
notable is support for arbitrary-precision integers.
|
||||||
- Supports hexdecimal `0xab`, octal `0o77` and binary `0b101` integer literals.
|
- Supports hexdecimal `0xab`, octal `0o77` and binary `0b101` integer literals.
|
||||||
- Has bitwise operators, `band`, `bor`, `bxor`, `bsl`, `bsr`, `bnot`.
|
|
||||||
- Try include `include "file?";` that don't fail if file is missing.
|
- Try include `include "file?";` that don't fail if file is missing.
|
||||||
- Some values can act as a object with keys even when it's an array, number etc.
|
- Some values can act as a object with keys even when it's an array, number etc.
|
||||||
- There can be keys hidden from `keys` and `[]`.
|
- There can be keys hidden from `keys` and `[]`.
|
||||||
@ -269,6 +268,8 @@ notable is support for arbitrary-precision integers.
|
|||||||
- `diff/2` produce diff object between two values.
|
- `diff/2` produce diff object between two values.
|
||||||
- `delta/0`, `delta_by/1`, array with difference between all consecutive pairs.
|
- `delta/0`, `delta_by/1`, array with difference between all consecutive pairs.
|
||||||
- `chunk/1`, split array or string into even chunks
|
- `chunk/1`, split array or string into even chunks
|
||||||
|
- Bitwise functions `band`, `bor`, `bxor`, `bsl`, `bsr` and `bnot`. Works the same as jq math functions,
|
||||||
|
unary uses input and if more than one argument all as arguments ignoring the input. Ex: `1 | bnot` `bsl(1; 3)`
|
||||||
- Adds some decode value specific functions:
|
- Adds some decode value specific functions:
|
||||||
- `root/0` tree root for value
|
- `root/0` tree root for value
|
||||||
- `buffer_root/0` root value of buffer for value
|
- `buffer_root/0` root value of buffer for value
|
||||||
|
24
pkg/interp/testdata/bitops.fqtest
vendored
24
pkg/interp/testdata/bitops.fqtest
vendored
@ -4,24 +4,48 @@ null> 0, -1, 1208925819614629174706175, -1208925819614629174706176 | bnot
|
|||||||
0
|
0
|
||||||
-1208925819614629174706176
|
-1208925819614629174706176
|
||||||
1208925819614629174706175
|
1208925819614629174706175
|
||||||
|
null> null | bnot
|
||||||
|
error: cannot bnot: null
|
||||||
|
null> bnot(1)
|
||||||
|
error: repl:1:0: function not defined: bnot/1
|
||||||
null> [0,0], [8,1], [0xffff_ffff_ffff_ffff,1] | bsl(.[0]; .[1])
|
null> [0,0], [8,1], [0xffff_ffff_ffff_ffff,1] | bsl(.[0]; .[1])
|
||||||
0
|
0
|
||||||
16
|
16
|
||||||
36893488147419103230
|
36893488147419103230
|
||||||
|
null> bsl(1)
|
||||||
|
error: repl:1:0: function not defined: bsl/1
|
||||||
|
null> bsl(null; 1)
|
||||||
|
error: cannot bsl: null and number
|
||||||
null> [0,0], [8,1], [0x1_ffff_ffff_ffff_fffe,1] | bsr(.[0]; .[1])
|
null> [0,0], [8,1], [0x1_ffff_ffff_ffff_fffe,1] | bsr(.[0]; .[1])
|
||||||
0
|
0
|
||||||
4
|
4
|
||||||
18446744073709551615
|
18446744073709551615
|
||||||
|
null> bsr(1)
|
||||||
|
error: repl:1:0: function not defined: bsr/1
|
||||||
|
null> bsr(null; 1)
|
||||||
|
error: cannot bsr: null and number
|
||||||
null> [0,0], [0xffff_ffff_ffff_ffff_ffff,0x1234], [0x1234,0xffff_ffff_ffff_ffff_ffff,0x1234] | band(.[0]; .[1])
|
null> [0,0], [0xffff_ffff_ffff_ffff_ffff,0x1234], [0x1234,0xffff_ffff_ffff_ffff_ffff,0x1234] | band(.[0]; .[1])
|
||||||
0
|
0
|
||||||
4660
|
4660
|
||||||
4660
|
4660
|
||||||
|
null> band(1)
|
||||||
|
error: repl:1:0: function not defined: band/1
|
||||||
|
null> band(null; 1)
|
||||||
|
error: cannot band: null and number
|
||||||
null> [0,0], [0xffff_ffff_ffff_ffff_0000,0x1234], [0x1234,0xffff_ffff_ffff_ffff_0000,0x1234] | bor(.[0]; .[1])
|
null> [0,0], [0xffff_ffff_ffff_ffff_0000,0x1234], [0x1234,0xffff_ffff_ffff_ffff_0000,0x1234] | bor(.[0]; .[1])
|
||||||
0
|
0
|
||||||
1208925819614629174645300
|
1208925819614629174645300
|
||||||
1208925819614629174645300
|
1208925819614629174645300
|
||||||
|
null> bor(1)
|
||||||
|
error: repl:1:0: function not defined: bor/1
|
||||||
|
null> bor(null; 1)
|
||||||
|
error: cannot bor: null and number
|
||||||
null> [0,0], [0xffff_ffff_ffff_ffff_ffff,0x1234], [0x1234,0xffff_ffff_ffff_ffff_ffff,0x1234] | bxor(.[0]; .[1])
|
null> [0,0], [0xffff_ffff_ffff_ffff_ffff,0x1234], [0x1234,0xffff_ffff_ffff_ffff_ffff,0x1234] | bxor(.[0]; .[1])
|
||||||
0
|
0
|
||||||
1208925819614629174701515
|
1208925819614629174701515
|
||||||
1208925819614629174701515
|
1208925819614629174701515
|
||||||
|
null> bxor(1)
|
||||||
|
error: repl:1:0: function not defined: bxor/1
|
||||||
|
null> bxor(null; 1)
|
||||||
|
error: cannot bxor: null and number
|
||||||
null> ^D
|
null> ^D
|
||||||
|
Loading…
Reference in New Issue
Block a user