mirror of
https://github.com/nushell/nushell.git
synced 2025-08-13 22:38:25 +02:00
Uniq: --count
flag to count occurences (#2017)
* uniq: Add counting option (WIP!) Usage: fetch https://raw.githubusercontent.com/timbray/topfew/master/test/data/access-1k | lines | wrap item | uniq | sort-by count | last 10 * uniq: Add first test * uniq: Re-enable the non-counting variant. * uniq: Also handle primitive lines. * uniq: Update documentation * uniq: Final comment about error handling. Let's get some feedback * uniq: Address review comments. Not happy with the way I create a TypeError. There must be a cleaner way. Anyway, good for shipping. * uniq: Use Labeled_error as suggested by jturner in chat. * uniq: Return error directly. Co-authored-by: Christoph Siedentop <christoph@siedentop.name>
This commit is contained in:
@ -140,3 +140,26 @@ fn uniq_when_keys_out_of_order() {
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uniq_counting() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo '["A", "B", "A"]'
|
||||
| from json
|
||||
| wrap item
|
||||
| uniq --count
|
||||
"#
|
||||
));
|
||||
let expected = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo '[{"item": "A", "count": 2}, {"item": "B", "count": 1}]'
|
||||
| from json
|
||||
"#
|
||||
));
|
||||
print!("{}", actual.out);
|
||||
print!("{}", expected.out);
|
||||
assert_eq!(actual.out, expected.out);
|
||||
}
|
||||
|
Reference in New Issue
Block a user