This commit is the continuing phase of extracting functionality to subcrates. We extract test helpers and begin to change Nu shell's test organization along with it.

This commit is contained in:
Andrés N. Robalino
2019-12-15 11:15:06 -05:00
parent 4b9ef5a9d0
commit 4034129dba
64 changed files with 2184 additions and 2340 deletions

133
tests/plugins/core_inc.rs Normal file
View File

@ -0,0 +1,133 @@
use test_support::fs::Stub::FileWithContent;
use test_support::playground::Playground;
use test_support::{nu, nu_error};
#[test]
fn can_only_apply_one() {
let actual = nu_error!(
cwd: "tests/fixtures/formats",
"open cargo_sample.toml | first 1 | inc package.version --major --minor"
);
assert!(actual.contains("Usage: inc field [--major|--minor|--patch]"));
}
#[test]
fn by_one_with_field_passed() {
Playground::setup("plugin_inc_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
edition = "2018"
"#,
)]);
let actual = nu!(
cwd: dirs.test(),
"open sample.toml | inc package.edition | get package.edition | echo $it"
);
assert_eq!(actual, "2019");
})
}
#[test]
fn by_one_with_no_field_passed() {
Playground::setup("plugin_inc_test_2", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
contributors = "2"
"#,
)]);
let actual = nu!(
cwd: dirs.test(),
"open sample.toml | get package.contributors | inc | echo $it"
);
assert_eq!(actual, "3");
})
}
#[test]
fn semversion_major_inc() {
Playground::setup("plugin_inc_test_3", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
version = "0.1.3"
"#,
)]);
let actual = nu!(
cwd: dirs.test(),
"open sample.toml | inc package.version --major | get package.version | echo $it"
);
assert_eq!(actual, "1.0.0");
})
}
#[test]
fn semversion_minor_inc() {
Playground::setup("plugin_inc_test_4", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
version = "0.1.3"
"#,
)]);
let actual = nu!(
cwd: dirs.test(),
"open sample.toml | inc package.version --minor | get package.version | echo $it"
);
assert_eq!(actual, "0.2.0");
})
}
#[test]
fn semversion_patch_inc() {
Playground::setup("plugin_inc_test_5", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
version = "0.1.3"
"#,
)]);
let actual = nu!(
cwd: dirs.test(),
"open sample.toml | inc package.version --patch | get package.version | echo $it"
);
assert_eq!(actual, "0.1.4");
})
}
#[test]
fn semversion_without_passing_field() {
Playground::setup("plugin_inc_test_6", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
version = "0.1.3"
"#,
)]);
let actual = nu!(
cwd: dirs.test(),
"open sample.toml | get package.version | inc --patch | echo $it"
);
assert_eq!(actual, "0.1.4");
})
}

166
tests/plugins/core_str.rs Normal file
View File

@ -0,0 +1,166 @@
use test_support::fs::Stub::FileWithContent;
use test_support::playground::Playground;
use test_support::{nu, nu_error, pipeline};
#[test]
fn can_only_apply_one() {
let actual = nu_error!(
cwd: "tests/fixtures/formats",
"open caco3_plastics.csv | first 1 | str origin --downcase --upcase"
);
assert!(actual.contains(r#"--downcase|--upcase|--to-int|--substring "start,end"|--replace|--find-replace [pattern replacement]]"#));
}
#[test]
fn acts_without_passing_field() {
Playground::setup("plugin_str_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
"sample.yml",
r#"
environment:
global:
PROJECT_NAME: nushell
"#,
)]);
let actual = nu!(
cwd: dirs.test(),
"open sample.yml | get environment.global.PROJECT_NAME | str --upcase | echo $it"
);
assert_eq!(actual, "NUSHELL");
})
}
#[test]
fn downcases() {
Playground::setup("plugin_str_test_2", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
"sample.toml",
r#"
[dependency]
name = "LIGHT"
"#,
)]);
let actual = nu!(
cwd: dirs.test(),
"open sample.toml | str dependency.name --downcase | get dependency.name | echo $it"
);
assert_eq!(actual, "light");
})
}
#[test]
fn upcases() {
Playground::setup("plugin_str_test_3", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
name = "nushell"
"#,
)]);
let actual = nu!(
cwd: dirs.test(),
"open sample.toml | str package.name --upcase | get package.name | echo $it"
);
assert_eq!(actual, "NUSHELL");
})
}
#[test]
fn converts_to_int() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
open caco3_plastics.csv
| first 1
| str tariff_item --to-int
| where tariff_item == 2509000000
| get tariff_item
| echo $it
"#
));
assert_eq!(actual, "2509000000");
}
#[test]
fn replaces() {
Playground::setup("plugin_str_test_4", |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 package.name --replace wykittenshell
| get package.name
| echo $it
"#
));
assert_eq!(actual, "wykittenshell");
})
}
#[test]
fn find_and_replaces() {
Playground::setup("plugin_str_test_5", |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 fortune.teller.phone --find-replace [KATZ "5289"]
| get fortune.teller.phone
| echo $it
"#
));
assert_eq!(actual, "1-800-5289");
})
}
#[test]
fn find_and_replaces_without_passing_field() {
Playground::setup("plugin_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
| get fortune.teller.phone
| str --find-replace [KATZ "5289"]
| echo $it
"#
));
assert_eq!(actual, "1-800-5289");
})
}

2
tests/plugins/mod.rs Normal file
View File

@ -0,0 +1,2 @@
mod core_inc;
mod core_str;