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,13 +1,8 @@
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
use nu_test_support::playground::Playground;
use nu_test_support::{nu, pipeline};
#[test]
fn discards_rows_where_given_column_is_empty() {
Playground::setup("compact_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"los_tres_amigos.json",
r#"
let sample_json = r#"
{
"amigos": [
{"name": "Yehuda", "rusty_luck": 1},
@ -16,35 +11,29 @@ fn discards_rows_where_given_column_is_empty() {
{"name":"GorbyPuff"}
]
}
"#,
)]);
"#;
let actual = nu!(
cwd: dirs.test(), pipeline(
"
open los_tres_amigos.json
let actual = nu!(pipeline(&format!(
"
{sample_json}
| get amigos
| compact rusty_luck
| length
"
));
)));
assert_eq!(actual.out, "3");
});
assert_eq!(actual.out, "3");
}
#[test]
fn discards_empty_rows_by_default() {
Playground::setup("compact_test_2", |dirs, _| {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
let actual = nu!(pipeline(
r#"
echo "[1,2,3,14,null]"
| from json
| compact
| length
"#
));
));
assert_eq!(actual.out, "4");
});
assert_eq!(actual.out, "4");
}