1
1
mirror of https://github.com/wader/fq.git synced 2024-12-01 02:30:32 +03:00
fq/pkg/interp/funcs_test.jq
Mattias Wadman 26d9650b0e interp: Refactor radix* into toradix($base)/fromradix($base)
There is also toradix($base; $table)/fromradix($base; $table) for custom symbols and bases.
Add radix tests

Part of cleaning up all convert/tranformation functions into to/from*.

Remove number_to_bytes as with better binary support it can be written as:
1234 | tobytes | [.[range(.size)]] and soon as 1234 | tobytes | explode
2022-02-11 01:28:39 +01:00

49 lines
1.1 KiB
Plaintext

include "assert";
include "funcs";
(
([
".",
".a",
".a[0]",
".a[123].bb",
".[123].a",
".[123][123].a",
".\"b b\"",
".\"a \\\\ b\"",
".\"a \\\" b\""
][] | assert("\(.) | expr_to_path | path_to_expr"; .; expr_to_path | path_to_expr))
,
([
[[], []],
[[1], [[1]]],
[[1,1], [[1,1]]],
[[1,1,2], [[1,1],[2]]],
[[1,1,2,2], [[1,1],[2,2]]],
[[1,2,2,1], [[1],[2,2],[1]]]
][] | assert("\(.) | streaks"; .[1]; .[0] | streaks))
,
([
[[{a:1},{a:1},{a:2}], [[{a:1},{a:1}],[{a:2}]]]
][] | assert("\(.) | streaks_by"; .[1]; .[0] | streaks_by(.a)))
,
([
[[], 1, []],
[[], 2, []],
[[1], 1, [[1]]],
[[1], 2, [[1]]],
[[1,2], 1, [[1],[2]]],
[[1,2], 2, [[1,2]]],
[[1,2,3,4], 2, [[1,2],[3,4]]],
[[1,2,3,4], 3, [[1,2,3],[4]]],
["", 1, []],
["", 2, []],
["1", 1, ["1"]],
["1", 2, ["1"]],
["12", 1, ["1","2"]],
["12", 2, ["12"]],
["1234", 2, ["12","34"]],
["1234", 3, ["123","4"]]
][] | . as $t | assert("\($t[0]) | chunk(\($t[1]))"; $t[2]; $t[0] | chunk($t[1])))
)