Skip to content

Commit

Permalink
Clean up tests containing unnecessary cwd: tokens (nushell#9692)
Browse files Browse the repository at this point in the history
# Description
The working directory doesn't have to be set for those tests (or would
be the default anyways). When appropriate also remove calls to the
`pipeline()` function. In most places kept the diff minimal and only
removed the superfluous part to not pollute the blame view. With simpler
tests also simplified things to make them more readable overall (this
included removal of the raw string literal).

Work for nushell#8670
  • Loading branch information
sholderbach committed Jul 17, 2023
1 parent 48271d8 commit 656f707
Show file tree
Hide file tree
Showing 70 changed files with 611 additions and 1,344 deletions.
77 changes: 22 additions & 55 deletions crates/nu-cmd-extra/tests/commands/bytes/starts_with.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,128 +2,98 @@ use nu_test_support::nu;

#[test]
fn basic_binary_starts_with() {
let actual = nu!(
cwd: ".",
r#"
let actual = nu!(r#"
"hello world" | into binary | bytes starts-with 0x[68 65 6c 6c 6f]
"#
);
"#);

assert_eq!(actual.out, "true");
}

#[test]
fn basic_string_fails() {
let actual = nu!(
cwd: ".",
r#"
let actual = nu!(r#"
"hello world" | bytes starts-with 0x[68 65 6c 6c 6f]
"#
);
"#);

assert!(actual.err.contains("command doesn't support"));
assert_eq!(actual.out, "");
}

#[test]
fn short_stream_binary() {
let actual = nu!(
cwd: ".",
r#"
let actual = nu!(r#"
nu --testbin repeater (0x[01]) 5 | bytes starts-with 0x[010101]
"#
);
"#);

assert_eq!(actual.out, "true");
}

#[test]
fn short_stream_mismatch() {
let actual = nu!(
cwd: ".",
r#"
let actual = nu!(r#"
nu --testbin repeater (0x[010203]) 5 | bytes starts-with 0x[010204]
"#
);
"#);

assert_eq!(actual.out, "false");
}

#[test]
fn short_stream_binary_overflow() {
let actual = nu!(
cwd: ".",
r#"
let actual = nu!(r#"
nu --testbin repeater (0x[01]) 5 | bytes starts-with 0x[010101010101]
"#
);
"#);

assert_eq!(actual.out, "false");
}

#[test]
fn long_stream_binary() {
let actual = nu!(
cwd: ".",
r#"
let actual = nu!(r#"
nu --testbin repeater (0x[01]) 32768 | bytes starts-with 0x[010101]
"#
);
"#);

assert_eq!(actual.out, "true");
}

#[test]
fn long_stream_binary_overflow() {
// .. ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
let actual = nu!(
cwd: ".",
r#"
let actual = nu!(r#"
nu --testbin repeater (0x[01]) 32768 | bytes starts-with (0..32768 | each {|| 0x[01] } | bytes collect)
"#
);
"#);

assert_eq!(actual.out, "false");
}

#[test]
fn long_stream_binary_exact() {
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
let actual = nu!(
cwd: ".",
r#"
let actual = nu!(r#"
nu --testbin repeater (0x[01020304]) 8192 | bytes starts-with (0..<8192 | each {|| 0x[01020304] } | bytes collect)
"#
);
"#);

assert_eq!(actual.out, "true");
}

#[test]
fn long_stream_string_exact() {
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
let actual = nu!(
cwd: ".",
r#"
let actual = nu!(r#"
nu --testbin repeater hell 8192 | bytes starts-with (0..<8192 | each {|| "hell" | into binary } | bytes collect)
"#
);
"#);

assert_eq!(actual.out, "true");
}

#[test]
fn long_stream_mixed_exact() {
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
let actual = nu!(
cwd: ".",
r#"
let actual = nu!(r#"
let binseg = (0..<2048 | each {|| 0x[003d9fbf] } | bytes collect)
let strseg = (0..<2048 | each {|| "hell" | into binary } | bytes collect)
nu --testbin repeat_bytes 003d9fbf 2048 68656c6c 2048 | bytes starts-with (bytes build $binseg $strseg)
"#
);
"#);

assert_eq!(
actual.err, "",
Expand All @@ -135,15 +105,12 @@ fn long_stream_mixed_exact() {
#[test]
fn long_stream_mixed_overflow() {
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
let actual = nu!(
cwd: ".",
r#"
let actual = nu!(r#"
let binseg = (0..<2048 | each {|| 0x[003d9fbf] } | bytes collect)
let strseg = (0..<2048 | each {|| "hell" | into binary } | bytes collect)
nu --testbin repeat_bytes 003d9fbf 2048 68656c6c 2048 | bytes starts-with (bytes build $binseg $strseg 0x[01])
"#
);
"#);

assert_eq!(
actual.err, "",
Expand Down
65 changes: 19 additions & 46 deletions crates/nu-command/tests/commands/assignment/append_assign.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
use nu_test_support::{nu, pipeline};
use nu_test_support::nu;

#[test]
fn append_assign_int() {
let actual = nu!(
cwd: ".", pipeline(
r#"
let actual = nu!(r#"
mut a = [1 2];
$a ++= [3 4];
$a
"#
));
"#);

let expected = nu!(
cwd: ".", pipeline(
r#"
let expected = nu!(r#"
[1 2 3 4]
"#
));
"#);

print!("{}", actual.out);
print!("{}", expected.out);
Expand All @@ -25,21 +19,15 @@ fn append_assign_int() {

#[test]
fn append_assign_string() {
let actual = nu!(
cwd: ".", pipeline(
r#"
let actual = nu!(r#"
mut a = [a b];
$a ++= [c d];
$a
"#
));
"#);

let expected = nu!(
cwd: ".", pipeline(
r#"
let expected = nu!(r#"
[a b c d]
"#
));
"#);

print!("{}", actual.out);
print!("{}", expected.out);
Expand All @@ -48,21 +36,15 @@ fn append_assign_string() {

#[test]
fn append_assign_any() {
let actual = nu!(
cwd: ".", pipeline(
r#"
let actual = nu!(r#"
mut a = [1 2 a];
$a ++= [b 3];
$a
"#
));
"#);

let expected = nu!(
cwd: ".", pipeline(
r#"
let expected = nu!(r#"
[1 2 a b 3]
"#
));
"#);

print!("{}", actual.out);
print!("{}", expected.out);
Expand All @@ -71,21 +53,15 @@ fn append_assign_any() {

#[test]
fn append_assign_both_empty() {
let actual = nu!(
cwd: ".", pipeline(
r#"
let actual = nu!(r#"
mut a = [];
$a ++= [];
$a
"#
));
"#);

let expected = nu!(
cwd: ".", pipeline(
r#"
let expected = nu!(r#"
[]
"#
));
"#);

print!("{}", actual.out);
print!("{}", expected.out);
Expand All @@ -94,14 +70,11 @@ fn append_assign_both_empty() {

#[test]
fn append_assign_type_mismatch() {
let actual = nu!(
cwd: ".", pipeline(
r#"
let actual = nu!(r#"
mut a = [1 2];
$a ++= [a];
$a | to json -r;
"#
));
"#);

assert_eq!(actual.out, r#"[1,2,"a"]"#);
}
16 changes: 4 additions & 12 deletions crates/nu-command/tests/commands/date/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,18 @@ use nu_test_support::{nu, pipeline};

#[test]
fn formatter_not_valid() {
let actual = nu!(
cwd: ".", pipeline(
r#"
let actual = nu!(r#"
date now | date format '%N'
"#
)
);
"#);

assert!(actual.err.contains("invalid format"));
}

#[test]
fn fails_without_input() {
let actual = nu!(
cwd: ".", pipeline(
r#"
let actual = nu!(r#"
date format "%c"
"#
)
);
"#);

assert!(actual.err.contains("Pipeline empty"));
}
Expand Down
9 changes: 3 additions & 6 deletions crates/nu-command/tests/commands/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use nu_test_support::{nu, pipeline};

#[test]
fn flatten_nested_tables_with_columns() {
let actual = nu!(
cwd: ".", pipeline(
let actual = nu!(pipeline(
r#"
echo [[origin, people]; [Ecuador, ('Andres' | wrap name)]]
[[origin, people]; [Nu, ('nuno' | wrap name)]]
Expand All @@ -20,8 +19,7 @@ fn flatten_nested_tables_with_columns() {

#[test]
fn flatten_nested_tables_that_have_many_columns() {
let actual = nu!(
cwd: ".", pipeline(
let actual = nu!(pipeline(
r#"
echo [[origin, people]; [Ecuador, (echo [[name, meal]; ['Andres', 'arepa']])]]
[[origin, people]; [USA, (echo [[name, meal]; ['Katz', 'nurepa']])]]
Expand All @@ -36,8 +34,7 @@ fn flatten_nested_tables_that_have_many_columns() {

#[test]
fn flatten_nested_tables() {
let actual = nu!(
cwd: ".", pipeline(
let actual = nu!(pipeline(
r#"
echo [[Andrés, Nicolás, Robalino]] | flatten | get 1
"#
Expand Down
Loading

0 comments on commit 656f707

Please sign in to comment.