nushell/tests/tests.rs

121 lines
2.3 KiB
Rust
Raw Normal View History

mod helpers;
2019-06-02 05:37:09 +02:00
2019-08-29 03:30:51 +02:00
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
2019-08-29 03:30:51 +02:00
| echo "$it"
2019-09-08 03:35:02 +02:00
"#,
);
2019-08-29 03:30:51 +02:00
2019-09-08 03:35:02 +02:00
assert_eq!(
actual,
r#"open los_tres_amigos.txt | from-csv | get rusty_luck | str --to-int | sum | echo "$it""#
);
2019-08-29 03:30:51 +02:00
}
#[test]
fn external_num() {
2019-08-29 03:30:51 +02:00
let actual = nu!(
2019-08-29 08:31:56 +02:00
cwd: "tests/fixtures/formats",
2019-07-22 05:52:57 +02:00
"open sgml_description.json | get glossary.GlossDiv.GlossList.GlossEntry.Height | echo $it"
);
2019-08-29 03:30:51 +02:00
assert_eq!(actual, "10");
}
2019-06-24 09:59:23 +02:00
2019-08-02 18:33:52 +02:00
#[test]
fn external_has_correct_quotes() {
2019-08-29 08:31:56 +02:00
let actual = nu!(
cwd: ".",
2019-08-29 08:31:56 +02:00
r#"echo "hello world""#
);
2019-08-02 18:33:52 +02:00
2019-09-08 04:00:04 +02:00
assert_eq!(actual, r#"hello world"#);
2019-08-02 18:33:52 +02:00
}
2019-07-22 05:52:57 +02:00
#[test]
2019-11-02 02:47:14 +01:00
fn insert_plugin() {
2019-08-29 03:30:51 +02:00
let actual = nu!(
2019-08-29 08:31:56 +02:00
cwd: "tests/fixtures/formats", h::pipeline(
r#"
open cargo_sample.toml
2019-11-02 02:47:14 +01:00
| insert dev-dependencies.newdep "1"
| get dev-dependencies.newdep
2019-08-29 08:31:56 +02:00
| echo $it
"#
));
2019-07-22 05:52:57 +02:00
2019-08-29 03:30:51 +02:00
assert_eq!(actual, "1");
2019-07-22 05:52:57 +02:00
}
#[test]
fn read_plugin() {
let actual = nu!(
cwd: "tests/fixtures/formats", h::pipeline(
r#"
open fileA.txt
| read "{Name}={Value}"
| nth 1
| get Value
| echo $it
"#
));
assert_eq!(actual, "StupidLongName");
}
2019-10-30 07:54:06 +01:00
#[test]
fn prepend_plugin() {
let actual = nu!(
cwd: "tests/fixtures/formats", h::pipeline(
r#"
open fileA.txt
| lines
| prepend "testme"
| nth 0
| echo $it
"#
));
assert_eq!(actual, "testme");
}
#[test]
fn append_plugin() {
let actual = nu!(
cwd: "tests/fixtures/formats", h::pipeline(
r#"
open fileA.txt
| lines
| append "testme"
| nth 3
| echo $it
"#
));
assert_eq!(actual, "testme");
}
2019-07-22 05:52:57 +02:00
#[test]
fn edit_plugin() {
2019-08-29 03:30:51 +02:00
let actual = nu!(
2019-08-29 08:31:56 +02:00
cwd: "tests/fixtures/formats", h::pipeline(
r#"
open cargo_sample.toml
| edit dev-dependencies.pretty_assertions "7"
| get dev-dependencies.pretty_assertions
2019-08-29 08:31:56 +02:00
| echo $it
"#
));
2019-07-22 05:52:57 +02:00
2019-08-29 03:30:51 +02:00
assert_eq!(actual, "7");
2019-07-22 05:52:57 +02:00
}