mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
uniq
code refactoring (#7188)
# Description While trying to add a new `uniq-by` command I refactored the `uniq` command code to understand it and try to reuse. I think this is more compact and easier to understand. The part that I think it's a little confusing in this refactor is the conditions inside `.filters()`, for example: `!flag_show_repeated || (value.1 > 1)`. I could use `if (flag_show_repeated) {value.1 > 1} else {true}` but it is more verbose, what do you think? PS: Not sure if you like this kind of PR, sorry if not. # Tests + Formatting I also added a test where the `uniq` has a table as input.
This commit is contained in:
@ -230,3 +230,24 @@ fn uniq_simple_vals_strs() {
|
||||
print!("{}", expected.out);
|
||||
assert_eq!(actual.out, expected.out);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_table() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
[[fruit day]; [apple monday] [apple friday] [apple monday] [pear monday] [orange tuesday]]
|
||||
| uniq
|
||||
"#
|
||||
));
|
||||
|
||||
let expected = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [[fruit day]; [apple monday] [apple friday] [pear monday] [orange tuesday]]
|
||||
"#
|
||||
));
|
||||
print!("{}", actual.out);
|
||||
print!("{}", expected.out);
|
||||
assert_eq!(actual.out, expected.out);
|
||||
}
|
||||
|
Reference in New Issue
Block a user