nushell/tests/filter_str_tests.rs

87 lines
2.1 KiB
Rust
Raw Normal View History

2019-08-10 11:11:38 +02:00
mod helpers;
2019-08-10 11:12:48 +02:00
use h::{in_directory as cwd, Playground, Stub::*};
use helpers as h;
2019-08-10 11:11:38 +02:00
#[test]
2019-08-10 11:12:48 +02:00
fn can_only_apply_one() {
nu_error!(
2019-08-10 11:11:38 +02:00
output,
cwd("tests/fixtures/formats"),
2019-08-10 11:12:48 +02:00
"open caco3_plastics.csv | first 1 | str origin --downcase --upcase"
2019-08-10 11:11:38 +02:00
);
2019-08-10 11:12:48 +02:00
assert!(output.contains("Usage: str field [--downcase|--upcase|--to-int]"));
2019-08-10 11:11:38 +02:00
}
#[test]
2019-08-10 11:12:48 +02:00
fn acts_without_passing_field() {
Playground::setup_for("plugin_str_test_without_passing_field")
.with_files(vec![FileWithContent(
"sample.yml",
r#"
environment:
global:
PROJECT_NAME: nushell
"#,
)]);
nu!(
2019-08-10 11:11:38 +02:00
output,
2019-08-10 11:12:48 +02:00
cwd("tests/fixtures/nuplayground/plugin_str_test_without_passing_field"),
"open sample.yml | get environment.global.PROJECT_NAME | str --upcase | echo $it"
2019-08-10 11:11:38 +02:00
);
2019-08-10 11:12:48 +02:00
assert_eq!(output, "NUSHELL");
2019-08-10 11:11:38 +02:00
}
#[test]
fn downcases() {
2019-08-10 11:12:48 +02:00
Playground::setup_for("plugin_str_test_downcases")
.with_files(vec![FileWithContent(
"sample.toml",
r#"
[dependency]
name = "LIGHT"
"#,
)]);
2019-08-10 11:11:38 +02:00
nu!(
output,
2019-08-10 11:12:48 +02:00
cwd("tests/fixtures/nuplayground/plugin_str_test_downcases"),
"open sample.toml | str dependency.name --downcase | get dependency.name | echo $it"
2019-08-10 11:11:38 +02:00
);
2019-08-10 11:12:48 +02:00
assert_eq!(output, "light");
2019-08-10 11:11:38 +02:00
}
#[test]
fn upcases() {
2019-08-10 11:12:48 +02:00
Playground::setup_for("plugin_str_test_upcases")
.with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
name = "nushell"
"#,
)]);
2019-08-10 11:11:38 +02:00
nu!(
output,
2019-08-10 11:12:48 +02:00
cwd("tests/fixtures/nuplayground/plugin_str_test_upcases"),
"open sample.toml | str package.name --upcase | get package.name | echo $it"
2019-08-10 11:11:38 +02:00
);
assert_eq!(output, "NUSHELL");
}
#[test]
fn converts_to_int() {
nu!(
output,
cwd("tests/fixtures/formats"),
2019-08-10 11:12:48 +02:00
"open caco3_plastics.csv | first 1 | str tariff_item --to-int | where tariff_item == 2509000000 | get tariff_item | echo $it"
2019-08-10 11:11:38 +02:00
);
assert_eq!(output, "2509000000");
}