forked from extern/nushell
Clean up.
This commit is contained in:
parent
5372463b37
commit
e744237451
@ -79,10 +79,7 @@ impl Str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Str {
|
impl Str {
|
||||||
fn strutils(
|
fn strutils(&self, value: Tagged<Value>) -> Result<Tagged<Value>, ShellError> {
|
||||||
&self,
|
|
||||||
value: Tagged<Value>,
|
|
||||||
) -> Result<Tagged<Value>, ShellError> {
|
|
||||||
match value.item {
|
match value.item {
|
||||||
Value::Primitive(Primitive::String(ref s)) => {
|
Value::Primitive(Primitive::String(ref s)) => {
|
||||||
Ok(Tagged::from_item(self.apply(&s), value.tag()))
|
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> {
|
fn filter(&mut self, input: Tagged<Value>) -> Result<Vec<ReturnValue>, ShellError> {
|
||||||
Ok(vec![ReturnSuccess::value(
|
Ok(vec![ReturnSuccess::value(self.strutils(input)?)])
|
||||||
self.strutils(input)?,
|
|
||||||
)])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,11 +249,7 @@ mod tests {
|
|||||||
let mut plugin = Str::new();
|
let mut plugin = Str::new();
|
||||||
|
|
||||||
assert!(plugin
|
assert!(plugin
|
||||||
.begin_filter(
|
.begin_filter(CallStub::new().with_long_flag("downcase").create())
|
||||||
CallStub::new()
|
|
||||||
.with_long_flag("downcase")
|
|
||||||
.create()
|
|
||||||
)
|
|
||||||
.is_ok());
|
.is_ok());
|
||||||
assert!(plugin.action.is_some());
|
assert!(plugin.action.is_some());
|
||||||
}
|
}
|
||||||
@ -268,11 +259,7 @@ mod tests {
|
|||||||
let mut plugin = Str::new();
|
let mut plugin = Str::new();
|
||||||
|
|
||||||
assert!(plugin
|
assert!(plugin
|
||||||
.begin_filter(
|
.begin_filter(CallStub::new().with_long_flag("upcase").create())
|
||||||
CallStub::new()
|
|
||||||
.with_long_flag("upcase")
|
|
||||||
.create()
|
|
||||||
)
|
|
||||||
.is_ok());
|
.is_ok());
|
||||||
assert!(plugin.action.is_some());
|
assert!(plugin.action.is_some());
|
||||||
}
|
}
|
||||||
@ -282,11 +269,7 @@ mod tests {
|
|||||||
let mut plugin = Str::new();
|
let mut plugin = Str::new();
|
||||||
|
|
||||||
assert!(plugin
|
assert!(plugin
|
||||||
.begin_filter(
|
.begin_filter(CallStub::new().with_long_flag("to-int").create())
|
||||||
CallStub::new()
|
|
||||||
.with_long_flag("to-int")
|
|
||||||
.create()
|
|
||||||
)
|
|
||||||
.is_ok());
|
.is_ok());
|
||||||
assert!(plugin.action.is_some());
|
assert!(plugin.action.is_some());
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,7 @@
|
|||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use helpers::in_directory as cwd;
|
use h::{in_directory as cwd, Playground, Stub::*};
|
||||||
|
use helpers as h;
|
||||||
#[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");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_only_apply_one() {
|
fn can_only_apply_one() {
|
||||||
@ -37,34 +15,82 @@ fn can_only_apply_one() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[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!(
|
nu!(
|
||||||
output,
|
output,
|
||||||
cwd("tests/fixtures/formats"),
|
cwd("tests/fixtures/nuplayground/plugin_inc_test_1"),
|
||||||
"open cargo_sample.toml | inc package.version --major | get package.version | echo $it"
|
"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");
|
assert_eq!(output, "1.0.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[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!(
|
nu!(
|
||||||
output,
|
output,
|
||||||
cwd("tests/fixtures/formats"),
|
cwd("tests/fixtures/nuplayground/plugin_inc_test_4"),
|
||||||
"open cargo_sample.toml | inc package.version --minor | get package.version | echo $it"
|
"open sample.toml | get package.version | inc --patch | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(output, "0.2.0");
|
assert_eq!(output, "0.1.4");
|
||||||
}
|
|
||||||
|
|
||||||
#[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");
|
|
||||||
}
|
}
|
@ -1,20 +1,10 @@
|
|||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use helpers::in_directory as cwd;
|
use h::{in_directory as cwd, Playground, Stub::*};
|
||||||
|
use helpers as h;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn acts_without_passing_field() {
|
fn can_only_apply_one() {
|
||||||
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() {
|
|
||||||
nu_error!(
|
nu_error!(
|
||||||
output,
|
output,
|
||||||
cwd("tests/fixtures/formats"),
|
cwd("tests/fixtures/formats"),
|
||||||
@ -25,22 +15,61 @@ fn str_can_only_apply_one() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[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!(
|
nu!(
|
||||||
output,
|
output,
|
||||||
cwd("tests/fixtures/formats"),
|
cwd("tests/fixtures/nuplayground/plugin_str_test_without_passing_field"),
|
||||||
"open caco3_plastics.csv | first 1 | str origin --downcase | get origin | echo $it"
|
"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]
|
#[test]
|
||||||
fn upcases() {
|
fn upcases() {
|
||||||
|
Playground::setup_for("plugin_str_test_upcases")
|
||||||
|
.with_files(vec![FileWithContent(
|
||||||
|
"sample.toml",
|
||||||
|
r#"
|
||||||
|
[package]
|
||||||
|
name = "nushell"
|
||||||
|
"#,
|
||||||
|
)]);
|
||||||
|
|
||||||
nu!(
|
nu!(
|
||||||
output,
|
output,
|
||||||
cwd("tests/fixtures/formats"),
|
cwd("tests/fixtures/nuplayground/plugin_str_test_upcases"),
|
||||||
"open appveyor.yml | str environment.global.PROJECT_NAME --upcase | get environment.global.PROJECT_NAME | echo $it"
|
"open sample.toml | str package.name --upcase | get package.name | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(output, "NUSHELL");
|
assert_eq!(output, "NUSHELL");
|
||||||
@ -51,7 +80,7 @@ fn converts_to_int() {
|
|||||||
nu!(
|
nu!(
|
||||||
output,
|
output,
|
||||||
cwd("tests/fixtures/formats"),
|
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");
|
assert_eq!(output, "2509000000");
|
||||||
|
Loading…
Reference in New Issue
Block a user