mirror of
https://github.com/wader/fq.git
synced 2024-12-25 14:23:18 +03:00
a3c33fc1f4
Also add tests for count, count_by, delta and delta_by
84 lines
1.9 KiB
Plaintext
84 lines
1.9 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,2], [[1], [2]]]
|
|
, [[1,2,2], [[1], [2,2]]]
|
|
, [[1,2,2,3], [[1], [2,2], [3]]]
|
|
) | assert("\(.[0]) | group"; .[1]; .[0] | group))
|
|
,
|
|
(([[], []]
|
|
, [[1], [[1,1]]]
|
|
, [[1,2], [[1,1], [2,1]]]
|
|
, [[1,2,2,2], [[1,1], [2,3]]]
|
|
, [[1,2,2,2,3], [[1,1], [2,3], [3,1]]]
|
|
) | assert("\(.[0]) | count"; .[1]; .[0] | count))
|
|
,
|
|
(([[], []]
|
|
, [[1], [[1,1]]]
|
|
, [[1,2], [[0,1], [1,1]]]
|
|
, [[1,2,2,2], [[0,3],[1,1]]]
|
|
, [[1,2,2,2,3], [[0,3],[1,2]]]
|
|
) | assert("\(.[0]) | count_by(.%2)"; .[1]; .[0] | count_by(.%2)))
|
|
,
|
|
([
|
|
[[], []],
|
|
[[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))
|
|
,
|
|
(([[], []]
|
|
, [[1], []]
|
|
, [[1,2], [1]]
|
|
, [[1,2,2,2], [1,0,0]]
|
|
, [[1,2,2,2,3], [1,0,0,1]]
|
|
) | assert("\(.[0]) | delta"; .[1]; .[0] | delta))
|
|
,
|
|
(([[], []]
|
|
, [[1], []]
|
|
, [[1,2], [3]]
|
|
, [[1,2,2,2], [3,4,4]]
|
|
, [[1,2,2,2,3], [3,4,4,5]]
|
|
) | assert("\(.[0]) | delta_by(.a+.b)"; .[1]; .[0] | delta_by(.a+.b)))
|
|
,
|
|
([
|
|
[[{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])))
|
|
)
|