Remove file I/O from tests that don't need it (#11182)

# Description

This PR implements modifications to command tests that write unnecessary
json and csv to disk then load it with open, by using nuon literals
instead.

- Fixes #7189



# User-Facing Changes
None

# Tests + Formatting
This only affects existing tests, which still pass.
This commit is contained in:
Renan Ribeiro
2023-11-29 19:21:34 -03:00
committed by GitHub
parent d08e254d16
commit 54d73748e4
20 changed files with 414 additions and 760 deletions

View File

@ -1,61 +1,45 @@
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
use nu_test_support::playground::Playground;
use nu_test_support::{nu, pipeline};
#[test]
fn wrap_rows_into_a_row() {
Playground::setup("wrap_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"los_tres_caballeros.txt",
r#"
first_name,last_name
Andrés,Robalino
JT,Turner
Yehuda,Katz
"#,
)]);
let sample = r#"
[[first_name, last_name];
[Andrés, Robalino],
[JT, Turner],
[Yehuda, Katz]]
"#;
let actual = nu!(
cwd: dirs.test(), pipeline(
"
open los_tres_caballeros.txt
| from csv
let actual = nu!(pipeline(&format!(
"
{sample}
| wrap caballeros
| get caballeros
| get 0
| get last_name
"
));
)));
assert_eq!(actual.out, "Robalino");
})
assert_eq!(actual.out, "Robalino");
}
#[test]
fn wrap_rows_into_a_table() {
Playground::setup("wrap_test_2", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"los_tres_caballeros.txt",
r#"
first_name,last_name
Andrés,Robalino
JT,Turner
Yehuda,Katz
"#,
)]);
let sample = r#"
[[first_name, last_name];
[Andrés, Robalino],
[JT, Turner],
[Yehuda, Katz]]
"#;
let actual = nu!(
cwd: dirs.test(), pipeline(
"
open los_tres_caballeros.txt
| from csv
let actual = nu!(pipeline(&format!(
"
{sample}
| get last_name
| wrap caballero
| get 2
| get caballero
"
));
)));
assert_eq!(actual.out, "Katz");
})
assert_eq!(actual.out, "Katz");
}