mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 20:17:44 +02:00
nu-cli refactor moving commands into their own crate nu-command (#2910)
* move commands, futures.rs, script.rs, utils * move over maybe_print_errors * add nu_command crate references to nu_cli * in commands.rs open up to pub mod from pub(crate) * nu-cli, nu-command, and nu tests are now passing * cargo fmt * clean up nu-cli/src/prelude.rs * code cleanup * for some reason lex.rs was not formatted, may be causing my error * remove mod completion from lib.rs which was not being used along with quickcheck macros * add in allow unused imports * comment out one failing external test; comment out one failing internal test * revert commenting out failing tests; something else might be going on; someone with a windows machine should check and see what is going on with these failing windows tests * Update Cargo.toml Extend the optional features to nu-command Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
This commit is contained in:
@ -1,29 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn adds_a_row_to_the_end() {
|
||||
Playground::setup("append_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.txt",
|
||||
r#"
|
||||
Andrés N. Robalino
|
||||
Jonathan Turner
|
||||
Yehuda Katz
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.txt
|
||||
| lines
|
||||
| append "pollo loco"
|
||||
| nth 3
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "pollo loco");
|
||||
})
|
||||
}
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -1,79 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn cal_full_year() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
cal -y --full-year 2010 | first | to json
|
||||
"#
|
||||
));
|
||||
|
||||
let first_week_2010_json = r#"{"year":2010,"sunday":null,"monday":null,"tuesday":null,"wednesday":null,"thursday":null,"friday":1,"saturday":2}"#;
|
||||
|
||||
assert_eq!(actual.out, first_week_2010_json);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cal_february_2020_leap_year() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
cal -ym --full-year 2020 --month-names | where month == "february" | to json
|
||||
"#
|
||||
));
|
||||
|
||||
let cal_february_json = r#"[{"year":2020,"month":"february","sunday":null,"monday":null,"tuesday":null,"wednesday":null,"thursday":null,"friday":null,"saturday":1},{"year":2020,"month":"february","sunday":2,"monday":3,"tuesday":4,"wednesday":5,"thursday":6,"friday":7,"saturday":8},{"year":2020,"month":"february","sunday":9,"monday":10,"tuesday":11,"wednesday":12,"thursday":13,"friday":14,"saturday":15},{"year":2020,"month":"february","sunday":16,"monday":17,"tuesday":18,"wednesday":19,"thursday":20,"friday":21,"saturday":22},{"year":2020,"month":"february","sunday":23,"monday":24,"tuesday":25,"wednesday":26,"thursday":27,"friday":28,"saturday":29}]"#;
|
||||
|
||||
assert_eq!(actual.out, cal_february_json);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cal_friday_the_thirteenths_in_2015() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
cal --full-year 2015 | default friday 0 | where friday == 13 | count
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains('3'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cal_rows_in_2020() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
cal --full-year 2020 | count
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("62"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cal_week_day_start_monday() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
cal --full-year 2020 -m --month-names --week-start monday | where month == january | to json
|
||||
"#
|
||||
));
|
||||
|
||||
let cal_january_json = r#"[{"month":"january","monday":null,"tuesday":null,"wednesday":1,"thursday":2,"friday":3,"saturday":4,"sunday":5},{"month":"january","monday":6,"tuesday":7,"wednesday":8,"thursday":9,"friday":10,"saturday":11,"sunday":12},{"month":"january","monday":13,"tuesday":14,"wednesday":15,"thursday":16,"friday":17,"saturday":18,"sunday":19},{"month":"january","monday":20,"tuesday":21,"wednesday":22,"thursday":23,"friday":24,"saturday":25,"sunday":26},{"month":"january","monday":27,"tuesday":28,"wednesday":29,"thursday":30,"friday":31,"saturday":null,"sunday":null}]"#;
|
||||
|
||||
assert_eq!(actual.out, cal_january_json);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cal_sees_pipeline_year() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
cal --full-year 1020 | get monday | first 3 | to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[3,10,17]");
|
||||
}
|
@ -1,459 +0,0 @@
|
||||
use nu_test_support::fs::{Stub::EmptyFile, Stub::FileWithContent};
|
||||
use nu_test_support::nu;
|
||||
use nu_test_support::playground::Playground;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[test]
|
||||
fn filesystem_change_from_current_directory_using_relative_path() {
|
||||
Playground::setup("cd_test_1", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.root(),
|
||||
r#"
|
||||
cd cd_test_1
|
||||
echo $(pwd)
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(PathBuf::from(actual.out), *dirs.test());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filesystem_change_from_current_directory_using_absolute_path() {
|
||||
Playground::setup("cd_test_2", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
cd "{}"
|
||||
echo $(pwd)
|
||||
"#,
|
||||
dirs.formats()
|
||||
);
|
||||
|
||||
assert_eq!(PathBuf::from(actual.out), dirs.formats());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filesystem_switch_back_to_previous_working_directory() {
|
||||
Playground::setup("cd_test_3", |dirs, sandbox| {
|
||||
sandbox.mkdir("odin");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test().join("odin"),
|
||||
r#"
|
||||
cd {}
|
||||
cd -
|
||||
echo $(pwd)
|
||||
"#,
|
||||
dirs.test()
|
||||
);
|
||||
|
||||
assert_eq!(PathBuf::from(actual.out), dirs.test().join("odin"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filesytem_change_from_current_directory_using_relative_path_and_dash() {
|
||||
Playground::setup("cd_test_4", |dirs, sandbox| {
|
||||
sandbox.within("odin").mkdir("-");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
cd odin/-
|
||||
echo $(pwd)
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
PathBuf::from(actual.out),
|
||||
dirs.test().join("odin").join("-")
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filesystem_change_current_directory_to_parent_directory() {
|
||||
Playground::setup("cd_test_5", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
cd ..
|
||||
echo $(pwd)
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(PathBuf::from(actual.out), *dirs.root());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filesystem_change_current_directory_to_two_parents_up_using_multiple_dots() {
|
||||
Playground::setup("cd_test_6", |dirs, sandbox| {
|
||||
sandbox.within("foo").mkdir("bar");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test().join("foo/bar"),
|
||||
r#"
|
||||
cd ...
|
||||
echo $(pwd)
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(PathBuf::from(actual.out), *dirs.test());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filesystem_change_current_directory_to_parent_directory_after_delete_cwd() {
|
||||
Playground::setup("cd_test_7", |dirs, sandbox| {
|
||||
sandbox.within("foo").mkdir("bar");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test().join("foo/bar"),
|
||||
r#"
|
||||
rm {}/foo/bar
|
||||
echo ","
|
||||
cd ..
|
||||
echo $(pwd)
|
||||
"#,
|
||||
dirs.test()
|
||||
);
|
||||
|
||||
let actual = actual.out.split(',').nth(1).unwrap();
|
||||
|
||||
assert_eq!(PathBuf::from(actual), *dirs.test().join("foo"));
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "dirs")]
|
||||
#[test]
|
||||
fn filesystem_change_to_home_directory() {
|
||||
Playground::setup("cd_test_8", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
cd ~
|
||||
echo $(pwd)
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(Some(PathBuf::from(actual.out)), dirs::home_dir());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filesystem_change_to_a_directory_containing_spaces() {
|
||||
Playground::setup("cd_test_9", |dirs, sandbox| {
|
||||
sandbox.mkdir("robalino turner katz");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
cd "robalino turner katz"
|
||||
echo $(pwd)
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
PathBuf::from(actual.out),
|
||||
dirs.test().join("robalino turner katz")
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filesystem_not_a_directory() {
|
||||
Playground::setup("cd_test_10", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("ferris_did_it.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"cd ferris_did_it.txt"
|
||||
);
|
||||
|
||||
assert!(
|
||||
actual.err.contains("ferris_did_it.txt"),
|
||||
"actual={:?}",
|
||||
actual.err
|
||||
);
|
||||
assert!(
|
||||
actual.err.contains("is not a directory"),
|
||||
"actual={:?}",
|
||||
actual.err
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filesystem_directory_not_found() {
|
||||
Playground::setup("cd_test_11", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"cd dir_that_does_not_exist"
|
||||
|
||||
);
|
||||
|
||||
assert!(
|
||||
actual.err.contains("dir_that_does_not_exist"),
|
||||
"actual={:?}",
|
||||
actual.err
|
||||
);
|
||||
assert!(
|
||||
actual.err.contains("directory not found"),
|
||||
"actual={:?}",
|
||||
actual.err
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filesystem_change_directory_to_symlink_relative() {
|
||||
Playground::setup("cd_test_12", |dirs, sandbox| {
|
||||
sandbox.mkdir("foo");
|
||||
sandbox.mkdir("boo");
|
||||
sandbox.symlink("foo", "foo_link");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test().join("boo"),
|
||||
r#"
|
||||
cd ../foo_link
|
||||
echo $(pwd)
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(PathBuf::from(actual.out), dirs.test().join("foo"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valuesystem_change_from_current_path_using_relative_path() {
|
||||
Playground::setup("cd_test_13", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[[bin]]
|
||||
path = "src/plugins/turner.rs"
|
||||
|
||||
[[bin]]
|
||||
path = "src/plugins/robalino.rs"
|
||||
|
||||
[[bin]]
|
||||
path = "src/plugins/katz.rs"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
enter sample.toml
|
||||
cd bin
|
||||
pwd
|
||||
exit
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(PathBuf::from(actual.out), PathBuf::from("/bin"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valuesystem_change_from_current_path_using_absolute_path() {
|
||||
Playground::setup("cd_test_14", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[dependencies]
|
||||
turner-ts = "0.1.1"
|
||||
robalino-tkd = "0.0.1"
|
||||
katz-ember = "0.2.3"
|
||||
|
||||
[[bin]]
|
||||
path = "src/plugins/arepa.rs"
|
||||
|
||||
[[bin]]
|
||||
path = "src/plugins/bbq.rs"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
enter sample.toml
|
||||
cd bin
|
||||
cd /dependencies
|
||||
pwd
|
||||
exit
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(PathBuf::from(actual.out), PathBuf::from("/dependencies"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valuesystem_switch_back_to_previous_working_path() {
|
||||
Playground::setup("cd_test_15", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[dependencies]
|
||||
turner-ts = "0.1.1"
|
||||
robalino-tkd = "0.0.1"
|
||||
katz-ember = "0.2.3"
|
||||
odin-gf = "0.2.1"
|
||||
|
||||
[[bin]]
|
||||
path = "src/plugins/arepa.rs"
|
||||
|
||||
[[bin]]
|
||||
path = "src/plugins/bbq.rs"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
enter sample.toml
|
||||
cd dependencies
|
||||
cd /bin
|
||||
cd -
|
||||
pwd
|
||||
exit
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(PathBuf::from(actual.out), PathBuf::from("/dependencies"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valuesystem_change_from_current_path_using_relative_path_and_dash() {
|
||||
Playground::setup("cd_test_16", |dirs, sandbox| {
|
||||
sandbox
|
||||
.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
- = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
|
||||
|
||||
[[bin]]
|
||||
path = "src/plugins/arepa.rs"
|
||||
|
||||
[[bin]]
|
||||
path = "src/plugins/bbq.rs"
|
||||
"#
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
enter sample.toml
|
||||
cd package/-
|
||||
cd /bin
|
||||
cd -
|
||||
pwd
|
||||
exit
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(PathBuf::from(actual.out), PathBuf::from("/package/-"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valuesystem_change_current_path_to_parent_path() {
|
||||
Playground::setup("cd_test_17", |dirs, sandbox| {
|
||||
sandbox
|
||||
.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
emberenios = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
|
||||
"#
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
enter sample.toml
|
||||
cd package/emberenios
|
||||
cd ..
|
||||
pwd
|
||||
exit
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(PathBuf::from(actual.out), PathBuf::from("/package"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valuesystem_change_to_a_path_containing_spaces() {
|
||||
Playground::setup("cd_test_18", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
["pa que te"]
|
||||
el = "pollo loco"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
enter sample.toml
|
||||
cd "pa que te"
|
||||
pwd
|
||||
exit
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
PathBuf::from(actual.out),
|
||||
PathBuf::from("/").join("pa que te")
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valuesystem_path_not_found() {
|
||||
Playground::setup("cd_test_19", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.formats(),
|
||||
r#"
|
||||
enter cargo_sample.toml
|
||||
cd im_a_path_that_does_not_exist
|
||||
exit
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("Can not change to path inside"));
|
||||
assert!(actual.err.contains("No such path exists"));
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
#[test]
|
||||
fn test_change_windows_drive() {
|
||||
Playground::setup("cd_test_20", |dirs, sandbox| {
|
||||
sandbox.mkdir("test_folder");
|
||||
|
||||
let _actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
subst Z: test_folder
|
||||
Z:
|
||||
echo "some text" | save test_file.txt
|
||||
cd ~
|
||||
subst Z: /d
|
||||
"#
|
||||
);
|
||||
assert!(dirs
|
||||
.test()
|
||||
.join("test_folder")
|
||||
.join("test_file.txt")
|
||||
.exists());
|
||||
})
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
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#"
|
||||
{
|
||||
"amigos": [
|
||||
{"name": "Yehuda", "rusty_luck": 1},
|
||||
{"name": "Jonathan", "rusty_luck": 1},
|
||||
{"name": "Andres", "rusty_luck": 1},
|
||||
{"name":"GorbyPuff"}
|
||||
]
|
||||
}
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_amigos.json
|
||||
| get amigos
|
||||
| compact rusty_luck
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
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#"
|
||||
echo "[1,2,3,14,null]"
|
||||
| from json
|
||||
| compact
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
});
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn count_columns_in_cal_table() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
cal | count -c
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "7");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn count_columns_no_rows() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [] | count -c
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "0");
|
||||
}
|
@ -1,237 +0,0 @@
|
||||
use nu_test_support::fs::{files_exist_at, AbsoluteFile, Stub::EmptyFile};
|
||||
use nu_test_support::nu;
|
||||
use nu_test_support::playground::Playground;
|
||||
use std::path::Path;
|
||||
|
||||
#[test]
|
||||
fn copies_a_file() {
|
||||
Playground::setup("cp_test_1", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.root(),
|
||||
"cp \"{}\" cp_test_1/sample.ini",
|
||||
dirs.formats().join("sample.ini")
|
||||
);
|
||||
|
||||
assert!(dirs.test().join("sample.ini").exists());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copies_the_file_inside_directory_if_path_to_copy_is_directory() {
|
||||
Playground::setup("cp_test_2", |dirs, _| {
|
||||
let expected_file = AbsoluteFile::new(dirs.test().join("sample.ini"));
|
||||
|
||||
nu!(
|
||||
cwd: dirs.formats(),
|
||||
"cp ../formats/sample.ini {}",
|
||||
expected_file.dir()
|
||||
);
|
||||
|
||||
assert!(dirs.test().join("sample.ini").exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_if_attempting_to_copy_a_directory_to_another_directory() {
|
||||
Playground::setup("cp_test_3", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.formats(),
|
||||
"cp ../formats {}", dirs.test()
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("../formats"));
|
||||
assert!(actual.err.contains("resolves to a directory (not copied)"));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copies_the_directory_inside_directory_if_path_to_copy_is_directory_and_with_recursive_flag() {
|
||||
Playground::setup("cp_test_4", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("originals")
|
||||
.with_files(vec![
|
||||
EmptyFile("yehuda.txt"),
|
||||
EmptyFile("jonathan.txt"),
|
||||
EmptyFile("andres.txt"),
|
||||
])
|
||||
.mkdir("expected");
|
||||
|
||||
let expected_dir = dirs.test().join("expected").join("originals");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"cp originals expected -r"
|
||||
);
|
||||
|
||||
assert!(expected_dir.exists());
|
||||
assert!(files_exist_at(
|
||||
vec![
|
||||
Path::new("yehuda.txt"),
|
||||
Path::new("jonathan.txt"),
|
||||
Path::new("andres.txt")
|
||||
],
|
||||
expected_dir
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deep_copies_with_recursive_flag() {
|
||||
Playground::setup("cp_test_5", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("originals")
|
||||
.with_files(vec![EmptyFile("manifest.txt")])
|
||||
.within("originals/contributors")
|
||||
.with_files(vec![
|
||||
EmptyFile("yehuda.txt"),
|
||||
EmptyFile("jonathan.txt"),
|
||||
EmptyFile("andres.txt"),
|
||||
])
|
||||
.within("originals/contributors/jonathan")
|
||||
.with_files(vec![EmptyFile("errors.txt"), EmptyFile("multishells.txt")])
|
||||
.within("originals/contributors/andres")
|
||||
.with_files(vec![EmptyFile("coverage.txt"), EmptyFile("commands.txt")])
|
||||
.within("originals/contributors/yehuda")
|
||||
.with_files(vec![EmptyFile("defer-evaluation.txt")])
|
||||
.mkdir("expected");
|
||||
|
||||
let expected_dir = dirs.test().join("expected").join("originals");
|
||||
|
||||
let jonathans_expected_copied_dir = expected_dir.join("contributors").join("jonathan");
|
||||
let andres_expected_copied_dir = expected_dir.join("contributors").join("andres");
|
||||
let yehudas_expected_copied_dir = expected_dir.join("contributors").join("yehuda");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"cp originals expected --recursive"
|
||||
);
|
||||
|
||||
assert!(expected_dir.exists());
|
||||
assert!(files_exist_at(
|
||||
vec![Path::new("errors.txt"), Path::new("multishells.txt")],
|
||||
jonathans_expected_copied_dir
|
||||
));
|
||||
assert!(files_exist_at(
|
||||
vec![Path::new("coverage.txt"), Path::new("commands.txt")],
|
||||
andres_expected_copied_dir
|
||||
));
|
||||
assert!(files_exist_at(
|
||||
vec![Path::new("defer-evaluation.txt")],
|
||||
yehudas_expected_copied_dir
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copies_using_path_with_wildcard() {
|
||||
Playground::setup("cp_test_6", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.formats(),
|
||||
"cp ../formats/* {}", dirs.test()
|
||||
);
|
||||
|
||||
assert!(files_exist_at(
|
||||
vec![
|
||||
Path::new("caco3_plastics.csv"),
|
||||
Path::new("cargo_sample.toml"),
|
||||
Path::new("jonathan.xml"),
|
||||
Path::new("sample.ini"),
|
||||
Path::new("sgml_description.json"),
|
||||
Path::new("utf16.ini"),
|
||||
],
|
||||
dirs.test()
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copies_using_a_glob() {
|
||||
Playground::setup("cp_test_7", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.formats(),
|
||||
"cp * {}", dirs.test()
|
||||
);
|
||||
|
||||
assert!(files_exist_at(
|
||||
vec![
|
||||
Path::new("caco3_plastics.csv"),
|
||||
Path::new("cargo_sample.toml"),
|
||||
Path::new("jonathan.xml"),
|
||||
Path::new("sample.ini"),
|
||||
Path::new("sgml_description.json"),
|
||||
Path::new("utf16.ini"),
|
||||
],
|
||||
dirs.test()
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copies_same_file_twice() {
|
||||
Playground::setup("cp_test_8", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.root(),
|
||||
"cp \"{}\" cp_test_8/sample.ini",
|
||||
dirs.formats().join("sample.ini")
|
||||
);
|
||||
|
||||
nu!(
|
||||
cwd: dirs.root(),
|
||||
"cp \"{}\" cp_test_8/sample.ini",
|
||||
dirs.formats().join("sample.ini")
|
||||
);
|
||||
|
||||
assert!(dirs.test().join("sample.ini").exists());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copy_files_using_glob_two_parents_up_using_multiple_dots() {
|
||||
Playground::setup("cp_test_9", |dirs, sandbox| {
|
||||
sandbox.within("foo").within("bar").with_files(vec![
|
||||
EmptyFile("jonathan.json"),
|
||||
EmptyFile("andres.xml"),
|
||||
EmptyFile("yehuda.yaml"),
|
||||
EmptyFile("kevin.txt"),
|
||||
EmptyFile("many_more.ppl"),
|
||||
]);
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test().join("foo/bar"),
|
||||
r#"
|
||||
cp * ...
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(files_exist_at(
|
||||
vec![
|
||||
"yehuda.yaml",
|
||||
"jonathan.json",
|
||||
"andres.xml",
|
||||
"kevin.txt",
|
||||
"many_more.ppl",
|
||||
],
|
||||
dirs.test()
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copy_file_and_dir_from_two_parents_up_using_multiple_dots_to_current_dir_recursive() {
|
||||
Playground::setup("cp_test_10", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("hello_there")]);
|
||||
sandbox.mkdir("hello_again");
|
||||
sandbox.within("foo").mkdir("bar");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test().join("foo/bar"),
|
||||
r#"
|
||||
cp -r .../hello* .
|
||||
"#
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("foo/bar");
|
||||
|
||||
assert!(files_exist_at(vec!["hello_there", "hello_again"], expected));
|
||||
})
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
use nu_test_support::nu;
|
||||
use nu_test_support::playground::Playground;
|
||||
use std::fs;
|
||||
#[test]
|
||||
fn def_with_comment() {
|
||||
Playground::setup("def_with_comment", |dirs, _| {
|
||||
let data = r#"
|
||||
#My echo
|
||||
def e [arg] {echo $arg}
|
||||
"#;
|
||||
fs::write(dirs.root().join("def_test"), data).expect("Unable to write file");
|
||||
let actual = nu!(
|
||||
cwd: dirs.root(),
|
||||
"source def_test; help e | to json"
|
||||
);
|
||||
|
||||
assert!(actual.out.contains("My echo\\n\\n"));
|
||||
});
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn adds_row_data_if_column_missing() {
|
||||
Playground::setup("default_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_amigos.json",
|
||||
r#"
|
||||
{
|
||||
"amigos": [
|
||||
{"name": "Yehuda"},
|
||||
{"name": "Jonathan", "rusty_luck": 0},
|
||||
{"name": "Andres", "rusty_luck": 0},
|
||||
{"name":"GorbyPuff"}
|
||||
]
|
||||
}
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_amigos.json
|
||||
| get amigos
|
||||
| default rusty_luck 1
|
||||
| where rusty_luck == 1
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
});
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn drop_rows() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
r#"echo '[{"foo": 3}, {"foo": 8}, {"foo": 4}]' | from json | drop 2 | get foo | math sum "#
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drop_more_rows_than_table_has() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
date | drop 50 | count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "0");
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn each_works_separately() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [1 2 3] | each { echo $it 10 | math sum } | to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[11,12,13]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_group_works() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [1 2 3 4 5 6] | each group 3 { echo $it } | to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[[1,2,3],[4,5,6]]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_window() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [1 2 3 4] | each window 3 { echo $it } | to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[[1,2,3],[2,3,4]]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_window_stride() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [1 2 3 4 5 6] | each window 3 -s 2 { echo $it } | to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[[1,2,3],[3,4,5]]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_no_args_in_block() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [[foo bar]; [a b] [c d] [e f]] | each { to json } | nth 1 | str collect
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, r#"{"foo":"c","bar":"d"}"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_implicit_it_in_block() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [[foo bar]; [a b] [c d] [e f]] | each { nu --testbin cococo $it.foo }
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "ace");
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn echo_range_is_lazy() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo 1..10000000000 | first 3 | to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[1,2,3]");
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn reports_emptiness() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [[are_empty];
|
||||
[$(= [[check]; [[]] ])]
|
||||
[$(= [[check]; [""] ])]
|
||||
[$(= [[check]; [$(wrap)] ])]
|
||||
]
|
||||
| get are_empty
|
||||
| empty? check
|
||||
| where check
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sets_block_run_value_for_an_empty_column() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [
|
||||
[ first_name, last_name, rusty_at, likes ];
|
||||
[ Andrés, Robalino, 10/11/2013, 1 ]
|
||||
[ Jonathan, Turner, 10/12/2013, 1 ]
|
||||
[ Jason, Gedge, 10/11/2013, 1 ]
|
||||
[ Yehuda, Katz, 10/11/2013, '' ]
|
||||
]
|
||||
| empty? likes { = 1 }
|
||||
| get likes
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sets_block_run_value_for_many_empty_columns() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [
|
||||
[ boost check ];
|
||||
[ 1, [] ]
|
||||
[ 1, "" ]
|
||||
[ 1, $(wrap) ]
|
||||
]
|
||||
| empty? boost check { = 1 }
|
||||
| get boost check
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "6");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn passing_a_block_will_set_contents_on_empty_cells_and_leave_non_empty_ones_untouched() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [
|
||||
[ NAME, LVL, HP ];
|
||||
[ Andrés, 30, 3000 ]
|
||||
[ Alistair, 29, 2900 ]
|
||||
[ Arepas, "", "" ]
|
||||
[ Jorge, 30, 3000 ]
|
||||
]
|
||||
| empty? LVL { = 9 }
|
||||
| empty? HP {
|
||||
= $it.LVL * 1000
|
||||
}
|
||||
| math sum
|
||||
| get HP
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "17900");
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
use nu_test_support::fs::{files_exist_at, Stub::EmptyFile};
|
||||
use nu_test_support::nu;
|
||||
use nu_test_support::playground::Playground;
|
||||
use std::path::Path;
|
||||
|
||||
#[test]
|
||||
fn knows_the_filesystems_entered() {
|
||||
Playground::setup("enter_test_1", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("red_pill")
|
||||
.with_files(vec![
|
||||
EmptyFile("andres.nu"),
|
||||
EmptyFile("jonathan.nu"),
|
||||
EmptyFile("yehuda.nu"),
|
||||
])
|
||||
.within("blue_pill")
|
||||
.with_files(vec![
|
||||
EmptyFile("bash.nxt"),
|
||||
EmptyFile("korn.nxt"),
|
||||
EmptyFile("powedsh.nxt"),
|
||||
])
|
||||
.mkdir("expected");
|
||||
|
||||
let red_pill_dir = dirs.test().join("red_pill");
|
||||
let blue_pill_dir = dirs.test().join("blue_pill");
|
||||
let expected = dirs.test().join("expected");
|
||||
let expected_recycled = expected.join("recycled");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
enter expected
|
||||
mkdir recycled
|
||||
enter ../red_pill
|
||||
mv jonathan.nu ../expected
|
||||
enter ../blue_pill
|
||||
cp *.nxt ../expected/recycled
|
||||
p
|
||||
p
|
||||
mv ../red_pill/yehuda.nu .
|
||||
n
|
||||
mv andres.nu ../expected/andres.nu
|
||||
exit
|
||||
cd ..
|
||||
rm red_pill --recursive
|
||||
exit
|
||||
n
|
||||
rm blue_pill --recursive
|
||||
exit
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(!red_pill_dir.exists());
|
||||
assert!(files_exist_at(
|
||||
vec![
|
||||
Path::new("andres.nu"),
|
||||
Path::new("jonathan.nu"),
|
||||
Path::new("yehuda.nu"),
|
||||
],
|
||||
expected
|
||||
));
|
||||
|
||||
assert!(!blue_pill_dir.exists());
|
||||
assert!(files_exist_at(
|
||||
vec![
|
||||
Path::new("bash.nxt"),
|
||||
Path::new("korn.nxt"),
|
||||
Path::new("powedsh.nxt"),
|
||||
],
|
||||
expected_recycled
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_file_not_found() {
|
||||
Playground::setup("enter_test_2", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"enter i_dont_exist.csv"
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("Cannot find file"));
|
||||
})
|
||||
}
|
@ -1,209 +0,0 @@
|
||||
use nu_test_support::fs::Stub::EmptyFile;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn gets_all_rows_by_every_zero() {
|
||||
Playground::setup("every_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("amigos.txt"),
|
||||
EmptyFile("arepas.clu"),
|
||||
EmptyFile("los.txt"),
|
||||
EmptyFile("tres.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| get name
|
||||
| every 0
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
r#"["amigos.txt","arepas.clu","los.txt","tres.txt"]"#
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gets_no_rows_by_every_skip_zero() {
|
||||
Playground::setup("every_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("amigos.txt"),
|
||||
EmptyFile("arepas.clu"),
|
||||
EmptyFile("los.txt"),
|
||||
EmptyFile("tres.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| get name
|
||||
| every 0 --skip
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gets_all_rows_by_every_one() {
|
||||
Playground::setup("every_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("amigos.txt"),
|
||||
EmptyFile("arepas.clu"),
|
||||
EmptyFile("los.txt"),
|
||||
EmptyFile("tres.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| get name
|
||||
| every 1
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
r#"["amigos.txt","arepas.clu","los.txt","tres.txt"]"#
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gets_no_rows_by_every_skip_one() {
|
||||
Playground::setup("every_test_4", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("amigos.txt"),
|
||||
EmptyFile("arepas.clu"),
|
||||
EmptyFile("los.txt"),
|
||||
EmptyFile("tres.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| get name
|
||||
| every 1 --skip
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gets_first_row_by_every_too_much() {
|
||||
Playground::setup("every_test_5", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("amigos.txt"),
|
||||
EmptyFile("arepas.clu"),
|
||||
EmptyFile("los.txt"),
|
||||
EmptyFile("tres.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| get name
|
||||
| every 999
|
||||
"#
|
||||
));
|
||||
|
||||
let expected = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
echo [ amigos.txt ]
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, expected.out);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gets_all_rows_except_first_by_every_skip_too_much() {
|
||||
Playground::setup("every_test_6", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("amigos.txt"),
|
||||
EmptyFile("arepas.clu"),
|
||||
EmptyFile("los.txt"),
|
||||
EmptyFile("tres.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| get name
|
||||
| every 999 --skip
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, r#"["arepas.clu","los.txt","tres.txt"]"#);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gets_every_third_row() {
|
||||
Playground::setup("every_test_7", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("amigos.txt"),
|
||||
EmptyFile("arepas.clu"),
|
||||
EmptyFile("los.txt"),
|
||||
EmptyFile("quatro.txt"),
|
||||
EmptyFile("tres.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| get name
|
||||
| every 3
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, r#"["amigos.txt","quatro.txt"]"#);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn skips_every_third_row() {
|
||||
Playground::setup("every_test_8", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("amigos.txt"),
|
||||
EmptyFile("arepas.clu"),
|
||||
EmptyFile("los.txt"),
|
||||
EmptyFile("quatro.txt"),
|
||||
EmptyFile("tres.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| get name
|
||||
| every 3 --skip
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, r#"["arepas.clu","los.txt","tres.txt"]"#);
|
||||
})
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
use nu_test_support::fs::Stub::EmptyFile;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn gets_first_rows_by_amount() {
|
||||
Playground::setup("first_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("los.txt"),
|
||||
EmptyFile("tres.txt"),
|
||||
EmptyFile("amigos.txt"),
|
||||
EmptyFile("arepas.clu"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| first 3
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gets_all_rows_if_amount_higher_than_all_rows() {
|
||||
Playground::setup("first_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("los.txt"),
|
||||
EmptyFile("tres.txt"),
|
||||
EmptyFile("amigos.txt"),
|
||||
EmptyFile("arepas.clu"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| first 99
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gets_first_row_when_no_amount_given() {
|
||||
Playground::setup("first_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("caballeros.txt"), EmptyFile("arepas.clu")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| first
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
})
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn flatten_nested_tables_with_columns() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [[origin, people]; [Ecuador, $(= 'Andres' | wrap name)]]
|
||||
[[origin, people]; [Nu, $(= 'nuno' | wrap name)]]
|
||||
| flatten
|
||||
| get name
|
||||
| str collect ','
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "Andres,nuno");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flatten_nested_tables_that_have_many_columns() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [[origin, people]; [Ecuador, $(echo [[name, meal]; ['Andres', 'arepa']])]]
|
||||
[[origin, people]; [USA, $(echo [[name, meal]; ['Katz', 'nurepa']])]]
|
||||
| flatten
|
||||
| get meal
|
||||
| str collect ','
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "arepa,nurepa");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flatten_nested_tables() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [[Andrés, Nicolás, Robalino]] | flatten | nth 1
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "Nicolás");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flatten_row_column_explicitly() {
|
||||
Playground::setup("flatten_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"katz.json",
|
||||
r#"
|
||||
[
|
||||
{
|
||||
"people": {
|
||||
"name": "Andres",
|
||||
"meal": "arepa"
|
||||
}
|
||||
},
|
||||
{
|
||||
"people": {
|
||||
"name": "Katz",
|
||||
"meal": "nurepa"
|
||||
}
|
||||
}
|
||||
]
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open katz.json | flatten people | where name == Andres | count"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flatten_row_columns_having_same_column_names_flats_separately() {
|
||||
Playground::setup("flatten_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"katz.json",
|
||||
r#"
|
||||
[
|
||||
{
|
||||
"people": {
|
||||
"name": "Andres",
|
||||
"meal": "arepa"
|
||||
},
|
||||
"city": [{"name": "Guayaquil"}, {"name": "Samborondón"}]
|
||||
},
|
||||
{
|
||||
"people": {
|
||||
"name": "Katz",
|
||||
"meal": "nurepa"
|
||||
},
|
||||
"city": [{"name": "Oregon"}, {"name": "Brooklin"}]
|
||||
}
|
||||
]
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open katz.json | flatten | flatten people city | get city_name | count"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flatten_table_columns_explicitly() {
|
||||
Playground::setup("flatten_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"katz.json",
|
||||
r#"
|
||||
[
|
||||
{
|
||||
"people": {
|
||||
"name": "Andres",
|
||||
"meal": "arepa"
|
||||
},
|
||||
"city": ["Guayaquil", "Samborondón"]
|
||||
},
|
||||
{
|
||||
"people": {
|
||||
"name": "Katz",
|
||||
"meal": "nurepa"
|
||||
},
|
||||
"city": ["Oregon", "Brooklin"]
|
||||
}
|
||||
]
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open katz.json | flatten city | where people.name == Katz | count"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flatten_more_than_one_column_that_are_subtables_not_supported() {
|
||||
Playground::setup("flatten_test_4", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"katz.json",
|
||||
r#"
|
||||
[
|
||||
{
|
||||
"people": {
|
||||
"name": "Andres",
|
||||
"meal": "arepa"
|
||||
}
|
||||
"tags": ["carbohydrate", "corn", "maiz"],
|
||||
"city": ["Guayaquil", "Samborondón"]
|
||||
},
|
||||
{
|
||||
"people": {
|
||||
"name": "Katz",
|
||||
"meal": "nurepa"
|
||||
},
|
||||
"tags": ["carbohydrate", "shell food", "amigos flavor"],
|
||||
"city": ["Oregon", "Brooklin"]
|
||||
}
|
||||
]
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open katz.json | flatten tags city"
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("tried flattening"));
|
||||
assert!(actual.err.contains("but is flattened already"));
|
||||
})
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
use nu_test_support::fs::Stub::EmptyFile;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn creates_the_resulting_string_from_the_given_fields() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml
|
||||
| get package
|
||||
| format "{name} has license {license}"
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "nu has license ISC");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn given_fields_can_be_column_paths() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml
|
||||
| format "{package.name} is {package.description}"
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "nu is a new type of shell");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_use_variables() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml
|
||||
| format "{$it.package.name} is {$it.package.description}"
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "nu is a new type of shell");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_filesize_works() {
|
||||
Playground::setup("format_filesize_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("yehuda.txt"),
|
||||
EmptyFile("jonathan.txt"),
|
||||
EmptyFile("andres.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| format filesize size KB
|
||||
| get size
|
||||
| first
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "0.01 KB");
|
||||
})
|
||||
}
|
@ -1,252 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContent;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn fetches_a_row() {
|
||||
Playground::setup("get_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
nu_party_venue = "zion"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| get nu_party_venue
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "zion");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fetches_by_index() {
|
||||
Playground::setup("get_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "nu"
|
||||
version = "0.4.1"
|
||||
authors = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
|
||||
description = "When arepas shells are tasty and fun."
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| get package.authors.2
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "Andrés N. Robalino <andres@androbtech.com>");
|
||||
})
|
||||
}
|
||||
#[test]
|
||||
fn fetches_by_column_path() {
|
||||
Playground::setup("get_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "nu"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| get package.name
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "nu");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn column_paths_are_either_double_quoted_or_regular_unquoted_words_separated_by_dot() {
|
||||
Playground::setup("get_test_4", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
9999 = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
|
||||
description = "When arepas shells are tasty and fun."
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| get package."9999"
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fetches_more_than_one_column_path() {
|
||||
Playground::setup("get_test_5", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[[fortune_tellers]]
|
||||
name = "Andrés N. Robalino"
|
||||
arepas = 1
|
||||
|
||||
[[fortune_tellers]]
|
||||
name = "Jonathan Turner"
|
||||
arepas = 1
|
||||
|
||||
[[fortune_tellers]]
|
||||
name = "Yehuda Katz"
|
||||
arepas = 1
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| get fortune_tellers.2.name fortune_tellers.0.name fortune_tellers.1.name
|
||||
| nth 2
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "Jonathan Turner");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_fetching_by_column_not_present() {
|
||||
Playground::setup("get_test_6", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[taconushell]
|
||||
sentence_words = ["Yo", "quiero", "taconushell"]
|
||||
[pizzanushell]
|
||||
sentence-words = ["I", "want", "pizza"]
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| get taco
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(
|
||||
actual.err.contains("Unknown column"),
|
||||
format!("actual: {:?}", actual.err)
|
||||
);
|
||||
assert!(
|
||||
actual.err.contains("There isn't a column named 'taco'"),
|
||||
format!("actual: {:?}", actual.err)
|
||||
);
|
||||
assert!(
|
||||
actual.err.contains("Perhaps you meant 'taconushell'?"),
|
||||
format!("actual: {:?}", actual.err)
|
||||
);
|
||||
assert!(
|
||||
actual
|
||||
.err
|
||||
.contains("Columns available: pizzanushell, taconushell"),
|
||||
format!("actual: {:?}", actual.err)
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_fetching_by_column_using_a_number() {
|
||||
Playground::setup("get_test_7", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[spanish_lesson]
|
||||
0 = "can only be fetched with 0 double quoted."
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| get spanish_lesson.0
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(
|
||||
actual.err.contains("No rows available"),
|
||||
format!("actual: {:?}", actual.err)
|
||||
);
|
||||
assert!(
|
||||
actual.err.contains("A row at '0' can't be indexed."),
|
||||
format!("actual: {:?}", actual.err)
|
||||
);
|
||||
assert!(
|
||||
actual
|
||||
.err
|
||||
.contains("Appears to contain columns. Columns available: 0"),
|
||||
format!("actual: {:?}", actual.err)
|
||||
)
|
||||
})
|
||||
}
|
||||
#[test]
|
||||
fn errors_fetching_by_index_out_of_bounds() {
|
||||
Playground::setup("get_test_8", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[spanish_lesson]
|
||||
sentence_words = ["Yo", "quiero", "taconushell"]
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| get spanish_lesson.sentence_words.3
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(
|
||||
actual.err.contains("Row not found"),
|
||||
format!("actual: {:?}", actual.err)
|
||||
);
|
||||
assert!(
|
||||
actual.err.contains("There isn't a row indexed at 3"),
|
||||
format!("actual: {:?}", actual.err)
|
||||
);
|
||||
assert!(
|
||||
actual.err.contains("The table only has 3 rows (0 to 2)"),
|
||||
format!("actual: {:?}", actual.err)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quoted_column_access() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
r#"echo '[{"foo bar": {"baz": 4}}]' | from json | get "foo bar".baz "#
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn groups() {
|
||||
Playground::setup("group_by_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at,type
|
||||
Andrés,Robalino,10/11/2013,A
|
||||
Jonathan,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
| group-by rusty_at
|
||||
| get "10/11/2013"
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_given_unknown_column_name() {
|
||||
Playground::setup("group_by_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.json",
|
||||
r#"
|
||||
{
|
||||
"nu": {
|
||||
"committers": [
|
||||
{"name": "Andrés N. Robalino"},
|
||||
{"name": "Jonathan Turner"},
|
||||
{"name": "Yehuda Katz"}
|
||||
],
|
||||
"releases": [
|
||||
{"version": "0.2"}
|
||||
{"version": "0.8"},
|
||||
{"version": "0.9999999"}
|
||||
],
|
||||
"0xATYKARNU": [
|
||||
["Th", "e", " "],
|
||||
["BIG", " ", "UnO"],
|
||||
["punto", "cero"]
|
||||
]
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.json
|
||||
| group-by { get nu.releases.version }
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("requires a table with one value for grouping"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_block_given_evaluates_more_than_one_row() {
|
||||
Playground::setup("group_by_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at,type
|
||||
Andrés,Robalino,10/11/2013,A
|
||||
Jonathan,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
| group-by ttype
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("Unknown column"));
|
||||
})
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn base64_defaults_to_encoding_with_standard_character_type() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo 'username:password' | hash base64
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "dXNlcm5hbWU6cGFzc3dvcmQ=");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn base64_encode_characterset_binhex() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo 'username:password' | hash base64 --character_set binhex --encode
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "F@0NEPjJD97kE\'&bEhFZEP3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_when_invalid_character_set_given() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo 'username:password' | hash base64 --character_set 'this is invalid' --encode
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("this is invalid is not a valid character-set"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn base64_decode_characterset_binhex() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "F@0NEPjJD97kE'&bEhFZEP3" | hash base64 --character_set binhex --decode
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "username:password");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_invalid_decode_value() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "this should not be a valid encoded value" | hash base64 --character_set url-safe --decode
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("invalid base64 input for character set url-safe"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_use_both_flags() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo 'username:password' | hash base64 --encode --decode
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("only one of --decode and --encode flags can be used"));
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn headers_uses_first_row_as_header() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample_headers.xlsx
|
||||
| get Sheet1
|
||||
| headers
|
||||
| get header0
|
||||
| from json"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "r1c0r2c0")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn headers_adds_missing_column_name() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample_headers.xlsx
|
||||
| get Sheet1
|
||||
| headers
|
||||
| get Column1
|
||||
| from json"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "r1c1r2c1")
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn summarizes_by_column_given() {
|
||||
Playground::setup("histogram_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at
|
||||
Andrés,Robalino,Ecuador
|
||||
Jonathan,Turner,Estados Unidos
|
||||
Yehuda,Katz,Estados Unidos
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
| histogram rusty_at countries
|
||||
| where rusty_at == "Ecuador"
|
||||
| get countries
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"**************************************************"
|
||||
);
|
||||
// 50%
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summarizes_by_values() {
|
||||
Playground::setup("histogram_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at
|
||||
Andrés,Robalino,Ecuador
|
||||
Jonathan,Turner,Estados Unidos
|
||||
Yehuda,Katz,Estados Unidos
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
| get rusty_at
|
||||
| histogram
|
||||
| where value == "Estados Unidos"
|
||||
| get count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help() {
|
||||
Playground::setup("histogram_test_3", |dirs, _sandbox| {
|
||||
let help_command = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
help histogram
|
||||
"#
|
||||
));
|
||||
|
||||
let help_short = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
histogram -h
|
||||
"#
|
||||
));
|
||||
|
||||
let help_long = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
histogram --help
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(help_short.out, help_command.out);
|
||||
assert_eq!(help_long.out, help_command.out);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn count() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [[bit]; [1] [0] [0] [0] [0] [0] [0] [1]]
|
||||
| histogram bit
|
||||
| sort-by count
|
||||
| reject frequency
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
let bit_json = r#"[{"bit":"1","count":2,"percentage":"33.33%"},{"bit":"0","count":6,"percentage":"100.00%"}]"#;
|
||||
|
||||
assert_eq!(actual.out, bit_json);
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn sets_the_column_from_a_block_run_output() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml
|
||||
| insert dev-dependencies.newdep "1"
|
||||
| get dev-dependencies.newdep
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sets_the_column_from_a_block_full_stream_output() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
wrap _
|
||||
| insert content { open --raw cargo_sample.toml | lines | first 5 }
|
||||
| get content.1
|
||||
| str contains "nu"
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sets_the_column_from_an_invocation() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
wrap content
|
||||
| insert content $(open --raw cargo_sample.toml | lines | first 5)
|
||||
| get content.1
|
||||
| str contains "nu"
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn into_int_filesize() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
into-int 1kb | each {= $it / 1024 }
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains('1'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_int_int() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
into-int 1024 | each {= $it / 1024 }
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains('1'));
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
mod rows;
|
||||
mod until;
|
||||
mod while_;
|
@ -1,31 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn rows() {
|
||||
Playground::setup("keep_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"caballeros.csv",
|
||||
r#"
|
||||
name,lucky_code
|
||||
Andrés,1
|
||||
Jonathan,1
|
||||
Jason,2
|
||||
Yehuda,1
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open caballeros.csv
|
||||
| keep 3
|
||||
| get lucky_code
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
})
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn condition_is_met() {
|
||||
Playground::setup("keep_until_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"caballeros.txt",
|
||||
r#"
|
||||
CHICKEN SUMMARY report date: April 29th, 2020
|
||||
--------------------------------------------------------------------
|
||||
Chicken Collection,29/04/2020,30/04/2020,31/04/2020,
|
||||
Yellow Chickens,,,
|
||||
Andrés,1,1,1
|
||||
Jonathan,1,1,1
|
||||
Jason,1,1,1
|
||||
Yehuda,1,1,1
|
||||
Blue Chickens,,,
|
||||
Andrés,1,1,2
|
||||
Jonathan,1,1,2
|
||||
Jason,1,1,2
|
||||
Yehuda,1,1,2
|
||||
Red Chickens,,,
|
||||
Andrés,1,1,3
|
||||
Jonathan,1,1,3
|
||||
Jason,1,1,3
|
||||
Yehuda,1,1,3
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open --raw caballeros.txt
|
||||
| lines
|
||||
| skip 2
|
||||
| split column ','
|
||||
| headers
|
||||
| skip while "Chicken Collection" != "Blue Chickens"
|
||||
| keep until "Chicken Collection" == "Red Chickens"
|
||||
| skip 1
|
||||
| str to-int "31/04/2020"
|
||||
| get "31/04/2020"
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "8");
|
||||
})
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn condition_is_met() {
|
||||
Playground::setup("keep_while_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"caballeros.txt",
|
||||
r#"
|
||||
CHICKEN SUMMARY report date: April 29th, 2020
|
||||
--------------------------------------------------------------------
|
||||
Chicken Collection,29/04/2020,30/04/2020,31/04/2020,
|
||||
Yellow Chickens,,,
|
||||
Andrés,1,1,1
|
||||
Jonathan,1,1,1
|
||||
Jason,1,1,1
|
||||
Yehuda,1,1,1
|
||||
Blue Chickens,,,
|
||||
Andrés,1,1,2
|
||||
Jonathan,1,1,2
|
||||
Jason,1,1,2
|
||||
Yehuda,1,1,2
|
||||
Red Chickens,,,
|
||||
Andrés,1,1,3
|
||||
Jonathan,1,1,3
|
||||
Jason,1,1,3
|
||||
Yehuda,1,1,3
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open --raw caballeros.txt
|
||||
| lines
|
||||
| skip 2
|
||||
| split column ','
|
||||
| headers
|
||||
| skip 1
|
||||
| keep while "Chicken Collection" != "Blue Chickens"
|
||||
| str to-int "31/04/2020"
|
||||
| get "31/04/2020"
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
})
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
use nu_test_support::fs::Stub::EmptyFile;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn gets_the_last_row() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"ls | sort-by name | last 1 | get name | str trim"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "utf16.ini");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gets_last_rows_by_amount() {
|
||||
Playground::setup("last_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("los.txt"),
|
||||
EmptyFile("tres.txt"),
|
||||
EmptyFile("amigos.txt"),
|
||||
EmptyFile("arepas.clu"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| last 3
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gets_last_row_when_no_amount_given() {
|
||||
Playground::setup("last_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("caballeros.txt"), EmptyFile("arepas.clu")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| last
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn requests_more_rows_than_table_has() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
date | last 50 | count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn lines() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml -r
|
||||
| lines
|
||||
| skip while $it != "[dependencies]"
|
||||
| skip 1
|
||||
| first 1
|
||||
| split column "="
|
||||
| get Column1
|
||||
| str trim
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "rustyline");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lines_proper_buffering() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open lines_test.txt -r
|
||||
| lines
|
||||
| str length
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[8193,3]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lines_multi_value_split() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample-simple.json
|
||||
| get first second
|
||||
| lines
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "6");
|
||||
}
|
@ -1,329 +0,0 @@
|
||||
use nu_test_support::fs::Stub::EmptyFile;
|
||||
use nu_test_support::playground::{Dirs, Playground};
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn lists_regular_files() {
|
||||
Playground::setup("ls_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("yehuda.txt"),
|
||||
EmptyFile("jonathan.txt"),
|
||||
EmptyFile("andres.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lists_regular_files_using_asterisk_wildcard() {
|
||||
Playground::setup("ls_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("los.txt"),
|
||||
EmptyFile("tres.txt"),
|
||||
EmptyFile("amigos.txt"),
|
||||
EmptyFile("arepas.clu"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls *.txt
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lists_regular_files_using_question_mark_wildcard() {
|
||||
Playground::setup("ls_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("yehuda.10.txt"),
|
||||
EmptyFile("jonathan.10.txt"),
|
||||
EmptyFile("andres.10.txt"),
|
||||
EmptyFile("chicken_not_to_be_picked_up.100.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls *.??.txt
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lists_all_files_in_directories_from_stream() {
|
||||
Playground::setup("ls_test_4", |dirs, sandbox| {
|
||||
sandbox
|
||||
.with_files(vec![EmptyFile("root1.txt"), EmptyFile("root2.txt")])
|
||||
.within("dir_a")
|
||||
.with_files(vec![
|
||||
EmptyFile("yehuda.10.txt"),
|
||||
EmptyFile("jonathan.10.txt"),
|
||||
])
|
||||
.within("dir_b")
|
||||
.with_files(vec![
|
||||
EmptyFile("andres.10.txt"),
|
||||
EmptyFile("chicken_not_to_be_picked_up.100.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
echo dir_a dir_b
|
||||
| each { ls $it }
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn does_not_fail_if_glob_matches_empty_directory() {
|
||||
Playground::setup("ls_test_5", |dirs, sandbox| {
|
||||
sandbox.within("dir_a");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls dir_a
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "0");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fails_when_glob_doesnt_match() {
|
||||
Playground::setup("ls_test_5", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("root1.txt"), EmptyFile("root2.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"ls root3*"
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("no matches found"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_files_from_two_parents_up_using_multiple_dots() {
|
||||
Playground::setup("ls_test_6", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("yahuda.yaml"),
|
||||
EmptyFile("jonathan.json"),
|
||||
EmptyFile("andres.xml"),
|
||||
EmptyFile("kevin.txt"),
|
||||
]);
|
||||
|
||||
sandbox.within("foo").mkdir("bar");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test().join("foo/bar"),
|
||||
r#"
|
||||
ls ... | count
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "5");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lists_hidden_file_when_explicitly_specified() {
|
||||
Playground::setup("ls_test_7", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("los.txt"),
|
||||
EmptyFile("tres.txt"),
|
||||
EmptyFile("amigos.txt"),
|
||||
EmptyFile("arepas.clu"),
|
||||
EmptyFile(".testdotfile"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls .testdotfile
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lists_all_hidden_files_when_glob_contains_dot() {
|
||||
Playground::setup("ls_test_8", |dirs, sandbox| {
|
||||
sandbox
|
||||
.with_files(vec![
|
||||
EmptyFile("root1.txt"),
|
||||
EmptyFile("root2.txt"),
|
||||
EmptyFile(".dotfile1"),
|
||||
])
|
||||
.within("dir_a")
|
||||
.with_files(vec![
|
||||
EmptyFile("yehuda.10.txt"),
|
||||
EmptyFile("jonathan.10.txt"),
|
||||
EmptyFile(".dotfile2"),
|
||||
])
|
||||
.within("dir_b")
|
||||
.with_files(vec![
|
||||
EmptyFile("andres.10.txt"),
|
||||
EmptyFile("chicken_not_to_be_picked_up.100.txt"),
|
||||
EmptyFile(".dotfile3"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls **/.*
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
// TODO Remove this cfg value when we have an OS-agnostic way
|
||||
// of creating hidden files using the playground.
|
||||
#[cfg(unix)]
|
||||
fn lists_all_hidden_files_when_glob_does_not_contain_dot() {
|
||||
Playground::setup("ls_test_8", |dirs, sandbox| {
|
||||
sandbox
|
||||
.with_files(vec![
|
||||
EmptyFile("root1.txt"),
|
||||
EmptyFile("root2.txt"),
|
||||
EmptyFile(".dotfile1"),
|
||||
])
|
||||
.within("dir_a")
|
||||
.with_files(vec![
|
||||
EmptyFile("yehuda.10.txt"),
|
||||
EmptyFile("jonathan.10.txt"),
|
||||
EmptyFile(".dotfile2"),
|
||||
])
|
||||
.within(".dir_b")
|
||||
.with_files(vec![
|
||||
EmptyFile("andres.10.txt"),
|
||||
EmptyFile("chicken_not_to_be_picked_up.100.txt"),
|
||||
EmptyFile(".dotfile3"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls **/*
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "5");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lists_files_including_starting_with_dot() {
|
||||
Playground::setup("ls_test_9", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("yehuda.txt"),
|
||||
EmptyFile("jonathan.txt"),
|
||||
EmptyFile("andres.txt"),
|
||||
EmptyFile(".hidden1.txt"),
|
||||
EmptyFile(".hidden2.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls -a
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "5");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_all_columns() {
|
||||
Playground::setup(
|
||||
"ls_test_all_columns",
|
||||
|dirs: Dirs, sandbox: &mut Playground| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("Leonardo.yaml"),
|
||||
EmptyFile("Raphael.json"),
|
||||
EmptyFile("Donatello.xml"),
|
||||
EmptyFile("Michelangelo.txt"),
|
||||
]);
|
||||
// Normal Operation
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"ls | get | to md"
|
||||
);
|
||||
let expected = ["name", "type", "size", "modified"].join("");
|
||||
assert_eq!(actual.out, expected, "column names are incorrect for ls");
|
||||
// Long
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"ls -l | get | to md"
|
||||
);
|
||||
let expected = {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
[
|
||||
"name",
|
||||
"type",
|
||||
"target",
|
||||
"num_links",
|
||||
"inode",
|
||||
"readonly",
|
||||
"mode",
|
||||
"uid",
|
||||
"group",
|
||||
"size",
|
||||
"created",
|
||||
"accessed",
|
||||
"modified",
|
||||
]
|
||||
.join("")
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
[
|
||||
"name", "type", "target", "readonly", "size", "created", "accessed",
|
||||
"modified",
|
||||
]
|
||||
.join("")
|
||||
}
|
||||
};
|
||||
assert_eq!(
|
||||
actual.out, expected,
|
||||
"column names are incorrect for ls long"
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn can_average_numbers() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sgml_description.json
|
||||
| get glossary.GlossDiv.GlossList.GlossEntry.Sections
|
||||
| math avg
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "101.5")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_average_bytes() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"ls | sort-by name | skip 1 | first 2 | get size | math avg | format \"{$it}\" "
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "1.6 KB");
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn evaluates_two_plus_two() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
math eval "2 + 2"
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("4.0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_two_to_the_power_four() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "2 ^ 4" | math eval
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("16.0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_three_multiplied_by_five() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "3 * 5" | math eval
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("15.0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_twenty_four_divided_by_two() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "24 / 2" | math eval
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("12.0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_twenty_eight_minus_seven() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "28 - 7" | math eval
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("21"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_pi() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
math eval pi
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("3.14"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_tau() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
math eval tau
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("6.28"));
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn median_numbers_with_even_rows() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [10 6 19 21 4]
|
||||
| math median
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "10")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn median_numbers_with_odd_rows() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [3 8 9 12 12 15]
|
||||
| math median
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "10.5")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn median_mixed_numbers() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [-11.5 -13.5 10]
|
||||
| math median
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "-11.5")
|
||||
}
|
@ -1,258 +0,0 @@
|
||||
mod avg;
|
||||
mod eval;
|
||||
mod median;
|
||||
mod sum;
|
||||
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn one_arg() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1 + 1
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_compound() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1 + 2 + 2
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn precedence_of_operators() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1 + 2 * 2
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn precedence_of_operators2() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1 + 2 * 2 + 1
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "6");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn division_of_ints() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 4 / 2
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn division_of_ints2() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1 / 4
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "0.25");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_zero_division_int_int() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1 / 0
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("division by zero"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_zero_division_decimal_int() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1.0 / 0
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("division by zero"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_zero_division_int_decimal() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1 / 0.0
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("division by zero"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_zero_division_decimal_decimal() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1.0 / 0.0
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("division by zero"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn proper_precedence_history() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 2 / 2 / 2 + 1
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1.5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parens_precedence() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 4 * (6 - 3)
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "12");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn modulo() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 9 mod 2
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duration_math() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1wk + 1day
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "8day");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duration_math_with_nanoseconds() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1wk + 10ns
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "7day 10ns");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duration_math_with_negative() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1day - 1wk
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "-6day");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compound_comparison() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 4 > 3 && 2 > 1
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compound_comparison2() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 4 < 3 || 2 > 1
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compound_where() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from json | where a == 2 && b == 1 | to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, r#"{"a":2,"b":1}"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compound_where_paren() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from json | where (a == 2 && b == 1) || b == 2 | to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, r#"[{"a":2,"b":1},{"a":2,"b":2}]"#);
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
use std::str::FromStr;
|
||||
|
||||
#[test]
|
||||
fn all() {
|
||||
Playground::setup("sum_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"meals.json",
|
||||
r#"
|
||||
{
|
||||
meals: [
|
||||
{description: "1 large egg", calories: 90},
|
||||
{description: "1 cup white rice", calories: 250},
|
||||
{description: "1 tablespoon fish oil", calories: 108}
|
||||
]
|
||||
}
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open meals.json
|
||||
| get meals
|
||||
| get calories
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "448");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(clippy::unreadable_literal)]
|
||||
#[allow(clippy::float_cmp)]
|
||||
fn compute_sum_of_individual_row() -> Result<(), String> {
|
||||
let answers_for_columns = [
|
||||
("cpu", 88.257434),
|
||||
("mem", 3032375296.),
|
||||
("virtual", 102579965952.),
|
||||
];
|
||||
for (column_name, expected_value) in answers_for_columns.iter() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats/",
|
||||
format!("open sample-ps-output.json | select {} | math sum | get {}", column_name, column_name)
|
||||
);
|
||||
let result =
|
||||
f64::from_str(&actual.out).map_err(|_| String::from("Failed to parse float."))?;
|
||||
assert_eq!(result, *expected_value);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(clippy::unreadable_literal)]
|
||||
#[allow(clippy::float_cmp)]
|
||||
fn compute_sum_of_table() -> Result<(), String> {
|
||||
let answers_for_columns = [
|
||||
("cpu", 88.257434),
|
||||
("mem", 3032375296.),
|
||||
("virtual", 102579965952.),
|
||||
];
|
||||
for (column_name, expected_value) in answers_for_columns.iter() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats/",
|
||||
format!("open sample-ps-output.json | select cpu mem virtual | math sum | get {}", column_name)
|
||||
);
|
||||
let result =
|
||||
f64::from_str(&actual.out).map_err(|_| String::from("Failed to parse float."))?;
|
||||
assert_eq!(result, *expected_value);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sum_of_a_row_containing_a_table_is_an_error() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats/",
|
||||
"open sample-sys-output.json | math sum"
|
||||
);
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("Attempted to compute values that can't be operated on"));
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn row() {
|
||||
Playground::setup("merge_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
FileWithContentToBeTrimmed(
|
||||
"caballeros.csv",
|
||||
r#"
|
||||
name,country,luck
|
||||
Andrés,Ecuador,0
|
||||
Jonathan,USA,0
|
||||
Jason,Canada,0
|
||||
Yehuda,USA,0
|
||||
"#,
|
||||
),
|
||||
FileWithContentToBeTrimmed(
|
||||
"new_caballeros.csv",
|
||||
r#"
|
||||
name,country,luck
|
||||
Andrés Robalino,Guayaquil Ecuador,1
|
||||
Jonathan Turner,New Zealand,1
|
||||
"#,
|
||||
),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open caballeros.csv
|
||||
| merge { open new_caballeros.csv }
|
||||
| where country in ["Guayaquil Ecuador" "New Zealand"]
|
||||
| get luck
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
})
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
use nu_test_support::fs::files_exist_at;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
use std::path::Path;
|
||||
|
||||
#[test]
|
||||
fn creates_directory() {
|
||||
Playground::setup("mkdir_test_1", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mkdir my_new_directory"
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("my_new_directory");
|
||||
|
||||
assert!(expected.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accepts_and_creates_directories() {
|
||||
Playground::setup("mkdir_test_2", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mkdir dir_1 dir_2 dir_3"
|
||||
);
|
||||
|
||||
assert!(files_exist_at(
|
||||
vec![Path::new("dir_1"), Path::new("dir_2"), Path::new("dir_3")],
|
||||
dirs.test()
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn creates_intermediary_directories() {
|
||||
Playground::setup("mkdir_test_3", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mkdir some_folder/another/deeper_one"
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("some_folder/another/deeper_one");
|
||||
|
||||
assert!(expected.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_directory_two_parents_up_using_multiple_dots() {
|
||||
Playground::setup("mkdir_test_4", |dirs, sandbox| {
|
||||
sandbox.within("foo").mkdir("bar");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test().join("foo/bar"),
|
||||
"mkdir .../boo"
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("boo");
|
||||
|
||||
assert!(expected.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_created_paths() {
|
||||
Playground::setup("mkdir_test_2", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
pipeline(
|
||||
r#"
|
||||
mkdir -s dir_1 dir_2 dir_3
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(files_exist_at(
|
||||
vec![Path::new("dir_1"), Path::new("dir_2"), Path::new("dir_3")],
|
||||
dirs.test()
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
mod append;
|
||||
mod autoenv;
|
||||
mod autoenv_trust;
|
||||
mod autoenv_untrust;
|
||||
mod cal;
|
||||
mod cd;
|
||||
mod compact;
|
||||
mod count;
|
||||
mod cp;
|
||||
mod def;
|
||||
mod default;
|
||||
mod drop;
|
||||
mod each;
|
||||
mod echo;
|
||||
mod empty;
|
||||
mod enter;
|
||||
mod every;
|
||||
mod first;
|
||||
mod flatten;
|
||||
mod format;
|
||||
mod get;
|
||||
mod group_by;
|
||||
mod hash_;
|
||||
mod headers;
|
||||
mod histogram;
|
||||
mod insert;
|
||||
mod into_int;
|
||||
mod keep;
|
||||
mod last;
|
||||
mod lines;
|
||||
mod ls;
|
||||
mod math;
|
||||
mod merge;
|
||||
mod mkdir;
|
||||
mod move_;
|
||||
mod open;
|
||||
mod parse;
|
||||
mod path;
|
||||
mod prepend;
|
||||
mod random;
|
||||
mod range;
|
||||
mod reduce;
|
||||
mod rename;
|
||||
mod reverse;
|
||||
mod rm;
|
||||
mod save;
|
||||
mod select;
|
||||
mod semicolon;
|
||||
mod skip;
|
||||
mod sort_by;
|
||||
mod split_by;
|
||||
mod split_column;
|
||||
mod split_row;
|
||||
mod str_;
|
||||
mod touch;
|
||||
mod uniq;
|
||||
mod update;
|
||||
mod where_;
|
||||
mod which;
|
||||
mod with_env;
|
||||
mod wrap;
|
@ -1,137 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn moves_a_column_before() {
|
||||
Playground::setup("move_column_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"sample.csv",
|
||||
r#"
|
||||
column1,column2,column3,...,column98,column99,column100
|
||||
-------,-------,-------,---,--------, A ,---------
|
||||
-------,-------,-------,---,--------, N ,---------
|
||||
-------,-------,-------,---,--------, D ,---------
|
||||
-------,-------,-------,---,--------, R ,---------
|
||||
-------,-------,-------,---,--------, E ,---------
|
||||
-------,-------,-------,---,--------, S ,---------
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.csv
|
||||
| move column99 --before column1
|
||||
| rename chars
|
||||
| get chars
|
||||
| str trim
|
||||
| str collect
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("ANDRES"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moves_columns_before() {
|
||||
Playground::setup("move_column_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"sample.csv",
|
||||
r#"
|
||||
column1,column2,column3,...,column98,column99,column100
|
||||
-------,-------, A ,---,--------, N ,---------
|
||||
-------,-------, D ,---,--------, R ,---------
|
||||
-------,-------, E ,---,--------, S ,---------
|
||||
-------,-------, : ,---,--------, : ,---------
|
||||
-------,-------, J ,---,--------, O ,---------
|
||||
-------,-------, N ,---,--------, A ,---------
|
||||
-------,-------, T ,---,--------, H ,---------
|
||||
-------,-------, A ,---,--------, N ,---------
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.csv
|
||||
| move column99 column3 --before column2
|
||||
| rename _ chars_1 chars_2
|
||||
| get chars_2 chars_1
|
||||
| str trim
|
||||
| str collect
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("ANDRES::JONATHAN"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moves_a_column_after() {
|
||||
Playground::setup("move_column_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"sample.csv",
|
||||
r#"
|
||||
column1,column2,letters,...,column98,and_more,column100
|
||||
-------,-------, A ,---,--------, N ,---------
|
||||
-------,-------, D ,---,--------, R ,---------
|
||||
-------,-------, E ,---,--------, S ,---------
|
||||
-------,-------, : ,---,--------, : ,---------
|
||||
-------,-------, J ,---,--------, O ,---------
|
||||
-------,-------, N ,---,--------, A ,---------
|
||||
-------,-------, T ,---,--------, H ,---------
|
||||
-------,-------, A ,---,--------, N ,---------
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.csv
|
||||
| move letters --after and_more
|
||||
| move letters and_more --before column2
|
||||
| rename _ chars_1 chars_2
|
||||
| get chars_1 chars_2
|
||||
| str trim
|
||||
| str collect
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("ANDRES::JONATHAN"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moves_columns_after() {
|
||||
Playground::setup("move_column_test_4", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"sample.csv",
|
||||
r#"
|
||||
column1,column2,letters,...,column98,and_more,column100
|
||||
-------,-------, A ,---,--------, N ,---------
|
||||
-------,-------, D ,---,--------, R ,---------
|
||||
-------,-------, E ,---,--------, S ,---------
|
||||
-------,-------, : ,---,--------, : ,---------
|
||||
-------,-------, J ,---,--------, O ,---------
|
||||
-------,-------, N ,---,--------, A ,---------
|
||||
-------,-------, T ,---,--------, H ,---------
|
||||
-------,-------, A ,---,--------, N ,---------
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.csv
|
||||
| move letters and_more --after column1
|
||||
| get
|
||||
| nth 1 2
|
||||
| str collect
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("lettersand_more"));
|
||||
})
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
mod column;
|
||||
mod mv;
|
@ -1,361 +0,0 @@
|
||||
use nu_test_support::fs::{files_exist_at, Stub::EmptyFile};
|
||||
use nu_test_support::nu;
|
||||
use nu_test_support::playground::Playground;
|
||||
|
||||
#[test]
|
||||
fn moves_a_file() {
|
||||
Playground::setup("mv_test_1", |dirs, sandbox| {
|
||||
sandbox
|
||||
.with_files(vec![EmptyFile("andres.txt")])
|
||||
.mkdir("expected");
|
||||
|
||||
let original = dirs.test().join("andres.txt");
|
||||
let expected = dirs.test().join("expected/yehuda.txt");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mv andres.txt expected/yehuda.txt"
|
||||
);
|
||||
|
||||
assert!(!original.exists());
|
||||
assert!(expected.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overwrites_if_moving_to_existing_file() {
|
||||
Playground::setup("mv_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("andres.txt"), EmptyFile("jonathan.txt")]);
|
||||
|
||||
let original = dirs.test().join("andres.txt");
|
||||
let expected = dirs.test().join("jonathan.txt");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mv andres.txt jonathan.txt"
|
||||
);
|
||||
|
||||
assert!(!original.exists());
|
||||
assert!(expected.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moves_a_directory() {
|
||||
Playground::setup("mv_test_3", |dirs, sandbox| {
|
||||
sandbox.mkdir("empty_dir");
|
||||
|
||||
let original_dir = dirs.test().join("empty_dir");
|
||||
let expected = dirs.test().join("renamed_dir");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mv empty_dir renamed_dir"
|
||||
);
|
||||
|
||||
assert!(!original_dir.exists());
|
||||
assert!(expected.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moves_the_file_inside_directory_if_path_to_move_is_existing_directory() {
|
||||
Playground::setup("mv_test_4", |dirs, sandbox| {
|
||||
sandbox
|
||||
.with_files(vec![EmptyFile("jonathan.txt")])
|
||||
.mkdir("expected");
|
||||
|
||||
let original_dir = dirs.test().join("jonathan.txt");
|
||||
let expected = dirs.test().join("expected/jonathan.txt");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mv jonathan.txt expected"
|
||||
);
|
||||
|
||||
assert!(!original_dir.exists());
|
||||
assert!(expected.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moves_the_directory_inside_directory_if_path_to_move_is_existing_directory() {
|
||||
Playground::setup("mv_test_5", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("contributors")
|
||||
.with_files(vec![EmptyFile("jonathan.txt")])
|
||||
.mkdir("expected");
|
||||
|
||||
let original_dir = dirs.test().join("contributors");
|
||||
let expected = dirs.test().join("expected/contributors");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mv contributors expected"
|
||||
);
|
||||
|
||||
assert!(!original_dir.exists());
|
||||
assert!(expected.exists());
|
||||
assert!(files_exist_at(vec!["jonathan.txt"], expected))
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moves_using_path_with_wildcard() {
|
||||
Playground::setup("mv_test_7", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("originals")
|
||||
.with_files(vec![
|
||||
EmptyFile("andres.ini"),
|
||||
EmptyFile("caco3_plastics.csv"),
|
||||
EmptyFile("cargo_sample.toml"),
|
||||
EmptyFile("jonathan.ini"),
|
||||
EmptyFile("jonathan.xml"),
|
||||
EmptyFile("sgml_description.json"),
|
||||
EmptyFile("sample.ini"),
|
||||
EmptyFile("utf16.ini"),
|
||||
EmptyFile("yehuda.ini"),
|
||||
])
|
||||
.mkdir("work_dir")
|
||||
.mkdir("expected");
|
||||
|
||||
let work_dir = dirs.test().join("work_dir");
|
||||
let expected = dirs.test().join("expected");
|
||||
|
||||
nu!(cwd: work_dir, "mv ../originals/*.ini ../expected");
|
||||
|
||||
assert!(files_exist_at(
|
||||
vec!["yehuda.ini", "jonathan.ini", "sample.ini", "andres.ini",],
|
||||
expected
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moves_using_a_glob() {
|
||||
Playground::setup("mv_test_8", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("meals")
|
||||
.with_files(vec![
|
||||
EmptyFile("arepa.txt"),
|
||||
EmptyFile("empanada.txt"),
|
||||
EmptyFile("taquiza.txt"),
|
||||
])
|
||||
.mkdir("work_dir")
|
||||
.mkdir("expected");
|
||||
|
||||
let meal_dir = dirs.test().join("meals");
|
||||
let work_dir = dirs.test().join("work_dir");
|
||||
let expected = dirs.test().join("expected");
|
||||
|
||||
nu!(cwd: work_dir, "mv ../meals/* ../expected");
|
||||
|
||||
assert!(meal_dir.exists());
|
||||
assert!(files_exist_at(
|
||||
vec!["arepa.txt", "empanada.txt", "taquiza.txt",],
|
||||
expected
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moves_a_directory_with_files() {
|
||||
Playground::setup("mv_test_9", |dirs, sandbox| {
|
||||
sandbox
|
||||
.mkdir("vehicles/car")
|
||||
.mkdir("vehicles/bicycle")
|
||||
.with_files(vec![
|
||||
EmptyFile("vehicles/car/car1.txt"),
|
||||
EmptyFile("vehicles/car/car2.txt"),
|
||||
])
|
||||
.with_files(vec![
|
||||
EmptyFile("vehicles/bicycle/bicycle1.txt"),
|
||||
EmptyFile("vehicles/bicycle/bicycle2.txt"),
|
||||
]);
|
||||
|
||||
let original_dir = dirs.test().join("vehicles");
|
||||
let expected_dir = dirs.test().join("expected");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mv vehicles expected"
|
||||
);
|
||||
|
||||
assert!(!original_dir.exists());
|
||||
assert!(expected_dir.exists());
|
||||
assert!(files_exist_at(
|
||||
vec![
|
||||
"car/car1.txt",
|
||||
"car/car2.txt",
|
||||
"bicycle/bicycle1.txt",
|
||||
"bicycle/bicycle2.txt"
|
||||
],
|
||||
expected_dir
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_source_doesnt_exist() {
|
||||
Playground::setup("mv_test_10", |dirs, sandbox| {
|
||||
sandbox.mkdir("test_folder");
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"mv non-existing-file test_folder/"
|
||||
);
|
||||
assert!(actual.err.contains("Invalid file or pattern"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_destination_doesnt_exist() {
|
||||
Playground::setup("mv_test_10_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("empty.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"mv empty.txt does/not/exist"
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("Destination directory does not exist"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_multiple_sources_but_destination_not_a_directory() {
|
||||
Playground::setup("mv_test_10_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("file1.txt"),
|
||||
EmptyFile("file2.txt"),
|
||||
EmptyFile("file3.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"mv file?.txt not_a_dir"
|
||||
);
|
||||
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("Can only move multiple sources if destination is a directory"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_renaming_directory_to_an_existing_file() {
|
||||
Playground::setup("mv_test_10_3", |dirs, sandbox| {
|
||||
sandbox
|
||||
.mkdir("mydir")
|
||||
.with_files(vec![EmptyFile("empty.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"mv mydir empty.txt"
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("Cannot rename a directory to a file"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_moving_to_itself() {
|
||||
Playground::setup("mv_test_10_4", |dirs, sandbox| {
|
||||
sandbox.mkdir("mydir").mkdir("mydir/mydir_2");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"mv mydir mydir/mydir_2/"
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("cannot move to itself"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn does_not_error_on_relative_parent_path() {
|
||||
Playground::setup("mv_test_11", |dirs, sandbox| {
|
||||
sandbox
|
||||
.mkdir("first")
|
||||
.with_files(vec![EmptyFile("first/william_hartnell.txt")]);
|
||||
|
||||
let original = dirs.test().join("first/william_hartnell.txt");
|
||||
let expected = dirs.test().join("william_hartnell.txt");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test().join("first"),
|
||||
"mv william_hartnell.txt ./.."
|
||||
);
|
||||
|
||||
assert!(!original.exists());
|
||||
assert!(expected.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn move_files_using_glob_two_parents_up_using_multiple_dots() {
|
||||
Playground::setup("mv_test_12", |dirs, sandbox| {
|
||||
sandbox.within("foo").within("bar").with_files(vec![
|
||||
EmptyFile("jonathan.json"),
|
||||
EmptyFile("andres.xml"),
|
||||
EmptyFile("yehuda.yaml"),
|
||||
EmptyFile("kevin.txt"),
|
||||
EmptyFile("many_more.ppl"),
|
||||
]);
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test().join("foo/bar"),
|
||||
r#"
|
||||
mv * ...
|
||||
"#
|
||||
);
|
||||
|
||||
let files = vec![
|
||||
"yehuda.yaml",
|
||||
"jonathan.json",
|
||||
"andres.xml",
|
||||
"kevin.txt",
|
||||
"many_more.ppl",
|
||||
];
|
||||
|
||||
let original_dir = dirs.test().join("foo/bar");
|
||||
let destination_dir = dirs.test();
|
||||
|
||||
assert!(files_exist_at(files.clone(), destination_dir));
|
||||
assert!(!files_exist_at(files, original_dir))
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn move_file_from_two_parents_up_using_multiple_dots_to_current_dir() {
|
||||
Playground::setup("cp_test_10", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("hello_there")]);
|
||||
sandbox.within("foo").mkdir("bar");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test().join("foo/bar"),
|
||||
r#"
|
||||
mv .../hello_there .
|
||||
"#
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("foo/bar/hello_there");
|
||||
let original = dirs.test().join("hello_there");
|
||||
|
||||
assert!(expected.exists());
|
||||
assert!(!original.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn does_not_error_when_some_file_is_moving_into_itself() {
|
||||
Playground::setup("mv_test_13", |dirs, sandbox| {
|
||||
sandbox.mkdir("11").mkdir("12");
|
||||
|
||||
let original_dir = dirs.test().join("11");
|
||||
let expected = dirs.test().join("12/11");
|
||||
nu!(cwd: dirs.test(), "mv 1* 12");
|
||||
|
||||
assert!(!original_dir.exists());
|
||||
assert!(expected.exists());
|
||||
})
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
#[test]
|
||||
fn selects_a_row() {
|
||||
Playground::setup("nth_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("notes.txt"), EmptyFile("arepas.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| sort-by name
|
||||
| nth 0
|
||||
| get name
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "arepas.txt");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selects_many_rows() {
|
||||
Playground::setup("nth_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("notes.txt"), EmptyFile("arepas.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| get name
|
||||
| nth 1 0
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
});
|
||||
}
|
@ -1,232 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn parses_csv() {
|
||||
Playground::setup("open_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"nu.zion.csv",
|
||||
r#"
|
||||
author,lang,source
|
||||
Jonathan Turner,Rust,New Zealand
|
||||
Andres N. Robalino,Rust,Ecuador
|
||||
Yehuda Katz,Rust,Estados Unidos
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open nu.zion.csv
|
||||
| where author == "Andres N. Robalino"
|
||||
| get source
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "Ecuador");
|
||||
})
|
||||
}
|
||||
|
||||
// sample.bson has the following format:
|
||||
// ━━━━━━━━━━┯━━━━━━━━━━━
|
||||
// _id │ root
|
||||
// ──────────┼───────────
|
||||
// [object] │ [9 items]
|
||||
// ━━━━━━━━━━┷━━━━━━━━━━━
|
||||
//
|
||||
// the root value is:
|
||||
// ━━━┯━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━
|
||||
// # │ _id │ a │ b │ c
|
||||
// ───┼───────────────────┼─────────────────────────┼──────────┼──────────
|
||||
// 0 │ [object] │ 1.000000000000000 │ hello │ [2 items]
|
||||
// 1 │ [object] │ 42.00000000000000 │ whel │ hello
|
||||
// 2 │ [object] │ [object] │ │
|
||||
// 3 │ [object] │ │ [object] │
|
||||
// 4 │ [object] │ │ │ [object]
|
||||
// 5 │ [object] │ │ │ [object]
|
||||
// 6 │ [object] │ [object] │ [object] │
|
||||
// 7 │ [object] │ <date value> │ [object] │
|
||||
// 8 │ 1.000000 │ <decimal value> │ [object] │
|
||||
//
|
||||
// The decimal value is supposed to be π, but is currently wrong due to
|
||||
// what appears to be an issue in the bson library that is under investigation.
|
||||
//
|
||||
|
||||
#[cfg(feature = "bson")]
|
||||
#[test]
|
||||
fn parses_bson() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"open sample.bson | get root | nth 0 | get b"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "hello");
|
||||
}
|
||||
|
||||
#[cfg(feature = "bson")]
|
||||
#[test]
|
||||
fn parses_more_bson_complexity() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample.bson
|
||||
| get root
|
||||
| nth 6
|
||||
| get b
|
||||
| get '$binary_subtype'
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "function");
|
||||
}
|
||||
|
||||
// sample.db has the following format:
|
||||
//
|
||||
// ━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━
|
||||
// # │ table_name │ table_values
|
||||
// ───┼────────────┼──────────────
|
||||
// 0 │ strings │ [6 items]
|
||||
// 1 │ ints │ [5 items]
|
||||
// 2 │ floats │ [4 items]
|
||||
// ━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━━
|
||||
//
|
||||
// In this case, this represents a sqlite database
|
||||
// with three tables named `strings`, `ints`, and `floats`.
|
||||
// The table_values represent the values for the tables:
|
||||
//
|
||||
// ━━━━┯━━━━━━━┯━━━━━━━━━━┯━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
// # │ x │ y │ z │ f
|
||||
// ────┼───────┼──────────┼──────┼──────────────────────────────────────────────────────────────────────
|
||||
// 0 │ hello │ <binary> │ │
|
||||
// 1 │ hello │ <binary> │ │
|
||||
// 2 │ hello │ <binary> │ │
|
||||
// 3 │ hello │ <binary> │ │
|
||||
// 4 │ world │ <binary> │ │
|
||||
// 5 │ world │ <binary> │ │
|
||||
// 6 │ │ │ 1 │
|
||||
// 7 │ │ │ 42 │
|
||||
// 8 │ │ │ 425 │
|
||||
// 9 │ │ │ 4253 │
|
||||
// 10 │ │ │ │
|
||||
// 11 │ │ │ │ 3.400000000000000
|
||||
// 12 │ │ │ │ 3.141592650000000
|
||||
// 13 │ │ │ │ 23.00000000000000
|
||||
// 14 │ │ │ │ this string that doesn't really belong here but sqlite is what it is
|
||||
// ━━━━┷━━━━━━━┷━━━━━━━━━━┷━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
//
|
||||
// We can see here that each table has different columns. `strings` has `x` and `y`, while
|
||||
// `ints` has just `z`, and `floats` has only the column `f`. This means, in general, when working
|
||||
// with sqlite, one will want to select a single table, e.g.:
|
||||
//
|
||||
// open sample.db | nth 1 | get table_values
|
||||
// ━━━┯━━━━━━
|
||||
// # │ z
|
||||
// ───┼──────
|
||||
// 0 │ 1
|
||||
// 1 │ 42
|
||||
// 2 │ 425
|
||||
// 3 │ 4253
|
||||
// 4 │
|
||||
// ━━━┷━━━━━━
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
#[test]
|
||||
fn parses_sqlite() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample.db
|
||||
| get table_values
|
||||
| nth 2
|
||||
| get x
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "hello");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_toml() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"open cargo_sample.toml | get package.edition"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "2018");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_tsv() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open caco3_plastics.tsv
|
||||
| first 1
|
||||
| get origin
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "SPAIN")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_json() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sgml_description.json
|
||||
| get glossary.GlossDiv.GlossList.GlossEntry.GlossSee
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "markup")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_xml() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"open jonathan.xml | get rss.children.channel.children | get item.children | get link.children.0"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"http://www.jonathanturner.org/2015/10/off-to-new-adventures.html"
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_ini() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"open sample.ini | get SectionOne.integer"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "1234")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_utf16_ini() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"open utf16.ini | get '.ShellClassInfo' | get IconIndex"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "-236")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_file_not_found() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"open i_dont_exist.txt"
|
||||
);
|
||||
let expected = "Cannot find file";
|
||||
assert!(
|
||||
actual.err.contains(expected),
|
||||
"Error:\n{}\ndoes not contain{}",
|
||||
actual.err,
|
||||
expected
|
||||
);
|
||||
}
|
@ -1,187 +0,0 @@
|
||||
use nu_test_support::fs::Stub;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
mod simple {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn extracts_fields_from_the_given_the_pattern() {
|
||||
Playground::setup("parse_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![Stub::FileWithContentToBeTrimmed(
|
||||
"key_value_separated_arepa_ingredients.txt",
|
||||
r#"
|
||||
VAR1=Cheese
|
||||
VAR2=JonathanParsed
|
||||
VAR3=NushellSecretIngredient
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open key_value_separated_arepa_ingredients.txt
|
||||
| lines
|
||||
| each { echo $it | parse "{Name}={Value}" }
|
||||
| nth 1
|
||||
| get Value
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "JonathanParsed");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_open_curly_evalutes_to_a_single_curly() {
|
||||
Playground::setup("parse_test_regex_2", |dirs, _sandbox| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
echo "{abc}123"
|
||||
| parse "{{abc}{name}"
|
||||
| get name
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "123");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn properly_escapes_text() {
|
||||
Playground::setup("parse_test_regex_3", |dirs, _sandbox| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
echo "(abc)123"
|
||||
| parse "(abc){name}"
|
||||
| get name
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "123");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn properly_captures_empty_column() {
|
||||
Playground::setup("parse_test_regex_4", |dirs, _sandbox| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
echo ["1:INFO:component:all is well" "2:ERROR::something bad happened"]
|
||||
| parse "{timestamp}:{level}:{tag}:{entry}"
|
||||
| get entry
|
||||
| nth 1
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "something bad happened");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_when_missing_closing_brace() {
|
||||
Playground::setup("parse_test_regex_5", |dirs, _sandbox| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
echo "(abc)123"
|
||||
| parse "(abc){name"
|
||||
| get name
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("invalid parse pattern"));
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
mod regex {
|
||||
use super::*;
|
||||
|
||||
fn nushell_git_log_oneline<'a>() -> Vec<Stub<'a>> {
|
||||
vec![Stub::FileWithContentToBeTrimmed(
|
||||
"nushell_git_log_oneline.txt",
|
||||
r#"
|
||||
ae87582c Fix missing invocation errors (#1846)
|
||||
b89976da let format access variables also (#1842)
|
||||
"#,
|
||||
)]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extracts_fields_with_all_named_groups() {
|
||||
Playground::setup("parse_test_regex_1", |dirs, sandbox| {
|
||||
sandbox.with_files(nushell_git_log_oneline());
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open nushell_git_log_oneline.txt
|
||||
| parse --regex "(?P<Hash>\w+) (?P<Message>.+) \(#(?P<PR>\d+)\)"
|
||||
| nth 1
|
||||
| get PR
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1842");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extracts_fields_with_all_unnamed_groups() {
|
||||
Playground::setup("parse_test_regex_2", |dirs, sandbox| {
|
||||
sandbox.with_files(nushell_git_log_oneline());
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open nushell_git_log_oneline.txt
|
||||
| parse --regex "(\w+) (.+) \(#(\d+)\)"
|
||||
| nth 1
|
||||
| get Capture1
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "b89976da");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extracts_fields_with_named_and_unnamed_groups() {
|
||||
Playground::setup("parse_test_regex_3", |dirs, sandbox| {
|
||||
sandbox.with_files(nushell_git_log_oneline());
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open nushell_git_log_oneline.txt
|
||||
| parse --regex "(?P<Hash>\w+) (.+) \(#(?P<PR>\d+)\)"
|
||||
| nth 1
|
||||
| get Capture2
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "let format access variables also");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_with_invalid_regex() {
|
||||
Playground::setup("parse_test_regex_1", |dirs, sandbox| {
|
||||
sandbox.with_files(nushell_git_log_oneline());
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open nushell_git_log_oneline.txt
|
||||
| parse --regex "(?P<Hash>\w+ unfinished capture group"
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("invalid regex"));
|
||||
})
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
use super::join_path_sep;
|
||||
|
||||
#[test]
|
||||
fn returns_basename_of_empty_input() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo ""
|
||||
| path basename
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replaces_basename_of_empty_input() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo ""
|
||||
| path basename -r newname.txt
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "newname.txt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_basename_of_path_ending_with_dot() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "some/file.txt/."
|
||||
| path basename
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "file.txt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replaces_basename_of_path_ending_with_dot() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "some/file.txt/."
|
||||
| path basename -r viking.txt
|
||||
"#
|
||||
));
|
||||
|
||||
let expected = join_path_sep(&["some", "viking.txt"]);
|
||||
assert_eq!(actual.out, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_basename_of_path_ending_with_double_dot() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "some/file.txt/.."
|
||||
| path basename
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replaces_basename_of_path_ending_with_double_dot() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "some/file.txt/.."
|
||||
| path basename -r eggs
|
||||
"#
|
||||
));
|
||||
|
||||
let expected = join_path_sep(&["some/file.txt/..", "eggs"]);
|
||||
assert_eq!(actual.out, expected);
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
use super::join_path_sep;
|
||||
|
||||
#[test]
|
||||
fn returns_dirname_of_empty_input() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo ""
|
||||
| path dirname
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replaces_dirname_of_empty_input() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo ""
|
||||
| path dirname -r newdir
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "newdir");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_dirname_of_path_ending_with_dot() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "some/dir/."
|
||||
| path dirname
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "some");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replaces_dirname_of_path_ending_with_dot() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "some/dir/."
|
||||
| path dirname -r eggs
|
||||
"#
|
||||
));
|
||||
|
||||
let expected = join_path_sep(&["eggs", "dir"]);
|
||||
assert_eq!(actual.out, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_dirname_of_path_ending_with_double_dot() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "some/dir/.."
|
||||
| path dirname
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "some/dir");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replaces_dirname_of_path_with_double_dot() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "some/dir/.."
|
||||
| path dirname -r eggs
|
||||
"#
|
||||
));
|
||||
|
||||
let expected = join_path_sep(&["eggs", ".."]);
|
||||
assert_eq!(actual.out, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_dirname_of_zero_levels() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "some/dir/with/spam.txt"
|
||||
| path dirname -n 0
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "some/dir/with/spam.txt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replaces_dirname_of_zero_levels_with_empty_string() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "some/dir/with/spam.txt"
|
||||
| path dirname -n 0 -r ""
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replaces_dirname_of_more_levels() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "some/dir/with/spam.txt"
|
||||
| path dirname -r eggs -n 2
|
||||
"#
|
||||
));
|
||||
|
||||
let expected = join_path_sep(&["eggs", "with/spam.txt"]);
|
||||
assert_eq!(actual.out, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replaces_dirname_of_way_too_many_levels() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "some/dir/with/spam.txt"
|
||||
| path dirname -r eggs -n 999
|
||||
"#
|
||||
));
|
||||
|
||||
let expected = join_path_sep(&["eggs", "some/dir/with/spam.txt"]);
|
||||
assert_eq!(actual.out, expected);
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
use nu_test_support::fs::Stub::EmptyFile;
|
||||
use nu_test_support::nu;
|
||||
use nu_test_support::playground::Playground;
|
||||
|
||||
#[test]
|
||||
fn checks_if_existing_file_exists() {
|
||||
Playground::setup("path_exists_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("spam.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"echo spam.txt | path exists"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checks_if_missing_file_exists() {
|
||||
Playground::setup("path_exists_2", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"echo spam.txt | path exists"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "false");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checks_if_dot_exists() {
|
||||
Playground::setup("path_exists_3", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"echo '.' | path exists"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checks_if_double_dot_exists() {
|
||||
Playground::setup("path_exists_4", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"echo '..' | path exists"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
})
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
use nu_test_support::fs::Stub::EmptyFile;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[test]
|
||||
fn expands_path_with_dot() {
|
||||
Playground::setup("path_expand_1", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("menu")
|
||||
.with_files(vec![EmptyFile("spam.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
echo "menu/./spam.txt"
|
||||
| path expand
|
||||
"#
|
||||
));
|
||||
|
||||
let expected = dirs.test.join("menu").join("spam.txt");
|
||||
assert_eq!(PathBuf::from(actual.out), expected);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expands_path_with_double_dot() {
|
||||
Playground::setup("path_expand_2", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("menu")
|
||||
.with_files(vec![EmptyFile("spam.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
echo "menu/../menu/spam.txt"
|
||||
| path expand
|
||||
"#
|
||||
));
|
||||
|
||||
let expected = dirs.test.join("menu").join("spam.txt");
|
||||
assert_eq!(PathBuf::from(actual.out), expected);
|
||||
})
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn returns_extension_of_path_ending_with_dot() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "bacon." | path extension
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replaces_extension_with_dot_of_path_ending_with_dot() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "bacon." | path extension -r .egg
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "bacon..egg");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replaces_extension_of_empty_path() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "" | path extension -r egg
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "");
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
use super::join_path_sep;
|
||||
|
||||
#[test]
|
||||
fn returns_filestem_of_dot() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "menu/eggs/."
|
||||
| path filestem
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "eggs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_filestem_of_double_dot() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "menu/eggs/.."
|
||||
| path filestem
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_filestem_of_path_with_empty_prefix() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "menu/spam.txt"
|
||||
| path filestem -p ""
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "spam");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_filestem_of_path_with_empty_suffix() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "menu/spam.txt"
|
||||
| path filestem -s ""
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "spam.txt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_filestem_of_path_with_empty_prefix_and_suffix() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "menu/spam.txt"
|
||||
| path filestem -p "" -s ""
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "spam.txt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_filestem_with_wrong_prefix_and_suffix() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "menu/spam.txt"
|
||||
| path filestem -p "bacon" -s "eggs"
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "spam.txt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replaces_filestem_stripped_to_dot() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "menu/spam.txt"
|
||||
| path filestem -p "spam" -s "txt" -r ".eggs."
|
||||
"#
|
||||
));
|
||||
|
||||
let expected = join_path_sep(&["menu", "spam.eggs.txt"]);
|
||||
assert_eq!(actual.out, expected);
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
mod basename;
|
||||
mod dirname;
|
||||
mod exists;
|
||||
mod expand;
|
||||
mod extension;
|
||||
mod filestem;
|
||||
mod type_;
|
||||
|
||||
use std::path::MAIN_SEPARATOR;
|
||||
|
||||
/// Helper function that joins string literals with '/' or '\', based on host OS
|
||||
fn join_path_sep(pieces: &[&str]) -> String {
|
||||
let sep_string = String::from(MAIN_SEPARATOR);
|
||||
pieces.join(&sep_string)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn joins_path_on_windows() {
|
||||
let pieces = ["sausage", "bacon", "spam"];
|
||||
let actual = join_path_sep(&pieces);
|
||||
|
||||
assert_eq!(&actual, "sausage\\bacon\\spam");
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
#[test]
|
||||
fn joins_path_on_other_than_windows() {
|
||||
let pieces = ["sausage", "bacon", "spam"];
|
||||
let actual = join_path_sep(&pieces);
|
||||
|
||||
assert_eq!(&actual, "sausage/bacon/spam");
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
use nu_test_support::fs::Stub::EmptyFile;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn returns_type_of_missing_file() {
|
||||
let actual = nu!(
|
||||
cwd: "tests", pipeline(
|
||||
r#"
|
||||
echo "spam.txt"
|
||||
| path type
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_type_of_existing_file() {
|
||||
Playground::setup("path_expand_1", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("menu")
|
||||
.with_files(vec![EmptyFile("spam.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
echo "menu"
|
||||
| path type
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "Dir");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_type_of_existing_directory() {
|
||||
Playground::setup("path_expand_1", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("menu")
|
||||
.with_files(vec![EmptyFile("spam.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
echo "menu/spam.txt"
|
||||
| path type
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "File");
|
||||
})
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn adds_a_row_to_the_beginning() {
|
||||
Playground::setup("prepend_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.txt",
|
||||
r#"
|
||||
Andrés N. Robalino
|
||||
Jonathan Turner
|
||||
Yehuda Katz
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.txt
|
||||
| lines
|
||||
| prepend "pollo loco"
|
||||
| nth 0
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "pollo loco");
|
||||
})
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn generates_a_bool() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
random bool
|
||||
"#
|
||||
));
|
||||
|
||||
let output = actual.out;
|
||||
let is_boolean_output = output == "true" || output == "false";
|
||||
|
||||
assert!(is_boolean_output);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn generates_chars_of_specified_length() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
random chars -l 15 | size | get chars
|
||||
"#
|
||||
));
|
||||
|
||||
let result = actual.out;
|
||||
assert_eq!(result, "15");
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn generates_an_decimal() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
random decimal 42..43
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("42") || actual.out.contains("43"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generates_55() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
random decimal 55..55
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("55"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generates_0() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
random decimal ..<1
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains('0'));
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn rolls_4_roll() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
random dice -d 4 -s 10 | count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn generates_an_integer() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
random integer 42..43
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("42") || actual.out.contains("43"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generates_55() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
random integer 55..55
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("55"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generates_0() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
random integer ..<1
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains('0'));
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
mod bool;
|
||||
mod chars;
|
||||
mod decimal;
|
||||
mod dice;
|
||||
mod integer;
|
||||
#[cfg(feature = "uuid_crate")]
|
||||
mod uuid;
|
@ -1,16 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
use uuid_crate::Uuid;
|
||||
|
||||
#[test]
|
||||
fn generates_valid_uuid4() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
random uuid
|
||||
"#
|
||||
));
|
||||
|
||||
let result = Uuid::parse_str(actual.out.as_str());
|
||||
|
||||
assert!(result.is_ok());
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
use nu_test_support::fs::Stub::EmptyFile;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn selects_a_row() {
|
||||
Playground::setup("range_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("notes.txt"), EmptyFile("tests.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| sort-by name
|
||||
| range 0..0
|
||||
| get name
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "notes.txt");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selects_some_rows() {
|
||||
Playground::setup("range_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("notes.txt"),
|
||||
EmptyFile("tests.txt"),
|
||||
EmptyFile("persons.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| get name
|
||||
| range 1..2
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
});
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn reduce_table_column() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "[{month:2,total:30}, {month:3,total:10}, {month:4,total:3}, {month:5,total:60}]"
|
||||
| from json
|
||||
| get total
|
||||
| reduce -f 20 { = $it + $( math eval `{{$acc}}^1.05` )}
|
||||
| str from -d 1
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "180.6");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "[{month:2,total:30}, {month:3,total:10}, {month:4,total:3}, {month:5,total:60}]"
|
||||
| from json
|
||||
| reduce -f 20 { = $it.total + $( math eval `{{$acc}}^1.05` )}
|
||||
| str from -d 1
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "180.6");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reduce_rows_example() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo a,b 1,2 3,4
|
||||
| split column ,
|
||||
| headers
|
||||
| reduce -f 1.6 { = $acc * $(echo $it.a | str to-int) + $(echo $it.b | str to-int) }
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "14.8");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reduce_numbered_example() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo one longest three bar
|
||||
| reduce -n { if $(echo $it.item | str length) > $(echo $acc.item | str length) {echo $it} {echo $acc}}
|
||||
| get index
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn folding_with_tables() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [10 20 30 40]
|
||||
| reduce -f [] {
|
||||
with-env [value $it] {
|
||||
echo $acc | append $(= 10 * $(= $nu.env.value | str to-int))
|
||||
}
|
||||
}
|
||||
| math sum
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "1000");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_reduce_fold_type_mismatch() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo a b c | reduce -f 0 { = $acc + $it }
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("Coercion"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_reduce_empty() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
reduce { = $acc + $it }
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("needs input"));
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn changes_the_column_name() {
|
||||
Playground::setup("rename_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_cuatro_mosqueteros.txt",
|
||||
r#"
|
||||
Andrés N. Robalino
|
||||
Jonathan Turner
|
||||
Yehuda Katz
|
||||
Jason Gedge
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_cuatro_mosqueteros.txt
|
||||
| lines
|
||||
| wrap name
|
||||
| rename mosqueteros
|
||||
| get mosqueteros
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_remaining_original_names_given_less_new_names_than_total_original_names() {
|
||||
Playground::setup("rename_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_cuatro_mosqueteros.txt",
|
||||
r#"
|
||||
Andrés N. Robalino
|
||||
Jonathan Turner
|
||||
Yehuda Katz
|
||||
Jason Gedge
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_cuatro_mosqueteros.txt
|
||||
| lines
|
||||
| wrap name
|
||||
| default hit "arepa!"
|
||||
| rename mosqueteros
|
||||
| get hit
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_no_columns_present() {
|
||||
Playground::setup("rename_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_cuatro_mosqueteros.txt",
|
||||
r#"
|
||||
Andrés N. Robalino
|
||||
Jonathan Turner
|
||||
Yehuda Katz
|
||||
Jason Gedge
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_cuatro_mosqueteros.txt
|
||||
| lines
|
||||
| rename mosqueteros
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(
|
||||
actual.err.contains("no column names available"),
|
||||
format!("actual: {:?}", actual.err)
|
||||
);
|
||||
assert!(
|
||||
actual.err.contains("can't rename"),
|
||||
format!("actual: {:?}", actual.err)
|
||||
);
|
||||
})
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
use nu_test_support::nu;
|
||||
|
||||
#[test]
|
||||
fn can_get_reverse_first() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"ls | sort-by name | reverse | first 1 | get name | str trim "
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "utf16.ini");
|
||||
}
|
@ -1,278 +0,0 @@
|
||||
use nu_test_support::fs::{files_exist_at, Stub::EmptyFile};
|
||||
use nu_test_support::nu;
|
||||
use nu_test_support::playground::Playground;
|
||||
|
||||
#[test]
|
||||
fn removes_a_file() {
|
||||
Playground::setup("rm_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("i_will_be_deleted.txt")]);
|
||||
|
||||
nu!(
|
||||
cwd: dirs.root(),
|
||||
"rm rm_test_1/i_will_be_deleted.txt"
|
||||
);
|
||||
|
||||
let path = dirs.test().join("i_will_be_deleted.txt");
|
||||
|
||||
assert!(!path.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removes_files_with_wildcard() {
|
||||
Playground::setup("rm_test_2", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("src")
|
||||
.with_files(vec![
|
||||
EmptyFile("cli.rs"),
|
||||
EmptyFile("lib.rs"),
|
||||
EmptyFile("prelude.rs"),
|
||||
])
|
||||
.within("src/parser")
|
||||
.with_files(vec![EmptyFile("parse.rs"), EmptyFile("parser.rs")])
|
||||
.within("src/parser/parse")
|
||||
.with_files(vec![EmptyFile("token_tree.rs")])
|
||||
.within("src/parser/hir")
|
||||
.with_files(vec![
|
||||
EmptyFile("baseline_parse.rs"),
|
||||
EmptyFile("baseline_parse_tokens.rs"),
|
||||
]);
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"rm "src/*/*/*.rs""#
|
||||
);
|
||||
|
||||
assert!(!files_exist_at(
|
||||
vec![
|
||||
"src/parser/parse/token_tree.rs",
|
||||
"src/parser/hir/baseline_parse.rs",
|
||||
"src/parser/hir/baseline_parse_tokens.rs"
|
||||
],
|
||||
dirs.test()
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
Playground::glob_vec(&format!("{}/src/*/*/*.rs", dirs.test().display())),
|
||||
Vec::<std::path::PathBuf>::new()
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removes_deeply_nested_directories_with_wildcard_and_recursive_flag() {
|
||||
Playground::setup("rm_test_3", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("src")
|
||||
.with_files(vec![
|
||||
EmptyFile("cli.rs"),
|
||||
EmptyFile("lib.rs"),
|
||||
EmptyFile("prelude.rs"),
|
||||
])
|
||||
.within("src/parser")
|
||||
.with_files(vec![EmptyFile("parse.rs"), EmptyFile("parser.rs")])
|
||||
.within("src/parser/parse")
|
||||
.with_files(vec![EmptyFile("token_tree.rs")])
|
||||
.within("src/parser/hir")
|
||||
.with_files(vec![
|
||||
EmptyFile("baseline_parse.rs"),
|
||||
EmptyFile("baseline_parse_tokens.rs"),
|
||||
]);
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"rm -r src/*"
|
||||
);
|
||||
|
||||
assert!(!files_exist_at(
|
||||
vec!["src/parser/parse", "src/parser/hir"],
|
||||
dirs.test()
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removes_directory_contents_without_recursive_flag_if_empty() {
|
||||
Playground::setup("rm_test_4", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.root(),
|
||||
"rm rm_test_4"
|
||||
);
|
||||
|
||||
assert!(!dirs.test().exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removes_directory_contents_with_recursive_flag() {
|
||||
Playground::setup("rm_test_5", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("yehuda.txt"),
|
||||
EmptyFile("jonathan.txt"),
|
||||
EmptyFile("andres.txt"),
|
||||
]);
|
||||
|
||||
nu!(
|
||||
cwd: dirs.root(),
|
||||
"rm rm_test_5 --recursive"
|
||||
);
|
||||
|
||||
assert!(!dirs.test().exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_attempting_to_delete_a_directory_with_content_without_recursive_flag() {
|
||||
Playground::setup("rm_test_6", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("some_empty_file.txt")]);
|
||||
let actual = nu!(
|
||||
cwd: dirs.root(),
|
||||
"rm rm_test_6"
|
||||
);
|
||||
|
||||
assert!(dirs.test().exists());
|
||||
assert!(actual.err.contains("cannot remove non-empty directory"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_attempting_to_delete_single_dot_as_argument() {
|
||||
Playground::setup("rm_test_7", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.root(),
|
||||
"rm ."
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("cannot remove any parent directory"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_attempting_to_delete_two_dot_as_argument() {
|
||||
Playground::setup("rm_test_8", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.root(),
|
||||
"rm .."
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("cannot remove any parent directory"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removes_multiple_directories() {
|
||||
Playground::setup("rm_test_9", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("src")
|
||||
.with_files(vec![EmptyFile("a.rs"), EmptyFile("b.rs")])
|
||||
.within("src/cli")
|
||||
.with_files(vec![EmptyFile("c.rs"), EmptyFile("d.rs")])
|
||||
.within("test")
|
||||
.with_files(vec![EmptyFile("a_test.rs"), EmptyFile("b_test.rs")]);
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"rm src test --recursive"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Playground::glob_vec(&format!("{}/*", dirs.test().display())),
|
||||
Vec::<std::path::PathBuf>::new()
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removes_multiple_files() {
|
||||
Playground::setup("rm_test_10", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("yehuda.txt"),
|
||||
EmptyFile("jonathan.txt"),
|
||||
EmptyFile("andres.txt"),
|
||||
]);
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"rm yehuda.txt jonathan.txt andres.txt"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Playground::glob_vec(&format!("{}/*", dirs.test().display())),
|
||||
Vec::<std::path::PathBuf>::new()
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removes_multiple_files_with_asterisks() {
|
||||
Playground::setup("rm_test_11", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("yehuda.txt"),
|
||||
EmptyFile("jonathan.txt"),
|
||||
EmptyFile("andres.toml"),
|
||||
]);
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"rm *.txt *.toml"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Playground::glob_vec(&format!("{}/*", dirs.test().display())),
|
||||
Vec::<std::path::PathBuf>::new()
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn allows_doubly_specified_file() {
|
||||
Playground::setup("rm_test_12", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("yehuda.txt"), EmptyFile("jonathan.toml")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"rm *.txt yehuda* *.toml"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Playground::glob_vec(&format!("{}/*", dirs.test().display())),
|
||||
Vec::<std::path::PathBuf>::new()
|
||||
);
|
||||
assert!(!actual.out.contains("error"))
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_files_from_two_parents_up_using_multiple_dots_and_glob() {
|
||||
Playground::setup("rm_test_13", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("yehuda.txt"),
|
||||
EmptyFile("jonathan.txt"),
|
||||
EmptyFile("kevin.txt"),
|
||||
]);
|
||||
|
||||
sandbox.within("foo").mkdir("bar");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test().join("foo/bar"),
|
||||
"rm .../*.txt"
|
||||
);
|
||||
|
||||
assert!(!files_exist_at(
|
||||
vec!["yehuda.txt", "jonathan.txt", "kevin.txt"],
|
||||
dirs.test()
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_errors_if_attempting_to_delete_non_existent_file_with_f_flag() {
|
||||
Playground::setup("rm_test_14", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.root(),
|
||||
"rm -f non_existent_file.txt"
|
||||
);
|
||||
|
||||
assert!(!actual.err.contains("no valid path"));
|
||||
})
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
use nu_test_support::fs::{file_contents, Stub::FileWithContent};
|
||||
use nu_test_support::nu;
|
||||
use nu_test_support::playground::Playground;
|
||||
|
||||
#[test]
|
||||
fn figures_out_intelligently_where_to_write_out_with_metadata() {
|
||||
Playground::setup("save_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"cargo_sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "nu"
|
||||
version = "0.1.1"
|
||||
authors = ["Yehuda Katz <wycats@gmail.com>"]
|
||||
description = "A shell for the GitHub era"
|
||||
license = "ISC"
|
||||
edition = "2018"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let subject_file = dirs.test().join("cargo_sample.toml");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.root(),
|
||||
"open save_test_1/cargo_sample.toml | save"
|
||||
);
|
||||
|
||||
let actual = file_contents(&subject_file);
|
||||
assert!(actual.contains("0.1.1"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn writes_out_csv() {
|
||||
Playground::setup("save_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![]);
|
||||
|
||||
let expected_file = dirs.test().join("cargo_sample.csv");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.root(),
|
||||
r#"echo [[name, version, description, license, edition]; [nu, "0.14", "A new type of shell", "MIT", "2018"]] | save save_test_2/cargo_sample.csv"#,
|
||||
);
|
||||
|
||||
let actual = file_contents(expected_file);
|
||||
println!("{}", actual);
|
||||
assert!(actual.contains("nu,0.14,A new type of shell,MIT,2018"));
|
||||
})
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn regular_columns() {
|
||||
Playground::setup("select_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at,type
|
||||
Andrés,Robalino,10/11/2013,A
|
||||
Jonathan,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
| select rusty_at last_name
|
||||
| nth 0
|
||||
| get last_name
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "Robalino");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn complex_nested_columns() {
|
||||
Playground::setup("select_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.json",
|
||||
r#"
|
||||
{
|
||||
"nu": {
|
||||
"committers": [
|
||||
{"name": "Andrés N. Robalino"},
|
||||
{"name": "Jonathan Turner"},
|
||||
{"name": "Yehuda Katz"}
|
||||
],
|
||||
"releases": [
|
||||
{"version": "0.2"}
|
||||
{"version": "0.8"},
|
||||
{"version": "0.9999999"}
|
||||
],
|
||||
"0xATYKARNU": [
|
||||
["Th", "e", " "],
|
||||
["BIG", " ", "UnO"],
|
||||
["punto", "cero"]
|
||||
]
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.json
|
||||
| select nu."0xATYKARNU" nu.committers.name nu.releases.version
|
||||
| where "nu.releases.version" > "0.8"
|
||||
| get "nu.releases.version"
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "0.9999999");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn allows_if_given_unknown_column_name_is_missing() {
|
||||
Playground::setup("select_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at,type
|
||||
Andrés,Robalino,10/11/2013,A
|
||||
Jonathan,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
| select rrusty_at first_name
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn column_names_with_spaces() {
|
||||
Playground::setup("select_test_4", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"test_data.csv",
|
||||
r#"
|
||||
first name,last name
|
||||
Jonathan,Turner
|
||||
Jonathan,Arns
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open test_data.csv
|
||||
| select "last name"
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
let expected_output = r#"[{"last name":"Turner"},{"last name":"Arns"}]"#;
|
||||
assert_eq!(actual.out, expected_output);
|
||||
})
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn semicolon_allows_lhs_to_complete() {
|
||||
Playground::setup("create_test_1", |dirs, _sandbox| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"touch i_will_be_created_semi.txt; echo done"
|
||||
);
|
||||
|
||||
let path = dirs.test().join("i_will_be_created_semi.txt");
|
||||
|
||||
assert!(path.exists());
|
||||
assert_eq!(actual.out, "done");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn semicolon_lhs_error_stops_processing() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
where 1 1; echo done
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(!actual.out.contains("done"));
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
mod until;
|
||||
mod while_;
|
@ -1,50 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn condition_is_met() {
|
||||
Playground::setup("skip_until_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"caballeros.txt",
|
||||
r#"
|
||||
CHICKEN SUMMARY report date: April 29th, 2020
|
||||
--------------------------------------------------------------------
|
||||
Chicken Collection,29/04/2020,30/04/2020,31/04/2020,
|
||||
Yellow Chickens,,,
|
||||
Andrés,0,0,1
|
||||
Jonathan,0,0,1
|
||||
Jason,0,0,1
|
||||
Yehuda,0,0,1
|
||||
Blue Chickens,,,
|
||||
Andrés,0,0,1
|
||||
Jonathan,0,0,1
|
||||
Jason,0,0,1
|
||||
Yehuda,0,0,2
|
||||
Red Chickens,,,
|
||||
Andrés,0,0,1
|
||||
Jonathan,0,0,1
|
||||
Jason,0,0,1
|
||||
Yehuda,0,0,3
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open --raw caballeros.txt
|
||||
| lines
|
||||
| skip 2
|
||||
| split column ','
|
||||
| headers
|
||||
| skip until "Chicken Collection" == "Red Chickens"
|
||||
| skip 1
|
||||
| str to-int "31/04/2020"
|
||||
| get "31/04/2020"
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "6");
|
||||
})
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn condition_is_met() {
|
||||
Playground::setup("skip_while_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"caballeros.txt",
|
||||
r#"
|
||||
CHICKEN SUMMARY report date: April 29th, 2020
|
||||
--------------------------------------------------------------------
|
||||
Chicken Collection,29/04/2020,30/04/2020,31/04/2020,
|
||||
Yellow Chickens,,,
|
||||
Andrés,0,0,1
|
||||
Jonathan,0,0,1
|
||||
Jason,0,0,1
|
||||
Yehuda,0,0,1
|
||||
Blue Chickens,,,
|
||||
Andrés,0,0,1
|
||||
Jonathan,0,0,1
|
||||
Jason,0,0,1
|
||||
Yehuda,0,0,2
|
||||
Red Chickens,,,
|
||||
Andrés,0,0,1
|
||||
Jonathan,0,0,1
|
||||
Jason,0,0,1
|
||||
Yehuda,0,0,3
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open --raw caballeros.txt
|
||||
| lines
|
||||
| skip 2
|
||||
| split column ','
|
||||
| headers
|
||||
| skip while "Chicken Collection" != "Red Chickens"
|
||||
| skip 1
|
||||
| str to-int "31/04/2020"
|
||||
| get "31/04/2020"
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "6");
|
||||
})
|
||||
}
|
@ -1,146 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn by_column() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml --raw
|
||||
| lines
|
||||
| skip 1
|
||||
| first 4
|
||||
| split column "="
|
||||
| sort-by Column1
|
||||
| skip 1
|
||||
| first 1
|
||||
| get Column1
|
||||
| str trim
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "description");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn by_invalid_column() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml --raw
|
||||
| lines
|
||||
| skip 1
|
||||
| first 4
|
||||
| split column "="
|
||||
| sort-by ColumnThatDoesNotExist
|
||||
| skip 1
|
||||
| first 1
|
||||
| get Column1
|
||||
| str trim
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("Can not find column to sort by"));
|
||||
assert!(actual.err.contains("invalid column"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn by_invalid_types() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml --raw
|
||||
| echo [1 "foo"]
|
||||
| sort-by
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("Not all values can be compared"));
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("Unable to sort values, as \"integer\" cannot compare against \"string\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sort_primitive_values() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml --raw
|
||||
| lines
|
||||
| skip 1
|
||||
| first 6
|
||||
| sort-by
|
||||
| first 1
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "authors = [\"The Nu Project Contributors\"]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_sort_by_name_sensitive() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample-ls-output.json
|
||||
| sort-by name
|
||||
| select name
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
let json_output = r#"[{"name":"B.txt"},{"name":"C"},{"name":"a.txt"}]"#;
|
||||
|
||||
assert_eq!(actual.out, json_output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_sort_by_name_insensitive() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample-ls-output.json
|
||||
| sort-by -i name
|
||||
| select name
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
let json_output = r#"[{"name":"a.txt"},{"name":"B.txt"},{"name":"C"}]"#;
|
||||
|
||||
assert_eq!(actual.out, json_output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_sort_by_type_name_sensitive() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample-ls-output.json
|
||||
| sort-by type name
|
||||
| select name type
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
let json_output = r#"[{"name":"C","type":"Dir"},{"name":"B.txt","type":"File"},{"name":"a.txt","type":"File"}]"#;
|
||||
|
||||
assert_eq!(actual.out, json_output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_sort_by_type_name_insensitive() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample-ls-output.json
|
||||
| sort-by -i type name
|
||||
| select name type
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
let json_output = r#"[{"name":"C","type":"Dir"},{"name":"a.txt","type":"File"},{"name":"B.txt","type":"File"}]"#;
|
||||
|
||||
assert_eq!(actual.out, json_output);
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
use nu_test_support::fs::Stub::{EmptyFile, FileWithContentToBeTrimmed};
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn splits() {
|
||||
Playground::setup("split_by_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at,type
|
||||
Andrés,Robalino,10/11/2013,A
|
||||
Jonathan,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
| group-by rusty_at
|
||||
| split-by type
|
||||
| get A."10/11/2013"
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_no_table_given_as_input() {
|
||||
Playground::setup("split_by_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("los.txt"),
|
||||
EmptyFile("tres.txt"),
|
||||
EmptyFile("amigos.txt"),
|
||||
EmptyFile("arepas.clu"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| get name
|
||||
| split-by type
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("Expected table from pipeline"));
|
||||
})
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn to_column() {
|
||||
Playground::setup("split_column_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"sample.txt",
|
||||
r#"
|
||||
importer,shipper,tariff_item,name,origin
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.txt
|
||||
| lines
|
||||
| str trim
|
||||
| split column ","
|
||||
| get Column2
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("shipper"));
|
||||
})
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn to_row() {
|
||||
Playground::setup("split_row_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"sample.txt",
|
||||
r#"
|
||||
importer,shipper,tariff_item,name,origin
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.txt
|
||||
| lines
|
||||
| str trim
|
||||
| split row ","
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains('5'));
|
||||
})
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn test_1() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo 1..5 | str from | str collect
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "12345");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_2() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [a b c d] | str collect "<sep>"
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "a<sep>b<sep>c<sep>d");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn construct_a_path() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [sample txt] | str collect "."
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "sample.txt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sum_one_to_four() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo 1..4 | str from | str collect "+" | math eval
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert!(actual.out.contains("10.0"));
|
||||
}
|
@ -1,431 +0,0 @@
|
||||
mod collect;
|
||||
|
||||
use nu_test_support::fs::Stub::FileWithContent;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn trims() {
|
||||
Playground::setup("str_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[dependency]
|
||||
name = "nu "
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open sample.toml | str trim dependency.name | get dependency.name"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "nu");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_trim_multiple_chars() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo 'does it work now?!' | str trim -c '?!'
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("char"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn capitalizes() {
|
||||
Playground::setup("str_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[dependency]
|
||||
name = "nu"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open sample.toml | str capitalize dependency.name | get dependency.name"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "Nu");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn downcases() {
|
||||
Playground::setup("str_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[dependency]
|
||||
name = "LIGHT"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open sample.toml | str downcase dependency.name | get dependency.name"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "light");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn upcases() {
|
||||
Playground::setup("str_test_4", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "nushell"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open sample.toml | str upcase package.name | get package.name"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "NUSHELL");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn camelcases() {
|
||||
Playground::setup("str_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[dependency]
|
||||
name = "THIS_IS_A_TEST"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open sample.toml | str camel-case dependency.name | get dependency.name"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "thisIsATest");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn converts_to_int() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo '{number_as_string: "1"}'
|
||||
| from json
|
||||
| str to-int number_as_string
|
||||
| rename number
|
||||
| where number == 1
|
||||
| get number
|
||||
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn converts_to_decimal() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo "3.1, 0.0415"
|
||||
| split row ","
|
||||
| str to-decimal
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3.1415");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sets() {
|
||||
Playground::setup("str_test_5", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "nushell"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| str set wykittenshell package.name
|
||||
| get package.name
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "wykittenshell");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_and_replaces() {
|
||||
Playground::setup("str_test_6", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[fortune.teller]
|
||||
phone = "1-800-KATZ"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| str find-replace KATZ "5289" fortune.teller.phone
|
||||
| get fortune.teller.phone
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1-800-5289");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_and_replaces_without_passing_field() {
|
||||
Playground::setup("str_test_7", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[fortune.teller]
|
||||
phone = "1-800-KATZ"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| get fortune.teller.phone
|
||||
| str find-replace KATZ "5289"
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1-800-5289");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn substrings_the_input() {
|
||||
Playground::setup("str_test_8", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[fortune.teller]
|
||||
phone = "1-800-ROBALINO"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| str substring 6,14 fortune.teller.phone
|
||||
| get fortune.teller.phone
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "ROBALINO");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn substring_errors_if_start_index_is_greater_than_end_index() {
|
||||
Playground::setup("str_test_9", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[fortune.teller]
|
||||
phone = "1-800-ROBALINO"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| str substring 6,5 fortune.teller.phone
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("End must be greater than or equal to Start"))
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn substrings_the_input_and_returns_the_string_if_end_index_exceeds_length() {
|
||||
Playground::setup("str_test_10", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "nu-arepas"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| str substring 0,999 package.name
|
||||
| get package.name
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "nu-arepas");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn substrings_the_input_and_returns_blank_if_start_index_exceeds_length() {
|
||||
Playground::setup("str_test_11", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "nu-arepas"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| str substring 50,999 package.name
|
||||
| get package.name
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn substrings_the_input_and_treats_start_index_as_zero_if_blank_start_index_given() {
|
||||
Playground::setup("str_test_12", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "nu-arepas"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| str substring ,2 package.name
|
||||
| get package.name
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "nu");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn substrings_the_input_and_treats_end_index_as_length_if_blank_end_index_given() {
|
||||
Playground::setup("str_test_13", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "nu-arepas"
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| str substring 3, package.name
|
||||
| get package.name
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "arepas");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_decimal_correct_trailing_zeros() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
= 1.23000 | str from -d 3
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("1.230"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_int_decimal_correct_trailing_zeros() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
= 1.00000 | str from -d 3
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("1.000"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_int_decimal_trim_trailing_zeros() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
= 1.00000 | str from | format "{$it} flat"
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("1 flat")); // "1" would match "1.0"
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_table() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo '[{"name": "foo", "weight": 32.377}, {"name": "bar", "weight": 15.2}]'
|
||||
| from json
|
||||
| str from weight -d 2
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("32.38"));
|
||||
assert!(actual.out.contains("15.20"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn str_reverse() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "nushell" | str reverse
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("llehsun"));
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
use nu_test_support::nu;
|
||||
use nu_test_support::playground::Playground;
|
||||
|
||||
#[test]
|
||||
fn creates_a_file_when_it_doesnt_exist() {
|
||||
Playground::setup("create_test_1", |dirs, _sandbox| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"touch i_will_be_created.txt"
|
||||
);
|
||||
|
||||
let path = dirs.test().join("i_will_be_created.txt");
|
||||
assert!(path.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn creates_two_files() {
|
||||
Playground::setup("create_test_2", |dirs, _sandbox| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"touch a b"
|
||||
);
|
||||
|
||||
let path = dirs.test().join("a");
|
||||
assert!(path.exists());
|
||||
|
||||
let path2 = dirs.test().join("b");
|
||||
assert!(path2.exists());
|
||||
})
|
||||
}
|
@ -1,211 +0,0 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn removes_duplicate_rows() {
|
||||
Playground::setup("uniq_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at,type
|
||||
Andrés,Robalino,10/11/2013,A
|
||||
Jonathan,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
Jonathan,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
| uniq
|
||||
| count
|
||||
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uniq_values() {
|
||||
Playground::setup("uniq_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at,type
|
||||
Andrés,Robalino,10/11/2013,A
|
||||
Jonathan,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
Jonathan,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
| select type
|
||||
| uniq
|
||||
| count
|
||||
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_json_structures() {
|
||||
Playground::setup("uniq_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"nested_json_structures.json",
|
||||
r#"
|
||||
[
|
||||
{
|
||||
"name": "this is duplicated",
|
||||
"nesting": [ { "a": "a", "b": "b" },
|
||||
{ "c": "c", "d": "d" }
|
||||
],
|
||||
"can_be_ordered_differently": {
|
||||
"array": [1, 2, 3, 4, 5],
|
||||
"something": { "else": "works" }
|
||||
}
|
||||
},
|
||||
{
|
||||
"can_be_ordered_differently": {
|
||||
"something": { "else": "works" },
|
||||
"array": [1, 2, 3, 4, 5]
|
||||
},
|
||||
"nesting": [ { "b": "b", "a": "a" },
|
||||
{ "d": "d", "c": "c" }
|
||||
],
|
||||
"name": "this is duplicated"
|
||||
},
|
||||
{
|
||||
"name": "this is unique",
|
||||
"nesting": [ { "a": "b", "b": "a" },
|
||||
{ "c": "d", "d": "c" }
|
||||
],
|
||||
"can_be_ordered_differently": {
|
||||
"array": [],
|
||||
"something": { "else": "does not work" }
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "this is unique",
|
||||
"nesting": [ { "a": "a", "b": "b", "c": "c" },
|
||||
{ "d": "d", "e": "e", "f": "f" }
|
||||
],
|
||||
"can_be_ordered_differently": {
|
||||
"array": [],
|
||||
"something": { "else": "works" }
|
||||
}
|
||||
}
|
||||
]
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open nested_json_structures.json
|
||||
| uniq
|
||||
| count
|
||||
|
||||
"#
|
||||
));
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uniq_when_keys_out_of_order() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo '[{"a": "a", "b": [1,2,3]},{"b": [1,2,3], "a": "a"}]'
|
||||
| from json
|
||||
| uniq
|
||||
| count
|
||||
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uniq_counting() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo '["A", "B", "A"]'
|
||||
| from json
|
||||
| wrap item
|
||||
| uniq --count
|
||||
| where item == A
|
||||
| get count
|
||||
"#
|
||||
));
|
||||
assert_eq!(actual.out, "2");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo '["A", "B", "A"]'
|
||||
| from json
|
||||
| wrap item
|
||||
| uniq --count
|
||||
| where item == B
|
||||
| get count
|
||||
"#
|
||||
));
|
||||
assert_eq!(actual.out, "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uniq_simple_vals_ints() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [1 2 3 4 1 5]
|
||||
| uniq
|
||||
"#
|
||||
));
|
||||
let expected = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [1 2 3 4 5]
|
||||
"#
|
||||
));
|
||||
print!("{}", actual.out);
|
||||
print!("{}", expected.out);
|
||||
assert_eq!(actual.out, expected.out);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uniq_simple_vals_strs() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [A B C A]
|
||||
| uniq
|
||||
"#
|
||||
));
|
||||
let expected = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [A B C]
|
||||
"#
|
||||
));
|
||||
print!("{}", actual.out);
|
||||
print!("{}", expected.out);
|
||||
assert_eq!(actual.out, expected.out);
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn sets_the_column() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml
|
||||
| update dev-dependencies.pretty_assertions "0.7.0"
|
||||
| get dev-dependencies.pretty_assertions
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "0.7.0");
|
||||
}
|
||||
|
||||
#[cfg(features = "inc")]
|
||||
#[test]
|
||||
fn sets_the_column_from_a_block_run_output() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml
|
||||
| update dev-dependencies.pretty_assertions { open cargo_sample.toml | get dev-dependencies.pretty_assertions | inc --minor }
|
||||
| get dev-dependencies.pretty_assertions
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "0.7.0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sets_the_column_from_a_block_full_stream_output() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
wrap content
|
||||
| update content { open --raw cargo_sample.toml | lines | first 5 }
|
||||
| get content.1
|
||||
| str contains "nu"
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sets_the_column_from_an_invocation() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
wrap content
|
||||
| update content $(open --raw cargo_sample.toml | lines | first 5)
|
||||
| get content.1
|
||||
| str contains "nu"
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
}
|
@ -1,166 +0,0 @@
|
||||
use nu_test_support::nu;
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
use nu_test_support::pipeline;
|
||||
|
||||
#[test]
|
||||
fn filters_by_unit_size_comparison() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"ls | where size > 1kb | sort-by size | get name | first 1 | str trim"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "cargo_sample.toml");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filters_with_nothing_comparison() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
r#"echo '[{"foo": 3}, {"foo": null}, {"foo": 4}]' | from json | get foo | compact | where $it > 1 | math sum"#
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "7");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn where_in_table() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
r#"echo '[{"name": "foo", "size": 3}, {"name": "foo", "size": 2}, {"name": "bar", "size": 4}]' | from json | where name in ["foo"] | get size | math sum"#
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn where_not_in_table() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
r#"echo '[{"name": "foo", "size": 3}, {"name": "foo", "size": 2}, {"name": "bar", "size": 4}]' | from json | where name not-in ["foo"] | get size | math sum"#
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
}
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
#[test]
|
||||
fn explicit_block_condition() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample.db
|
||||
| where table_name == ints
|
||||
| get table_values
|
||||
| first 4
|
||||
| where {= $it.z > 4200}
|
||||
| get z
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "4253");
|
||||
}
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
#[test]
|
||||
fn binary_operator_comparisons() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample.db
|
||||
| where table_name == ints
|
||||
| get table_values
|
||||
| first 4
|
||||
| where z > 4200
|
||||
| get z
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "4253");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample.db
|
||||
| where table_name == ints
|
||||
| get table_values
|
||||
| first 4
|
||||
| where z >= 4253
|
||||
| get z
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "4253");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample.db
|
||||
| where table_name == ints
|
||||
| get table_values
|
||||
| first 4
|
||||
| where z < 10
|
||||
| get z
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample.db
|
||||
| where table_name == ints
|
||||
| get table_values
|
||||
| first 4
|
||||
| where z <= 1
|
||||
| get z
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample.db
|
||||
| where table_name == ints
|
||||
| get table_values
|
||||
| where z != 1
|
||||
| first 1
|
||||
| get z
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "42");
|
||||
}
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
#[test]
|
||||
fn contains_operator() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample.db
|
||||
| where table_name == strings
|
||||
| get table_values
|
||||
| where x =~ ell
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample.db
|
||||
| where table_name == strings
|
||||
| get table_values
|
||||
| where x !~ ell
|
||||
| count
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
use nu_test_support::nu;
|
||||
|
||||
#[test]
|
||||
fn which_ls() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
"which ls | get path | str trim"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "Nushell built-in command");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn which_alias_ls() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
"alias ls = ls -a; which ls | get path | str trim"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "Nushell alias: ls -a");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn which_def_ls() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
"def ls [] {echo def}; which ls | get path | str trim"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "Nushell custom command");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn correct_precedence_alias_def_custom() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
"def ls [] {echo def}; alias ls = echo alias; which ls | get path | str trim"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "Nushell alias: echo alias");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiple_reports_for_alias_def_custom() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
"def ls [] {echo def}; alias ls = echo alias; which -a ls | count"
|
||||
);
|
||||
|
||||
let count: i32 = actual.out.parse().unwrap();
|
||||
assert!(count >= 3);
|
||||
}
|
||||
|
||||
// `get_aliases_with_name` and `get_custom_commands_with_name` don't return the correct count of
|
||||
// values
|
||||
// I suspect this is due to the ScopeFrame getting discarded at '}' and the command is then
|
||||
// executed in the parent scope
|
||||
// See: parse_definition, line 2187 for reference.
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn multiple_reports_of_multiple_alias() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
"alias xaz = echo alias1; def helper [] {alias xaz = echo alias2; which -a xaz}; helper | count"
|
||||
);
|
||||
|
||||
let count: i32 = actual.out.parse().unwrap();
|
||||
assert!(count == 2);
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn multiple_reports_of_multiple_defs() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
"def xaz [] {echo def1}; def helper [] { def xaz [] { echo def2 }; which -a xaz }; helper | count"
|
||||
);
|
||||
|
||||
let count: i32 = actual.out.parse().unwrap();
|
||||
assert!(count == 2);
|
||||
}
|
||||
|
||||
//Fails due to ParserScope::add_definition
|
||||
// frame.custom_commands.insert(name.clone(), block.clone());
|
||||
// frame.commands.insert(name, whole_stream_command(block));
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn def_only_seen_once() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
"def xaz [] {echo def1}; which -a xaz | count"
|
||||
);
|
||||
//count is 2. One custom_command (def) one built in ("wrongly" added)
|
||||
let count: i32 = actual.out.parse().unwrap();
|
||||
assert!(count == 1);
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
use nu_test_support::nu;
|
||||
|
||||
#[test]
|
||||
fn with_env_extends_environment() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"with-env [FOO BARRRR] {echo $nu.env} | get FOO"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "BARRRR");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_env_shorthand() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"FOO=BARRRR echo $nu.env | get FOO"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "BARRRR");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shorthand_doesnt_reorder_arguments() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"FOO=BARRRR nu --testbin cococo first second"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "first second");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_env_shorthand_trims_quotes() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"FOO='BARRRR' echo $nu.env | get FOO"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "BARRRR");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_env_and_shorthand_same_result() {
|
||||
let actual_shorthand = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"FOO='BARRRR' echo $nu.env | get FOO"
|
||||
);
|
||||
|
||||
let actual_normal = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"with-env [FOO BARRRR] {echo $nu.env} | get FOO"
|
||||
);
|
||||
|
||||
assert_eq!(actual_shorthand.out, actual_normal.out);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_env_shorthand_nested_quotes() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"FOO='-arg \"hello world\"' echo $nu.env | get FOO"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "-arg \"hello world\"");
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
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
|
||||
Jonathan,Turner
|
||||
Yehuda,Katz
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.txt
|
||||
| from csv
|
||||
| wrap caballeros
|
||||
| get caballeros
|
||||
| nth 0
|
||||
| get last_name
|
||||
"#
|
||||
));
|
||||
|
||||
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
|
||||
Jonathan,Turner
|
||||
Yehuda,Katz
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.txt
|
||||
| from csv
|
||||
| get last_name
|
||||
| wrap caballero
|
||||
| nth 2
|
||||
| get caballero
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "Katz");
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user