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:
raccmonteiro
2022-11-23 10:18:13 +00:00
committed by GitHub
parent b12ffb8888
commit f46c45343a
2 changed files with 67 additions and 59 deletions

View File

@ -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);
}