Clean up.

This commit is contained in:
Andrés N. Robalino 2019-08-10 04:12:48 -05:00
parent 5372463b37
commit e744237451
3 changed files with 122 additions and 84 deletions

View File

@ -79,10 +79,7 @@ impl Str {
}
impl Str {
fn strutils(
&self,
value: Tagged<Value>,
) -> Result<Tagged<Value>, ShellError> {
fn strutils(&self, value: Tagged<Value>) -> Result<Tagged<Value>, ShellError> {
match value.item {
Value::Primitive(Primitive::String(ref s)) => {
Ok(Tagged::from_item(self.apply(&s), value.tag()))
@ -176,9 +173,7 @@ impl Plugin for Str {
}
fn filter(&mut self, input: Tagged<Value>) -> Result<Vec<ReturnValue>, ShellError> {
Ok(vec![ReturnSuccess::value(
self.strutils(input)?,
)])
Ok(vec![ReturnSuccess::value(self.strutils(input)?)])
}
}
@ -254,11 +249,7 @@ mod tests {
let mut plugin = Str::new();
assert!(plugin
.begin_filter(
CallStub::new()
.with_long_flag("downcase")
.create()
)
.begin_filter(CallStub::new().with_long_flag("downcase").create())
.is_ok());
assert!(plugin.action.is_some());
}
@ -268,11 +259,7 @@ mod tests {
let mut plugin = Str::new();
assert!(plugin
.begin_filter(
CallStub::new()
.with_long_flag("upcase")
.create()
)
.begin_filter(CallStub::new().with_long_flag("upcase").create())
.is_ok());
assert!(plugin.action.is_some());
}
@ -282,11 +269,7 @@ mod tests {
let mut plugin = Str::new();
assert!(plugin
.begin_filter(
CallStub::new()
.with_long_flag("to-int")
.create()
)
.begin_filter(CallStub::new().with_long_flag("to-int").create())
.is_ok());
assert!(plugin.action.is_some());
}

View File

@ -1,29 +1,7 @@
mod helpers;
use helpers::in_directory as cwd;
#[test]
fn regular_field_by_one() {
nu!(
output,
cwd("tests/fixtures/formats"),
"open cargo_sample.toml | inc package.edition | get package.edition | echo $it"
);
assert_eq!(output, "2019");
}
#[test]
fn by_one_without_passing_field() {
nu!(
output,
cwd("tests/fixtures/formats"),
"open cargo_sample.toml | get package.edition | inc | echo $it"
);
assert_eq!(output, "2019");
}
use h::{in_directory as cwd, Playground, Stub::*};
use helpers as h;
#[test]
fn can_only_apply_one() {
@ -37,34 +15,82 @@ fn can_only_apply_one() {
}
#[test]
fn semversion_major() {
fn regular_field_by_one() {
Playground::setup_for("plugin_inc_test_1")
.with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
edition = "2018"
"#,
)]);
nu!(
output,
cwd("tests/fixtures/formats"),
"open cargo_sample.toml | inc package.version --major | get package.version | echo $it"
cwd("tests/fixtures/nuplayground/plugin_inc_test_1"),
"open sample.toml | inc package.edition | get package.edition | echo $it"
);
assert_eq!(output, "2019");
}
#[test]
fn by_one_without_passing_field() {
Playground::setup_for("plugin_inc_test_2")
.with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
contributors = "2"
"#,
)]);
nu!(
output,
cwd("tests/fixtures/nuplayground/plugin_inc_test_2"),
"open sample.toml | get package.contributors | inc | echo $it"
);
assert_eq!(output, "3");
}
#[test]
fn semversion() {
Playground::setup_for("plugin_inc_test_3")
.with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
version = "0.1.3"
"#,
)]);
nu!(
output,
cwd("tests/fixtures/nuplayground/plugin_inc_test_3"),
"open sample.toml | inc package.version --major | get package.version | echo $it"
);
assert_eq!(output, "1.0.0");
}
#[test]
fn semversion_minor() {
fn semversion_without_passing_field() {
Playground::setup_for("plugin_inc_test_4")
.with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
version = "0.1.3"
"#,
)]);
nu!(
output,
cwd("tests/fixtures/formats"),
"open cargo_sample.toml | inc package.version --minor | get package.version | echo $it"
cwd("tests/fixtures/nuplayground/plugin_inc_test_4"),
"open sample.toml | get package.version | inc --patch | echo $it"
);
assert_eq!(output, "0.2.0");
}
#[test]
fn semversion_patch() {
nu!(
output,
cwd("tests/fixtures/formats"),
"open cargo_sample.toml | inc package.version --patch | get package.version | echo $it"
);
assert_eq!(output, "0.1.2");
assert_eq!(output, "0.1.4");
}

View File

@ -1,20 +1,10 @@
mod helpers;
use helpers::in_directory as cwd;
use h::{in_directory as cwd, Playground, Stub::*};
use helpers as h;
#[test]
fn acts_without_passing_field() {
nu!(
output,
cwd("tests/fixtures/formats"),
"open caco3_plastics.csv | first 1 | get origin | str --downcase | echo $it"
);
assert_eq!(output, "spain");
}
#[test]
fn str_can_only_apply_one() {
fn can_only_apply_one() {
nu_error!(
output,
cwd("tests/fixtures/formats"),
@ -25,22 +15,61 @@ fn str_can_only_apply_one() {
}
#[test]
fn downcases() {
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!(
output,
cwd("tests/fixtures/formats"),
"open caco3_plastics.csv | first 1 | str origin --downcase | get origin | echo $it"
cwd("tests/fixtures/nuplayground/plugin_str_test_without_passing_field"),
"open sample.yml | get environment.global.PROJECT_NAME | str --upcase | echo $it"
);
assert_eq!(output, "spain");
assert_eq!(output, "NUSHELL");
}
#[test]
fn downcases() {
Playground::setup_for("plugin_str_test_downcases")
.with_files(vec![FileWithContent(
"sample.toml",
r#"
[dependency]
name = "LIGHT"
"#,
)]);
nu!(
output,
cwd("tests/fixtures/nuplayground/plugin_str_test_downcases"),
"open sample.toml | str dependency.name --downcase | get dependency.name | echo $it"
);
assert_eq!(output, "light");
}
#[test]
fn upcases() {
Playground::setup_for("plugin_str_test_upcases")
.with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
name = "nushell"
"#,
)]);
nu!(
output,
cwd("tests/fixtures/formats"),
"open appveyor.yml | str environment.global.PROJECT_NAME --upcase | get environment.global.PROJECT_NAME | echo $it"
cwd("tests/fixtures/nuplayground/plugin_str_test_upcases"),
"open sample.toml | str package.name --upcase | get package.name | echo $it"
);
assert_eq!(output, "NUSHELL");
@ -51,7 +80,7 @@ fn converts_to_int() {
nu!(
output,
cwd("tests/fixtures/formats"),
"open caco3_plastics.csv | get 0 | str tariff_item --to-int | where tariff_item == 2509000000 | get tariff_item | echo $it"
"open caco3_plastics.csv | first 1 | str tariff_item --to-int | where tariff_item == 2509000000 | get tariff_item | echo $it"
);
assert_eq!(output, "2509000000");