From a07817e0e043942522169ab02b53f3d440ad2724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20N=2E=20Robalino?= Date: Wed, 28 Aug 2019 20:30:51 -0500 Subject: [PATCH] cover pipeline helper. --- tests/helpers/mod.rs | 6 +++++- tests/tests.rs | 38 +++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/tests/helpers/mod.rs b/tests/helpers/mod.rs index e8a4107a18..e371b46ce7 100644 --- a/tests/helpers/mod.rs +++ b/tests/helpers/mod.rs @@ -369,9 +369,13 @@ pub fn in_directory(str: impl AsRef) -> String { str.as_ref().display().to_string() } + pub fn pipeline(commands: &str) -> String { commands.lines() .skip(1) + .map(|line| line.trim()) .collect::>() - .concat() + .join(" ") + .trim_end() + .to_string() } diff --git a/tests/tests.rs b/tests/tests.rs index b51fffe96c..7c157cb8a6 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -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"); }