mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 16:33:37 +01:00
cover pipeline helper.
This commit is contained in:
parent
b6ec98ce64
commit
a07817e0e0
@ -369,9 +369,13 @@ pub fn in_directory(str: impl AsRef<Path>) -> String {
|
||||
str.as_ref().display().to_string()
|
||||
}
|
||||
|
||||
|
||||
pub fn pipeline(commands: &str) -> String {
|
||||
commands.lines()
|
||||
.skip(1)
|
||||
.map(|line| line.trim())
|
||||
.collect::<Vec<&str>>()
|
||||
.concat()
|
||||
.join(" ")
|
||||
.trim_end()
|
||||
.to_string()
|
||||
}
|
||||
|
@ -1,43 +1,59 @@
|
||||
mod helpers;
|
||||
|
||||
use helpers::in_directory as cwd;
|
||||
use helpers::normalize_string;
|
||||
use helpers::{in_directory as cwd};
|
||||
use helpers as h;
|
||||
|
||||
#[test]
|
||||
fn pipeline_helper() {
|
||||
let actual = h::pipeline(
|
||||
r#"
|
||||
open los_tres_amigos.txt
|
||||
| from-csv
|
||||
| get rusty_luck
|
||||
| str --to-int
|
||||
| sum
|
||||
| echo "$it"
|
||||
"#);
|
||||
|
||||
assert_eq!(actual, r#"open los_tres_amigos.txt | from-csv | get rusty_luck | str --to-int | sum | echo "$it""#);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn external_num() {
|
||||
let output = nu!(
|
||||
let actual = nu!(
|
||||
cwd("tests/fixtures/formats"),
|
||||
"open sgml_description.json | get glossary.GlossDiv.GlossList.GlossEntry.Height | echo $it"
|
||||
);
|
||||
|
||||
assert_eq!(output, "10");
|
||||
assert_eq!(actual, "10");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn external_has_correct_quotes() {
|
||||
let output = nu!(cwd("."), r#"echo "hello world""#);
|
||||
let actual = nu!(cwd("."), r#"echo "hello world""#);
|
||||
|
||||
let output = normalize_string(&output);
|
||||
let actual = h::normalize_string(&actual);
|
||||
|
||||
assert_eq!(output, r#""hello world""#);
|
||||
assert_eq!(actual, r#""hello world""#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_plugin() {
|
||||
let output = nu!(
|
||||
let actual = nu!(
|
||||
cwd("tests/fixtures/formats"),
|
||||
r#"open cargo_sample.toml | add dev-dependencies.newdep "1" | get dev-dependencies.newdep | echo $it"#
|
||||
);
|
||||
|
||||
assert_eq!(output, "1");
|
||||
assert_eq!(actual, "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edit_plugin() {
|
||||
let output = nu!(
|
||||
let actual = nu!(
|
||||
cwd("tests/fixtures/formats"),
|
||||
r#"open cargo_sample.toml | edit dev-dependencies.pretty_assertions "7" | get dev-dependencies.pretty_assertions | echo $it"#
|
||||
);
|
||||
|
||||
assert_eq!(output, "7");
|
||||
assert_eq!(actual, "7");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user