mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 09:53:43 +01:00
Clean up tests containing unnecessary cwd:
tokens (#9692)
# Description The working directory doesn't have to be set for those tests (or would be the default anyways). When appropriate also remove calls to the `pipeline()` function. In most places kept the diff minimal and only removed the superfluous part to not pollute the blame view. With simpler tests also simplified things to make them more readable overall (this included removal of the raw string literal). Work for #8670
This commit is contained in:
parent
48271d8c3e
commit
656f707a0b
@ -2,24 +2,18 @@ use nu_test_support::nu;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_binary_starts_with() {
|
fn basic_binary_starts_with() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
"hello world" | into binary | bytes starts-with 0x[68 65 6c 6c 6f]
|
"hello world" | into binary | bytes starts-with 0x[68 65 6c 6c 6f]
|
||||||
"#
|
"#);
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "true");
|
assert_eq!(actual.out, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_string_fails() {
|
fn basic_string_fails() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
"hello world" | bytes starts-with 0x[68 65 6c 6c 6f]
|
"hello world" | bytes starts-with 0x[68 65 6c 6c 6f]
|
||||||
"#
|
"#);
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual.err.contains("command doesn't support"));
|
assert!(actual.err.contains("command doesn't support"));
|
||||||
assert_eq!(actual.out, "");
|
assert_eq!(actual.out, "");
|
||||||
@ -27,48 +21,36 @@ fn basic_string_fails() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn short_stream_binary() {
|
fn short_stream_binary() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
nu --testbin repeater (0x[01]) 5 | bytes starts-with 0x[010101]
|
nu --testbin repeater (0x[01]) 5 | bytes starts-with 0x[010101]
|
||||||
"#
|
"#);
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "true");
|
assert_eq!(actual.out, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn short_stream_mismatch() {
|
fn short_stream_mismatch() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
nu --testbin repeater (0x[010203]) 5 | bytes starts-with 0x[010204]
|
nu --testbin repeater (0x[010203]) 5 | bytes starts-with 0x[010204]
|
||||||
"#
|
"#);
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "false");
|
assert_eq!(actual.out, "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn short_stream_binary_overflow() {
|
fn short_stream_binary_overflow() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
nu --testbin repeater (0x[01]) 5 | bytes starts-with 0x[010101010101]
|
nu --testbin repeater (0x[01]) 5 | bytes starts-with 0x[010101010101]
|
||||||
"#
|
"#);
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "false");
|
assert_eq!(actual.out, "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn long_stream_binary() {
|
fn long_stream_binary() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
nu --testbin repeater (0x[01]) 32768 | bytes starts-with 0x[010101]
|
nu --testbin repeater (0x[01]) 32768 | bytes starts-with 0x[010101]
|
||||||
"#
|
"#);
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "true");
|
assert_eq!(actual.out, "true");
|
||||||
}
|
}
|
||||||
@ -76,12 +58,9 @@ fn long_stream_binary() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn long_stream_binary_overflow() {
|
fn long_stream_binary_overflow() {
|
||||||
// .. ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
// .. ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
nu --testbin repeater (0x[01]) 32768 | bytes starts-with (0..32768 | each {|| 0x[01] } | bytes collect)
|
nu --testbin repeater (0x[01]) 32768 | bytes starts-with (0..32768 | each {|| 0x[01] } | bytes collect)
|
||||||
"#
|
"#);
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "false");
|
assert_eq!(actual.out, "false");
|
||||||
}
|
}
|
||||||
@ -89,12 +68,9 @@ fn long_stream_binary_overflow() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn long_stream_binary_exact() {
|
fn long_stream_binary_exact() {
|
||||||
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
nu --testbin repeater (0x[01020304]) 8192 | bytes starts-with (0..<8192 | each {|| 0x[01020304] } | bytes collect)
|
nu --testbin repeater (0x[01020304]) 8192 | bytes starts-with (0..<8192 | each {|| 0x[01020304] } | bytes collect)
|
||||||
"#
|
"#);
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "true");
|
assert_eq!(actual.out, "true");
|
||||||
}
|
}
|
||||||
@ -102,12 +78,9 @@ fn long_stream_binary_exact() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn long_stream_string_exact() {
|
fn long_stream_string_exact() {
|
||||||
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
nu --testbin repeater hell 8192 | bytes starts-with (0..<8192 | each {|| "hell" | into binary } | bytes collect)
|
nu --testbin repeater hell 8192 | bytes starts-with (0..<8192 | each {|| "hell" | into binary } | bytes collect)
|
||||||
"#
|
"#);
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "true");
|
assert_eq!(actual.out, "true");
|
||||||
}
|
}
|
||||||
@ -115,15 +88,12 @@ fn long_stream_string_exact() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn long_stream_mixed_exact() {
|
fn long_stream_mixed_exact() {
|
||||||
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
let binseg = (0..<2048 | each {|| 0x[003d9fbf] } | bytes collect)
|
let binseg = (0..<2048 | each {|| 0x[003d9fbf] } | bytes collect)
|
||||||
let strseg = (0..<2048 | each {|| "hell" | into binary } | bytes collect)
|
let strseg = (0..<2048 | each {|| "hell" | into binary } | bytes collect)
|
||||||
|
|
||||||
nu --testbin repeat_bytes 003d9fbf 2048 68656c6c 2048 | bytes starts-with (bytes build $binseg $strseg)
|
nu --testbin repeat_bytes 003d9fbf 2048 68656c6c 2048 | bytes starts-with (bytes build $binseg $strseg)
|
||||||
"#
|
"#);
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
actual.err, "",
|
actual.err, "",
|
||||||
@ -135,15 +105,12 @@ fn long_stream_mixed_exact() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn long_stream_mixed_overflow() {
|
fn long_stream_mixed_overflow() {
|
||||||
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
let binseg = (0..<2048 | each {|| 0x[003d9fbf] } | bytes collect)
|
let binseg = (0..<2048 | each {|| 0x[003d9fbf] } | bytes collect)
|
||||||
let strseg = (0..<2048 | each {|| "hell" | into binary } | bytes collect)
|
let strseg = (0..<2048 | each {|| "hell" | into binary } | bytes collect)
|
||||||
|
|
||||||
nu --testbin repeat_bytes 003d9fbf 2048 68656c6c 2048 | bytes starts-with (bytes build $binseg $strseg 0x[01])
|
nu --testbin repeat_bytes 003d9fbf 2048 68656c6c 2048 | bytes starts-with (bytes build $binseg $strseg 0x[01])
|
||||||
"#
|
"#);
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
actual.err, "",
|
actual.err, "",
|
||||||
|
@ -1,22 +1,16 @@
|
|||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::nu;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn append_assign_int() {
|
fn append_assign_int() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut a = [1 2];
|
mut a = [1 2];
|
||||||
$a ++= [3 4];
|
$a ++= [3 4];
|
||||||
$a
|
$a
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
let expected = nu!(
|
let expected = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
[1 2 3 4]
|
[1 2 3 4]
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
print!("{}", actual.out);
|
print!("{}", actual.out);
|
||||||
print!("{}", expected.out);
|
print!("{}", expected.out);
|
||||||
@ -25,21 +19,15 @@ fn append_assign_int() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn append_assign_string() {
|
fn append_assign_string() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut a = [a b];
|
mut a = [a b];
|
||||||
$a ++= [c d];
|
$a ++= [c d];
|
||||||
$a
|
$a
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
let expected = nu!(
|
let expected = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
[a b c d]
|
[a b c d]
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
print!("{}", actual.out);
|
print!("{}", actual.out);
|
||||||
print!("{}", expected.out);
|
print!("{}", expected.out);
|
||||||
@ -48,21 +36,15 @@ fn append_assign_string() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn append_assign_any() {
|
fn append_assign_any() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut a = [1 2 a];
|
mut a = [1 2 a];
|
||||||
$a ++= [b 3];
|
$a ++= [b 3];
|
||||||
$a
|
$a
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
let expected = nu!(
|
let expected = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
[1 2 a b 3]
|
[1 2 a b 3]
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
print!("{}", actual.out);
|
print!("{}", actual.out);
|
||||||
print!("{}", expected.out);
|
print!("{}", expected.out);
|
||||||
@ -71,21 +53,15 @@ fn append_assign_any() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn append_assign_both_empty() {
|
fn append_assign_both_empty() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut a = [];
|
mut a = [];
|
||||||
$a ++= [];
|
$a ++= [];
|
||||||
$a
|
$a
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
let expected = nu!(
|
let expected = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
[]
|
[]
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
print!("{}", actual.out);
|
print!("{}", actual.out);
|
||||||
print!("{}", expected.out);
|
print!("{}", expected.out);
|
||||||
@ -94,14 +70,11 @@ fn append_assign_both_empty() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn append_assign_type_mismatch() {
|
fn append_assign_type_mismatch() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut a = [1 2];
|
mut a = [1 2];
|
||||||
$a ++= [a];
|
$a ++= [a];
|
||||||
$a | to json -r;
|
$a | to json -r;
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, r#"[1,2,"a"]"#);
|
assert_eq!(actual.out, r#"[1,2,"a"]"#);
|
||||||
}
|
}
|
||||||
|
@ -2,26 +2,18 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn formatter_not_valid() {
|
fn formatter_not_valid() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
date now | date format '%N'
|
date now | date format '%N'
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual.err.contains("invalid format"));
|
assert!(actual.err.contains("invalid format"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fails_without_input() {
|
fn fails_without_input() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
date format "%c"
|
date format "%c"
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual.err.contains("Pipeline empty"));
|
assert!(actual.err.contains("Pipeline empty"));
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,7 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn flatten_nested_tables_with_columns() {
|
fn flatten_nested_tables_with_columns() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo [[origin, people]; [Ecuador, ('Andres' | wrap name)]]
|
echo [[origin, people]; [Ecuador, ('Andres' | wrap name)]]
|
||||||
[[origin, people]; [Nu, ('nuno' | wrap name)]]
|
[[origin, people]; [Nu, ('nuno' | wrap name)]]
|
||||||
@ -20,8 +19,7 @@ fn flatten_nested_tables_with_columns() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn flatten_nested_tables_that_have_many_columns() {
|
fn flatten_nested_tables_that_have_many_columns() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo [[origin, people]; [Ecuador, (echo [[name, meal]; ['Andres', 'arepa']])]]
|
echo [[origin, people]; [Ecuador, (echo [[name, meal]; ['Andres', 'arepa']])]]
|
||||||
[[origin, people]; [USA, (echo [[name, meal]; ['Katz', 'nurepa']])]]
|
[[origin, people]; [USA, (echo [[name, meal]; ['Katz', 'nurepa']])]]
|
||||||
@ -36,8 +34,7 @@ fn flatten_nested_tables_that_have_many_columns() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn flatten_nested_tables() {
|
fn flatten_nested_tables() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo [[Andrés, Nicolás, Robalino]] | flatten | get 1
|
echo [[Andrés, Nicolás, Robalino]] | flatten | get 1
|
||||||
"#
|
"#
|
||||||
|
@ -2,13 +2,10 @@ use nu_test_support::nu;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn for_doesnt_auto_print_in_each_iteration() {
|
fn for_doesnt_auto_print_in_each_iteration() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
for i in 1..2 {
|
for i in 1..2 {
|
||||||
echo 1
|
echo 1
|
||||||
}"#
|
}"#);
|
||||||
);
|
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
// As we do not auto-print loops anymore
|
// As we do not auto-print loops anymore
|
||||||
assert!(!actual.out.contains('1'));
|
assert!(!actual.out.contains('1'));
|
||||||
@ -16,14 +13,11 @@ fn for_doesnt_auto_print_in_each_iteration() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn for_break_on_external_failed() {
|
fn for_break_on_external_failed() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
for i in 1..2 {
|
for i in 1..2 {
|
||||||
print 1;
|
print 1;
|
||||||
nu --testbin fail
|
nu --testbin fail
|
||||||
}"#
|
}"#);
|
||||||
);
|
|
||||||
// Note: nu! macro auto replace "\n" and "\r\n" with ""
|
// Note: nu! macro auto replace "\n" and "\r\n" with ""
|
||||||
// so our output will be `1`
|
// so our output will be `1`
|
||||||
assert_eq!(actual.out, "1");
|
assert_eq!(actual.out, "1");
|
||||||
@ -31,24 +25,18 @@ fn for_break_on_external_failed() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn failed_for_should_break_running() {
|
fn failed_for_should_break_running() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
for i in 1..2 {
|
for i in 1..2 {
|
||||||
nu --testbin fail
|
nu --testbin fail
|
||||||
}
|
}
|
||||||
print 3"#
|
print 3"#);
|
||||||
);
|
|
||||||
assert!(!actual.out.contains('3'));
|
assert!(!actual.out.contains('3'));
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
let x = [1 2]
|
let x = [1 2]
|
||||||
for i in $x {
|
for i in $x {
|
||||||
nu --testbin fail
|
nu --testbin fail
|
||||||
}
|
}
|
||||||
print 3"#
|
print 3"#);
|
||||||
);
|
|
||||||
assert!(!actual.out.contains('3'));
|
assert!(!actual.out.contains('3'));
|
||||||
}
|
}
|
||||||
|
@ -182,10 +182,7 @@ fn errors_fetching_by_accessing_empty_list() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn quoted_column_access() {
|
fn quoted_column_access() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"'[{"foo bar": {"baz": 4}}]' | from json | get "foo bar".baz.0 "#);
|
||||||
cwd: "tests/fixtures/formats",
|
|
||||||
r#"'[{"foo bar": {"baz": 4}}]' | from json | get "foo bar".baz.0 "#
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "4");
|
assert_eq!(actual.out, "4");
|
||||||
}
|
}
|
||||||
|
@ -2,39 +2,27 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn base64_defaults_to_encoding_with_standard_character_type() {
|
fn base64_defaults_to_encoding_with_standard_character_type() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo 'username:password' | encode base64
|
echo 'username:password' | encode base64
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "dXNlcm5hbWU6cGFzc3dvcmQ=");
|
assert_eq!(actual.out, "dXNlcm5hbWU6cGFzc3dvcmQ=");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn base64_encode_characterset_binhex() {
|
fn base64_encode_characterset_binhex() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo 'username:password' | encode base64 --character-set binhex
|
echo 'username:password' | encode base64 --character-set binhex
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "F@0NEPjJD97kE\'&bEhFZEP3");
|
assert_eq!(actual.out, "F@0NEPjJD97kE\'&bEhFZEP3");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_when_invalid_character_set_given() {
|
fn error_when_invalid_character_set_given() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo 'username:password' | encode base64 --character-set 'this is invalid'
|
echo 'username:password' | encode base64 --character-set 'this is invalid'
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual
|
assert!(actual
|
||||||
.err
|
.err
|
||||||
@ -43,26 +31,18 @@ fn error_when_invalid_character_set_given() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn base64_decode_characterset_binhex() {
|
fn base64_decode_characterset_binhex() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo "F@0NEPjJD97kE'&bEhFZEP3" | decode base64 --character-set binhex --binary | decode utf-8
|
echo "F@0NEPjJD97kE'&bEhFZEP3" | decode base64 --character-set binhex --binary | decode utf-8
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "username:password");
|
assert_eq!(actual.out, "username:password");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_invalid_decode_value() {
|
fn error_invalid_decode_value() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo "this should not be a valid encoded value" | decode base64 --character-set url-safe
|
echo "this should not be a valid encoded value" | decode base64 --character-set url-safe
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual
|
assert!(actual
|
||||||
.err
|
.err
|
||||||
|
@ -45,8 +45,7 @@ fn headers_handles_missing_values() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn headers_invalid_column_type_empty_record() {
|
fn headers_invalid_column_type_empty_record() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[[a b]; [{}, 2], [3,4] ]
|
[[a b]; [{}, 2], [3,4] ]
|
||||||
| headers"#
|
| headers"#
|
||||||
@ -59,8 +58,7 @@ fn headers_invalid_column_type_empty_record() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn headers_invalid_column_type_record() {
|
fn headers_invalid_column_type_record() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[[a b]; [1 (scope aliases)] [2 2]]
|
[[a b]; [1 (scope aliases)] [2 2]]
|
||||||
| headers"#
|
| headers"#
|
||||||
@ -73,8 +71,7 @@ fn headers_invalid_column_type_record() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn headers_invalid_column_type_array() {
|
fn headers_invalid_column_type_array() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[[a b]; [[f,g], 2], [3,4] ]
|
[[a b]; [[f,g], 2], [3,4] ]
|
||||||
| headers"#
|
| headers"#
|
||||||
@ -87,8 +84,7 @@ fn headers_invalid_column_type_array() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn headers_invalid_column_type_range() {
|
fn headers_invalid_column_type_range() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[[a b]; [(1..5), 2], [3,4] ]
|
[[a b]; [(1..5), 2], [3,4] ]
|
||||||
| headers"#
|
| headers"#
|
||||||
@ -101,8 +97,7 @@ fn headers_invalid_column_type_range() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn headers_invalid_column_type_duration() {
|
fn headers_invalid_column_type_duration() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[[a b]; [((date now) - (date now)), 2], [3,4] ]
|
[[a b]; [((date now) - (date now)), 2], [3,4] ]
|
||||||
| headers"#
|
| headers"#
|
||||||
@ -115,8 +110,7 @@ fn headers_invalid_column_type_duration() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn headers_invalid_column_type_binary() {
|
fn headers_invalid_column_type_binary() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[[a b]; [("aa" | into binary), 2], [3,4] ]
|
[[a b]; [("aa" | into binary), 2], [3,4] ]
|
||||||
| headers"#
|
| headers"#
|
||||||
|
@ -4,12 +4,7 @@ use nu_test_support::{nu, nu_repl_code, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn help_commands_length() {
|
fn help_commands_length() {
|
||||||
let actual = nu!(
|
let actual = nu!("help commands | length");
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
help commands | length
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
let output = actual.out;
|
let output = actual.out;
|
||||||
let output_int: i32 = output.parse().unwrap();
|
let output_int: i32 = output.parse().unwrap();
|
||||||
@ -68,7 +63,7 @@ fn help_alias_usage_2() {
|
|||||||
"alias SPAM = print 'spam' # line2",
|
"alias SPAM = print 'spam' # line2",
|
||||||
"help aliases | where name == SPAM | get 0.usage",
|
"help aliases | where name == SPAM | get 0.usage",
|
||||||
];
|
];
|
||||||
let actual = nu!(cwd: ".", nu_repl_code(code));
|
let actual = nu!(nu_repl_code(code));
|
||||||
|
|
||||||
assert_eq!(actual.out, "line2");
|
assert_eq!(actual.out, "line2");
|
||||||
}
|
}
|
||||||
@ -368,7 +363,7 @@ fn help_modules_main_2() {
|
|||||||
"help modules | where name == spam | get 0.commands.0",
|
"help modules | where name == spam | get 0.commands.0",
|
||||||
];
|
];
|
||||||
|
|
||||||
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
|
let actual = nu!(pipeline(&inp.join("; ")));
|
||||||
|
|
||||||
assert_eq!(actual.out, "spam");
|
assert_eq!(actual.out, "spam");
|
||||||
}
|
}
|
||||||
@ -381,7 +376,7 @@ fn help_alias_before_command() {
|
|||||||
"def SPAM [] { 'spam' }",
|
"def SPAM [] { 'spam' }",
|
||||||
"help SPAM",
|
"help SPAM",
|
||||||
];
|
];
|
||||||
let actual = nu!(cwd: ".", nu_repl_code(code));
|
let actual = nu!(nu_repl_code(code));
|
||||||
|
|
||||||
assert!(actual.out.contains("Alias"));
|
assert!(actual.out.contains("Alias"));
|
||||||
}
|
}
|
||||||
|
@ -121,8 +121,7 @@ fn count() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn count_with_normalize_percentage() {
|
fn count_with_normalize_percentage() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo [[bit]; [1] [0] [0] [0] [0] [0] [0] [1]]
|
echo [[bit]; [1] [0] [0] [0] [0] [0] [0] [1]]
|
||||||
| histogram bit --percentage-type normalize
|
| histogram bit --percentage-type normalize
|
||||||
|
@ -16,9 +16,7 @@ fn insert_the_column() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn doesnt_convert_record_to_table() {
|
fn doesnt_convert_record_to_table() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"{a:1} | insert b 2 | to nuon"#);
|
||||||
cwd: ".", r#"{a:1} | insert b 2 | to nuon"#
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "{a: 1, b: 2}");
|
assert_eq!(actual.out, "{a: 1, b: 2}");
|
||||||
}
|
}
|
||||||
@ -40,48 +38,36 @@ fn insert_the_column_conflict() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn insert_into_list() {
|
fn insert_into_list() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
[1, 2, 3] | insert 1 abc | to json -r
|
[1, 2, 3] | insert 1 abc | to json -r
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, r#"[1,"abc",2,3]"#);
|
assert_eq!(actual.out, r#"[1,"abc",2,3]"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn insert_into_list_begin() {
|
fn insert_into_list_begin() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
[1, 2, 3] | insert 0 abc | to json -r
|
[1, 2, 3] | insert 0 abc | to json -r
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, r#"["abc",1,2,3]"#);
|
assert_eq!(actual.out, r#"["abc",1,2,3]"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn insert_into_list_end() {
|
fn insert_into_list_end() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
[1, 2, 3] | insert 3 abc | to json -r
|
[1, 2, 3] | insert 3 abc | to json -r
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, r#"[1,2,3,"abc"]"#);
|
assert_eq!(actual.out, r#"[1,2,3,"abc"]"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn insert_past_end_list() {
|
fn insert_past_end_list() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
[1, 2, 3] | insert 5 abc | to json -r
|
[1, 2, 3] | insert 5 abc | to json -r
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, r#"[1,2,3,null,null,"abc"]"#);
|
assert_eq!(actual.out, r#"[1,2,3,null,null,"abc"]"#);
|
||||||
}
|
}
|
||||||
@ -89,9 +75,8 @@ fn insert_past_end_list() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn insert_uses_enumerate_index() {
|
fn insert_uses_enumerate_index() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"[[a]; [7] [6]] | enumerate | insert b {|el| $el.index + 1 + $el.item.a } | flatten | to nuon"#
|
r#"[[a]; [7] [6]] | enumerate | insert b {|el| $el.index + 1 + $el.item.a } | flatten | to nuon"#
|
||||||
));
|
);
|
||||||
|
|
||||||
assert_eq!(actual.out, "[[index, a, b]; [0, 7, 8], [1, 6, 8]]");
|
assert_eq!(actual.out, "[[index, a, b]; [0, 7, 8], [1, 6, 8]]");
|
||||||
}
|
}
|
||||||
|
@ -2,44 +2,34 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn into_filesize_int() {
|
fn into_filesize_int() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
1 | into filesize
|
1 | into filesize
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains("1 B"));
|
assert!(actual.out.contains("1 B"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn into_filesize_decimal() {
|
fn into_filesize_decimal() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
1.2 | into filesize
|
1.2 | into filesize
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains("1 B"));
|
assert!(actual.out.contains("1 B"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn into_filesize_str() {
|
fn into_filesize_str() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
'2000' | into filesize
|
'2000' | into filesize
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains("2.0 KiB"));
|
assert!(actual.out.contains("2.0 KiB"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn into_filesize_str_newline() {
|
fn into_filesize_str_newline() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
"2000
|
"2000
|
||||||
" | into filesize
|
" | into filesize
|
||||||
@ -51,8 +41,7 @@ fn into_filesize_str_newline() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn into_filesize_str_many_newlines() {
|
fn into_filesize_str_many_newlines() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
"2000
|
"2000
|
||||||
|
|
||||||
@ -65,24 +54,18 @@ fn into_filesize_str_many_newlines() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn into_filesize_filesize() {
|
fn into_filesize_filesize() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
3kib | into filesize
|
3kib | into filesize
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains("3.0 KiB"));
|
assert!(actual.out.contains("3.0 KiB"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn into_filesize_negative_filesize() {
|
fn into_filesize_negative_filesize() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
-3kib | into filesize
|
-3kib | into filesize
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains("-3.0 KiB"));
|
assert!(actual.out.contains("-3.0 KiB"));
|
||||||
}
|
}
|
||||||
|
@ -1,52 +1,40 @@
|
|||||||
use chrono::{DateTime, FixedOffset, NaiveDate, TimeZone};
|
use chrono::{DateTime, FixedOffset, NaiveDate, TimeZone};
|
||||||
use rstest::rstest;
|
use rstest::rstest;
|
||||||
|
|
||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::nu;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn into_int_filesize() {
|
fn into_int_filesize() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo 1kb | into int | each { |it| $it / 1000 }
|
echo 1kb | into int | each { |it| $it / 1000 }
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains('1'));
|
assert!(actual.out.contains('1'));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn into_int_filesize2() {
|
fn into_int_filesize2() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo 1kib | into int | each { |it| $it / 1024 }
|
echo 1kib | into int | each { |it| $it / 1024 }
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains('1'));
|
assert!(actual.out.contains('1'));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn into_int_int() {
|
fn into_int_int() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo 1024 | into int | each { |it| $it / 1024 }
|
echo 1024 | into int | each { |it| $it / 1024 }
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains('1'));
|
assert!(actual.out.contains('1'));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn into_int_binary() {
|
fn into_int_binary() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo 0x[01010101] | into int
|
echo 0x[01010101] | into int
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains("16843009"));
|
assert!(actual.out.contains("16843009"));
|
||||||
}
|
}
|
||||||
@ -80,9 +68,8 @@ fn into_int_datetime1() {
|
|||||||
#[case("2052-04-13T12:09:14.123456789-05:00", "2596640954123456789")] // future date > 2038 epoch
|
#[case("2052-04-13T12:09:14.123456789-05:00", "2596640954123456789")] // future date > 2038 epoch
|
||||||
#[case("1902-04-13T12:09:14.123456789-05:00", "-2137042245876543211")] // past date < 1970
|
#[case("1902-04-13T12:09:14.123456789-05:00", "-2137042245876543211")] // past date < 1970
|
||||||
fn into_int_datetime(#[case] time_in: &str, #[case] int_out: &str) {
|
fn into_int_datetime(#[case] time_in: &str, #[case] int_out: &str) {
|
||||||
let actual = nu!(
|
let actual = nu!(&format!(
|
||||||
cwd: ".", pipeline(
|
r#""{time_in}" | into datetime --format "%+" | into int"#
|
||||||
&format!(r#""{time_in}" | into datetime --format "%+" | into int"#)
|
|
||||||
));
|
));
|
||||||
|
|
||||||
assert_eq!(int_out, actual.out);
|
assert_eq!(int_out, actual.out);
|
||||||
|
@ -1,25 +1,15 @@
|
|||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::nu;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn length_columns_in_cal_table() {
|
fn length_columns_in_cal_table() {
|
||||||
let actual = nu!(
|
let actual = nu!("cal | length -c");
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
cal | length -c
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "7");
|
assert_eq!(actual.out, "7");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn length_columns_no_rows() {
|
fn length_columns_no_rows() {
|
||||||
let actual = nu!(
|
let actual = nu!("echo [] | length -c");
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo [] | length -c
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "0");
|
assert_eq!(actual.out, "0");
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,7 @@ use nu_test_support::nu;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn loop_doesnt_auto_print_in_each_iteration() {
|
fn loop_doesnt_auto_print_in_each_iteration() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
mut total = 0;
|
mut total = 0;
|
||||||
loop {
|
loop {
|
||||||
if $total == 3 {
|
if $total == 3 {
|
||||||
@ -13,8 +11,7 @@ fn loop_doesnt_auto_print_in_each_iteration() {
|
|||||||
$total += 1;
|
$total += 1;
|
||||||
}
|
}
|
||||||
echo 1
|
echo 1
|
||||||
}"#
|
}"#);
|
||||||
);
|
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
// As we do not auto-print loops anymore
|
// As we do not auto-print loops anymore
|
||||||
assert!(!actual.out.contains('1'));
|
assert!(!actual.out.contains('1'));
|
||||||
@ -22,9 +19,7 @@ fn loop_doesnt_auto_print_in_each_iteration() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn loop_break_on_external_failed() {
|
fn loop_break_on_external_failed() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
mut total = 0;
|
mut total = 0;
|
||||||
loop {
|
loop {
|
||||||
if $total == 3 {
|
if $total == 3 {
|
||||||
@ -34,8 +29,7 @@ fn loop_break_on_external_failed() {
|
|||||||
}
|
}
|
||||||
print 1;
|
print 1;
|
||||||
nu --testbin fail;
|
nu --testbin fail;
|
||||||
}"#
|
}"#);
|
||||||
);
|
|
||||||
// Note: nu! macro auto replace "\n" and "\r\n" with ""
|
// Note: nu! macro auto replace "\n" and "\r\n" with ""
|
||||||
// so our output will be `1`.
|
// so our output will be `1`.
|
||||||
assert_eq!(actual.out, "1");
|
assert_eq!(actual.out, "1");
|
||||||
@ -43,9 +37,7 @@ fn loop_break_on_external_failed() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn failed_loop_should_break_running() {
|
fn failed_loop_should_break_running() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
mut total = 0;
|
mut total = 0;
|
||||||
loop {
|
loop {
|
||||||
if $total == 3 {
|
if $total == 3 {
|
||||||
@ -55,7 +47,6 @@ fn failed_loop_should_break_running() {
|
|||||||
}
|
}
|
||||||
nu --testbin fail;
|
nu --testbin fail;
|
||||||
}
|
}
|
||||||
print 3"#
|
print 3"#);
|
||||||
);
|
|
||||||
assert!(!actual.out.contains('3'));
|
assert!(!actual.out.contains('3'));
|
||||||
}
|
}
|
||||||
|
@ -558,12 +558,7 @@ fn list_ignores_ansi() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn list_unknown_flag() {
|
fn list_unknown_flag() {
|
||||||
let actual = nu!(
|
let actual = nu!("ls -r");
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
ls -r
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual
|
assert!(actual
|
||||||
.err
|
.err
|
||||||
|
@ -2,10 +2,7 @@ use nu_test_support::nu;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn match_for_range() {
|
fn match_for_range() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"match 3 { 1..10 => { print "success" } }"#);
|
||||||
cwd: ".",
|
|
||||||
r#"match 3 { 1..10 => { print "success" } }"#
|
|
||||||
);
|
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
// As we do not auto-print loops anymore
|
// As we do not auto-print loops anymore
|
||||||
assert_eq!(actual.out, "success");
|
assert_eq!(actual.out, "success");
|
||||||
@ -13,10 +10,7 @@ fn match_for_range() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn match_for_range_unmatched() {
|
fn match_for_range_unmatched() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"match 11 { 1..10 => { print "failure" }, _ => { print "success" }}"#);
|
||||||
cwd: ".",
|
|
||||||
r#"match 11 { 1..10 => { print "failure" }, _ => { print "success" }}"#
|
|
||||||
);
|
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
// As we do not auto-print loops anymore
|
// As we do not auto-print loops anymore
|
||||||
assert_eq!(actual.out, "success");
|
assert_eq!(actual.out, "success");
|
||||||
@ -24,10 +18,7 @@ fn match_for_range_unmatched() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn match_for_record() {
|
fn match_for_record() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"match {a: 11} { {a: $b} => { print $b }}"#);
|
||||||
cwd: ".",
|
|
||||||
r#"match {a: 11} { {a: $b} => { print $b }}"#
|
|
||||||
);
|
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
// As we do not auto-print loops anymore
|
// As we do not auto-print loops anymore
|
||||||
assert_eq!(actual.out, "11");
|
assert_eq!(actual.out, "11");
|
||||||
@ -35,10 +26,7 @@ fn match_for_record() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn match_for_record_shorthand() {
|
fn match_for_record_shorthand() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"match {a: 12} { {$a} => { print $a }}"#);
|
||||||
cwd: ".",
|
|
||||||
r#"match {a: 12} { {$a} => { print $a }}"#
|
|
||||||
);
|
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
// As we do not auto-print loops anymore
|
// As we do not auto-print loops anymore
|
||||||
assert_eq!(actual.out, "12");
|
assert_eq!(actual.out, "12");
|
||||||
@ -47,7 +35,6 @@ fn match_for_record_shorthand() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn match_list() {
|
fn match_list() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
|
||||||
r#"match [1, 2] { [$a] => { print $"single: ($a)" }, [$b, $c] => {print $"double: ($b) ($c)"}}"#
|
r#"match [1, 2] { [$a] => { print $"single: ($a)" }, [$b, $c] => {print $"double: ($b) ($c)"}}"#
|
||||||
);
|
);
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
@ -58,7 +45,6 @@ fn match_list() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn match_list_rest_ignore() {
|
fn match_list_rest_ignore() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
|
||||||
r#"match [1, 2] { [$a, ..] => { print $"single: ($a)" }, [$b, $c] => {print $"double: ($b) ($c)"}}"#
|
r#"match [1, 2] { [$a, ..] => { print $"single: ($a)" }, [$b, $c] => {print $"double: ($b) ($c)"}}"#
|
||||||
);
|
);
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
@ -69,7 +55,6 @@ fn match_list_rest_ignore() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn match_list_rest() {
|
fn match_list_rest() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
|
||||||
r#"match [1, 2, 3] { [$a, ..$remainder] => { print $"single: ($a) ($remainder | math sum)" }, [$b, $c] => {print $"double: ($b) ($c)"}}"#
|
r#"match [1, 2, 3] { [$a, ..$remainder] => { print $"single: ($a) ($remainder | math sum)" }, [$b, $c] => {print $"double: ($b) ($c)"}}"#
|
||||||
);
|
);
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
@ -80,7 +65,6 @@ fn match_list_rest() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn match_constant_1() {
|
fn match_constant_1() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
|
||||||
r#"match 2 { 1 => { print "failure"}, 2 => { print "success" }, 3 => { print "failure" }}"#
|
r#"match 2 { 1 => { print "failure"}, 2 => { print "success" }, 3 => { print "failure" }}"#
|
||||||
);
|
);
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
@ -91,7 +75,6 @@ fn match_constant_1() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn match_constant_2() {
|
fn match_constant_2() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
|
||||||
r#"match 2.3 { 1.4 => { print "failure"}, 2.3 => { print "success" }, 3 => { print "failure" }}"#
|
r#"match 2.3 { 1.4 => { print "failure"}, 2.3 => { print "success" }, 3 => { print "failure" }}"#
|
||||||
);
|
);
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
@ -102,7 +85,6 @@ fn match_constant_2() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn match_constant_3() {
|
fn match_constant_3() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
|
||||||
r#"match true { false => { print "failure"}, true => { print "success" }, 3 => { print "failure" }}"#
|
r#"match true { false => { print "failure"}, true => { print "success" }, 3 => { print "failure" }}"#
|
||||||
);
|
);
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
@ -113,7 +95,6 @@ fn match_constant_3() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn match_constant_4() {
|
fn match_constant_4() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
|
||||||
r#"match "def" { "abc" => { print "failure"}, "def" => { print "success" }, "ghi" => { print "failure" }}"#
|
r#"match "def" { "abc" => { print "failure"}, "def" => { print "success" }, "ghi" => { print "failure" }}"#
|
||||||
);
|
);
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
@ -124,7 +105,6 @@ fn match_constant_4() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn match_constant_5() {
|
fn match_constant_5() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
|
||||||
r#"match 2019-08-23 { 2010-01-01 => { print "failure"}, 2019-08-23 => { print "success" }, 2020-02-02 => { print "failure" }}"#
|
r#"match 2019-08-23 { 2010-01-01 => { print "failure"}, 2019-08-23 => { print "success" }, 2020-02-02 => { print "failure" }}"#
|
||||||
);
|
);
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
@ -135,7 +115,6 @@ fn match_constant_5() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn match_constant_6() {
|
fn match_constant_6() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
|
||||||
r#"match 6sec { 2sec => { print "failure"}, 6sec => { print "success" }, 1min => { print "failure" }}"#
|
r#"match 6sec { 2sec => { print "failure"}, 6sec => { print "success" }, 1min => { print "failure" }}"#
|
||||||
);
|
);
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
@ -146,7 +125,6 @@ fn match_constant_6() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn match_constant_7() {
|
fn match_constant_7() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
|
||||||
r#"match 1kib { 1kb => { print "failure"}, 1kib => { print "success" }, 2kb => { print "failure" }}"#
|
r#"match 1kib { 1kb => { print "failure"}, 1kib => { print "success" }, 2kb => { print "failure" }}"#
|
||||||
);
|
);
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
@ -157,7 +135,6 @@ fn match_constant_7() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn match_or_pattern() {
|
fn match_or_pattern() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
|
||||||
r#"match {b: 7} { {a: $a} | {b: $b} => { print $"success: ($b)" }, _ => { print "failure" }}"#
|
r#"match {b: 7} { {a: $a} | {b: $b} => { print $"success: ($b)" }, _ => { print "failure" }}"#
|
||||||
);
|
);
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
@ -168,7 +145,6 @@ fn match_or_pattern() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn match_or_pattern_overlap_1() {
|
fn match_or_pattern_overlap_1() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
|
||||||
r#"match {a: 7} { {a: $b} | {b: $b} => { print $"success: ($b)" }, _ => { print "failure" }}"#
|
r#"match {a: 7} { {a: $b} | {b: $b} => { print $"success: ($b)" }, _ => { print "failure" }}"#
|
||||||
);
|
);
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
@ -179,7 +155,6 @@ fn match_or_pattern_overlap_1() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn match_or_pattern_overlap_2() {
|
fn match_or_pattern_overlap_2() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
|
||||||
r#"match {b: 7} { {a: $b} | {b: $b} => { print $"success: ($b)" }, _ => { print "failure" }}"#
|
r#"match {b: 7} { {a: $b} | {b: $b} => { print $"success: ($b)" }, _ => { print "failure" }}"#
|
||||||
);
|
);
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
@ -189,10 +164,7 @@ fn match_or_pattern_overlap_2() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn match_doesnt_overwrite_variable() {
|
fn match_doesnt_overwrite_variable() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"let b = 100; match 55 { $b => {} }; print $b"#);
|
||||||
cwd: ".",
|
|
||||||
r#"let b = 100; match 55 { $b => {} }; print $b"#
|
|
||||||
);
|
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
// As we do not auto-print loops anymore
|
// As we do not auto-print loops anymore
|
||||||
assert_eq!(actual.out, "100");
|
assert_eq!(actual.out, "100");
|
||||||
|
@ -16,10 +16,7 @@ fn can_average_numbers() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_average_bytes() {
|
fn can_average_bytes() {
|
||||||
let actual = nu!(
|
let actual = nu!("[100kb, 10b, 100mib] | math avg | to json -r");
|
||||||
cwd: "tests/fixtures/formats",
|
|
||||||
"[100kb, 10b, 100mib] | math avg | to json -r"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "34985870");
|
assert_eq!(actual.out, "34985870");
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,7 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn median_numbers_with_even_rows() {
|
fn median_numbers_with_even_rows() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo [10 6 19 21 4]
|
echo [10 6 19 21 4]
|
||||||
| math median
|
| math median
|
||||||
@ -15,8 +14,7 @@ fn median_numbers_with_even_rows() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn median_numbers_with_odd_rows() {
|
fn median_numbers_with_odd_rows() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo [3 8 9 12 12 15]
|
echo [3 8 9 12 12 15]
|
||||||
| math median
|
| math median
|
||||||
@ -28,8 +26,7 @@ fn median_numbers_with_odd_rows() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn median_mixed_numbers() {
|
fn median_mixed_numbers() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo [-11.5 -13.5 10]
|
echo [-11.5 -13.5 10]
|
||||||
| math median
|
| math median
|
||||||
|
@ -8,8 +8,7 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn one_arg() {
|
fn one_arg() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1
|
1
|
||||||
"#
|
"#
|
||||||
@ -20,8 +19,7 @@ fn one_arg() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add() {
|
fn add() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1 + 1
|
1 + 1
|
||||||
"#
|
"#
|
||||||
@ -32,8 +30,7 @@ fn add() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_compound() {
|
fn add_compound() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1 + 2 + 2
|
1 + 2 + 2
|
||||||
"#
|
"#
|
||||||
@ -44,8 +41,7 @@ fn add_compound() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn precedence_of_operators() {
|
fn precedence_of_operators() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1 + 2 * 2
|
1 + 2 * 2
|
||||||
"#
|
"#
|
||||||
@ -56,8 +52,7 @@ fn precedence_of_operators() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn precedence_of_operators2() {
|
fn precedence_of_operators2() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1 + 2 * 2 + 1
|
1 + 2 * 2 + 1
|
||||||
"#
|
"#
|
||||||
@ -68,8 +63,7 @@ fn precedence_of_operators2() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn precedence_of_operators3() {
|
fn precedence_of_operators3() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
5 - 5 * 10 + 5
|
5 - 5 * 10 + 5
|
||||||
"#
|
"#
|
||||||
@ -80,8 +74,7 @@ fn precedence_of_operators3() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn precedence_of_operators4() {
|
fn precedence_of_operators4() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
5 - (5 * 10) + 5
|
5 - (5 * 10) + 5
|
||||||
"#
|
"#
|
||||||
@ -92,8 +85,7 @@ fn precedence_of_operators4() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn division_of_ints() {
|
fn division_of_ints() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
4 / 2
|
4 / 2
|
||||||
"#
|
"#
|
||||||
@ -104,8 +96,7 @@ fn division_of_ints() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn division_of_ints2() {
|
fn division_of_ints2() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1 / 4
|
1 / 4
|
||||||
"#
|
"#
|
||||||
@ -116,8 +107,7 @@ fn division_of_ints2() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_zero_division_int_int() {
|
fn error_zero_division_int_int() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1 / 0
|
1 / 0
|
||||||
"#
|
"#
|
||||||
@ -128,8 +118,7 @@ fn error_zero_division_int_int() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_zero_division_decimal_int() {
|
fn error_zero_division_decimal_int() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1.0 / 0
|
1.0 / 0
|
||||||
"#
|
"#
|
||||||
@ -140,8 +129,7 @@ fn error_zero_division_decimal_int() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_zero_division_int_decimal() {
|
fn error_zero_division_int_decimal() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1 / 0.0
|
1 / 0.0
|
||||||
"#
|
"#
|
||||||
@ -152,8 +140,7 @@ fn error_zero_division_int_decimal() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_zero_division_decimal_decimal() {
|
fn error_zero_division_decimal_decimal() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1.0 / 0.0
|
1.0 / 0.0
|
||||||
"#
|
"#
|
||||||
@ -164,8 +151,7 @@ fn error_zero_division_decimal_decimal() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn floor_division_of_ints() {
|
fn floor_division_of_ints() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
5 // 2
|
5 // 2
|
||||||
"#
|
"#
|
||||||
@ -176,8 +162,7 @@ fn floor_division_of_ints() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn floor_division_of_ints2() {
|
fn floor_division_of_ints2() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
-3 // 2
|
-3 // 2
|
||||||
"#
|
"#
|
||||||
@ -188,8 +173,7 @@ fn floor_division_of_ints2() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn floor_division_of_floats() {
|
fn floor_division_of_floats() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
-3.0 // 2.0
|
-3.0 // 2.0
|
||||||
"#
|
"#
|
||||||
@ -200,8 +184,7 @@ fn floor_division_of_floats() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_zero_floor_division_int_int() {
|
fn error_zero_floor_division_int_int() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1 // 0
|
1 // 0
|
||||||
"#
|
"#
|
||||||
@ -212,8 +195,7 @@ fn error_zero_floor_division_int_int() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_zero_floor_division_decimal_int() {
|
fn error_zero_floor_division_decimal_int() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1.0 // 0
|
1.0 // 0
|
||||||
"#
|
"#
|
||||||
@ -224,8 +206,7 @@ fn error_zero_floor_division_decimal_int() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_zero_floor_division_int_decimal() {
|
fn error_zero_floor_division_int_decimal() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1 // 0.0
|
1 // 0.0
|
||||||
"#
|
"#
|
||||||
@ -236,8 +217,7 @@ fn error_zero_floor_division_int_decimal() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_zero_floor_division_decimal_decimal() {
|
fn error_zero_floor_division_decimal_decimal() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1.0 // 0.0
|
1.0 // 0.0
|
||||||
"#
|
"#
|
||||||
@ -247,8 +227,7 @@ fn error_zero_floor_division_decimal_decimal() {
|
|||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn proper_precedence_history() {
|
fn proper_precedence_history() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
2 / 2 / 2 + 1
|
2 / 2 / 2 + 1
|
||||||
"#
|
"#
|
||||||
@ -259,8 +238,7 @@ fn proper_precedence_history() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parens_precedence() {
|
fn parens_precedence() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
4 * (6 - 3)
|
4 * (6 - 3)
|
||||||
"#
|
"#
|
||||||
@ -271,8 +249,7 @@ fn parens_precedence() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn modulo() {
|
fn modulo() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
9 mod 2
|
9 mod 2
|
||||||
"#
|
"#
|
||||||
@ -283,8 +260,7 @@ fn modulo() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_multiplication_math() {
|
fn unit_multiplication_math() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1mb * 2
|
1mb * 2
|
||||||
"#
|
"#
|
||||||
@ -295,8 +271,7 @@ fn unit_multiplication_math() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_multiplication_float_math() {
|
fn unit_multiplication_float_math() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1mb * 1.2
|
1mb * 1.2
|
||||||
"#
|
"#
|
||||||
@ -307,8 +282,7 @@ fn unit_multiplication_float_math() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_float_floor_division_math() {
|
fn unit_float_floor_division_math() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1mb // 3.0
|
1mb // 3.0
|
||||||
"#
|
"#
|
||||||
@ -319,8 +293,7 @@ fn unit_float_floor_division_math() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_division_math() {
|
fn unit_division_math() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1mb / 4
|
1mb / 4
|
||||||
"#
|
"#
|
||||||
@ -331,8 +304,7 @@ fn unit_division_math() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_float_division_math() {
|
fn unit_float_division_math() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1mb / 3.1
|
1mb / 3.1
|
||||||
"#
|
"#
|
||||||
@ -343,8 +315,7 @@ fn unit_float_division_math() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn duration_math() {
|
fn duration_math() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1wk + 1day
|
1wk + 1day
|
||||||
"#
|
"#
|
||||||
@ -355,8 +326,7 @@ fn duration_math() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn duration_decimal_math() {
|
fn duration_decimal_math() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
5.5day + 0.5day
|
5.5day + 0.5day
|
||||||
"#
|
"#
|
||||||
@ -367,8 +337,7 @@ fn duration_decimal_math() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn duration_math_with_nanoseconds() {
|
fn duration_math_with_nanoseconds() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1wk + 10ns
|
1wk + 10ns
|
||||||
"#
|
"#
|
||||||
@ -379,8 +348,7 @@ fn duration_math_with_nanoseconds() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn duration_decimal_math_with_nanoseconds() {
|
fn duration_decimal_math_with_nanoseconds() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1.5wk + 10ns
|
1.5wk + 10ns
|
||||||
"#
|
"#
|
||||||
@ -391,8 +359,7 @@ fn duration_decimal_math_with_nanoseconds() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn duration_decimal_math_with_all_units() {
|
fn duration_decimal_math_with_all_units() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1wk + 3day + 8hr + 10min + 16sec + 121ms + 11us + 12ns
|
1wk + 3day + 8hr + 10min + 16sec + 121ms + 11us + 12ns
|
||||||
"#
|
"#
|
||||||
@ -403,8 +370,7 @@ fn duration_decimal_math_with_all_units() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn duration_decimal_dans_test() {
|
fn duration_decimal_dans_test() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
3.14sec
|
3.14sec
|
||||||
"#
|
"#
|
||||||
@ -415,8 +381,7 @@ fn duration_decimal_dans_test() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn duration_math_with_negative() {
|
fn duration_math_with_negative() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1day - 1wk
|
1day - 1wk
|
||||||
"#
|
"#
|
||||||
@ -427,8 +392,7 @@ fn duration_math_with_negative() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compound_comparison() {
|
fn compound_comparison() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
4 > 3 and 2 > 1
|
4 > 3 and 2 > 1
|
||||||
"#
|
"#
|
||||||
@ -439,8 +403,7 @@ fn compound_comparison() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compound_comparison2() {
|
fn compound_comparison2() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
4 < 3 or 2 > 1
|
4 < 3 or 2 > 1
|
||||||
"#
|
"#
|
||||||
@ -451,8 +414,7 @@ fn compound_comparison2() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compound_where() {
|
fn compound_where() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from json | where a == 2 and b == 1 | to json -r
|
echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from json | where a == 2 and b == 1 | to json -r
|
||||||
"#
|
"#
|
||||||
@ -463,8 +425,7 @@ fn compound_where() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compound_where_paren() {
|
fn compound_where_paren() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from json | where ($it.a == 2 and $it.b == 1) or $it.b == 2 | to json -r
|
echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from json | where ($it.a == 2 and $it.b == 1) or $it.b == 2 | to json -r
|
||||||
"#
|
"#
|
||||||
@ -477,8 +438,7 @@ fn compound_where_paren() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn adding_lists() {
|
fn adding_lists() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[1 3] ++ [5 6] | to nuon
|
[1 3] ++ [5 6] | to nuon
|
||||||
"#
|
"#
|
||||||
@ -489,8 +449,7 @@ fn adding_lists() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn adding_list_and_value() {
|
fn adding_list_and_value() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[1 3] ++ 5 | to nuon
|
[1 3] ++ 5 | to nuon
|
||||||
"#
|
"#
|
||||||
@ -501,8 +460,7 @@ fn adding_list_and_value() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn adding_value_and_list() {
|
fn adding_value_and_list() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1 ++ [3 5] | to nuon
|
1 ++ [3 5] | to nuon
|
||||||
"#
|
"#
|
||||||
@ -513,8 +471,7 @@ fn adding_value_and_list() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn adding_tables() {
|
fn adding_tables() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[[a b]; [1 2]] ++ [[c d]; [10 11]] | to nuon
|
[[a b]; [1 2]] ++ [[c d]; [10 11]] | to nuon
|
||||||
"#
|
"#
|
||||||
@ -524,8 +481,7 @@ fn adding_tables() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn append_strings() {
|
fn append_strings() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
"foo" ++ "bar"
|
"foo" ++ "bar"
|
||||||
"#
|
"#
|
||||||
@ -535,8 +491,7 @@ fn append_strings() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn append_binary_values() {
|
fn append_binary_values() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
0x[01 02] ++ 0x[03 04] | to nuon
|
0x[01 02] ++ 0x[03 04] | to nuon
|
||||||
"#
|
"#
|
||||||
@ -546,28 +501,16 @@ fn append_binary_values() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn int_multiple_string() {
|
fn int_multiple_string() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(r#"3 * "ab""#));
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"3 * "ab""#
|
|
||||||
));
|
|
||||||
assert_eq!(actual.out, "ababab");
|
assert_eq!(actual.out, "ababab");
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(r#""ab" * 3"#));
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#""ab" * 3"#
|
|
||||||
));
|
|
||||||
assert_eq!(actual.out, "ababab");
|
assert_eq!(actual.out, "ababab");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn int_multiple_list() {
|
fn int_multiple_list() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(r#"3 * [1 2] | to nuon"#));
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"3 * [1 2] | to nuon"#
|
|
||||||
));
|
|
||||||
assert_eq!(actual.out, "[1, 2, 1, 2, 1, 2]");
|
assert_eq!(actual.out, "[1, 2, 1, 2, 1, 2]");
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(r#"[1 2] * 3 | to nuon"#));
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"[1 2] * 3 | to nuon"#
|
|
||||||
));
|
|
||||||
assert_eq!(actual.out, "[1, 2, 1, 2, 1, 2]");
|
assert_eq!(actual.out, "[1, 2, 1, 2, 1, 2]");
|
||||||
}
|
}
|
||||||
|
@ -2,30 +2,21 @@ use nu_test_support::nu;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_sqrt_numbers() {
|
fn can_sqrt_numbers() {
|
||||||
let actual = nu!(
|
let actual = nu!("echo [0.25 2 4] | math sqrt | math sum");
|
||||||
cwd: ".",
|
|
||||||
"echo [0.25 2 4] | math sqrt | math sum"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "3.914213562373095");
|
assert_eq!(actual.out, "3.914213562373095");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_sqrt_irrational() {
|
fn can_sqrt_irrational() {
|
||||||
let actual = nu!(
|
let actual = nu!("echo 2 | math sqrt");
|
||||||
cwd: ".",
|
|
||||||
"echo 2 | math sqrt"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "1.4142135623730951");
|
assert_eq!(actual.out, "1.4142135623730951");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_sqrt_perfect_square() {
|
fn can_sqrt_perfect_square() {
|
||||||
let actual = nu!(
|
let actual = nu!("echo 4 | math sqrt");
|
||||||
cwd: ".",
|
|
||||||
"echo 4 | math sqrt"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "2");
|
assert_eq!(actual.out, "2");
|
||||||
}
|
}
|
||||||
|
@ -44,12 +44,9 @@ fn row() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn single_record_no_overwrite() {
|
fn single_record_no_overwrite() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
nu!(
|
nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
{a: 1, b: 5} | merge {c: 2} | to nuon
|
{a: 1, b: 5} | merge {c: 2} | to nuon
|
||||||
"#
|
"#)
|
||||||
))
|
|
||||||
.out,
|
.out,
|
||||||
"{a: 1, b: 5, c: 2}"
|
"{a: 1, b: 5, c: 2}"
|
||||||
);
|
);
|
||||||
@ -58,12 +55,9 @@ fn single_record_no_overwrite() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn single_record_overwrite() {
|
fn single_record_overwrite() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
nu!(
|
nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
{a: 1, b: 2} | merge {a: 2} | to nuon
|
{a: 1, b: 2} | merge {a: 2} | to nuon
|
||||||
"#
|
"#)
|
||||||
))
|
|
||||||
.out,
|
.out,
|
||||||
"{a: 2, b: 2}"
|
"{a: 2, b: 2}"
|
||||||
);
|
);
|
||||||
@ -72,12 +66,9 @@ fn single_record_overwrite() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn single_row_table_overwrite() {
|
fn single_row_table_overwrite() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
nu!(
|
nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
[[a b]; [1 4]] | merge [[a b]; [2 4]] | to nuon
|
[[a b]; [1 4]] | merge [[a b]; [2 4]] | to nuon
|
||||||
"#
|
"#)
|
||||||
))
|
|
||||||
.out,
|
.out,
|
||||||
"[[a, b]; [2, 4]]"
|
"[[a, b]; [2, 4]]"
|
||||||
);
|
);
|
||||||
@ -86,12 +77,9 @@ fn single_row_table_overwrite() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn single_row_table_no_overwrite() {
|
fn single_row_table_no_overwrite() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
nu!(
|
nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
[[a b]; [1 4]] | merge [[c d]; [2 4]] | to nuon
|
[[a b]; [1 4]] | merge [[c d]; [2 4]] | to nuon
|
||||||
"#
|
"#)
|
||||||
))
|
|
||||||
.out,
|
.out,
|
||||||
"[[a, b, c, d]; [1, 4, 2, 4]]"
|
"[[a, b, c, d]; [1, 4, 2, 4]]"
|
||||||
);
|
);
|
||||||
@ -100,12 +88,9 @@ fn single_row_table_no_overwrite() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn multi_row_table_no_overwrite() {
|
fn multi_row_table_no_overwrite() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
nu!(
|
nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
[[a b]; [1 4] [8 9] [9 9]] | merge [[c d]; [2 4]] | to nuon
|
[[a b]; [1 4] [8 9] [9 9]] | merge [[c d]; [2 4]] | to nuon
|
||||||
"#
|
"#)
|
||||||
))
|
|
||||||
.out,
|
.out,
|
||||||
"[{a: 1, b: 4, c: 2, d: 4}, {a: 8, b: 9}, {a: 9, b: 9}]"
|
"[{a: 1, b: 4, c: 2, d: 4}, {a: 8, b: 9}, {a: 9, b: 9}]"
|
||||||
);
|
);
|
||||||
@ -114,12 +99,9 @@ fn multi_row_table_no_overwrite() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn multi_row_table_overwrite() {
|
fn multi_row_table_overwrite() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
nu!(
|
nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
[[a b]; [1 4] [8 9] [9 9]] | merge [[a b]; [7 7]] | to nuon
|
[[a b]; [1 4] [8 9] [9 9]] | merge [[a b]; [7 7]] | to nuon
|
||||||
"#
|
"#)
|
||||||
))
|
|
||||||
.out,
|
.out,
|
||||||
"[[a, b]; [7, 7], [8, 9], [9, 9]]"
|
"[[a, b]; [7, 7], [8, 9], [9, 9]]"
|
||||||
);
|
);
|
||||||
|
@ -1,25 +1,19 @@
|
|||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::nu;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mut_variable() {
|
fn mut_variable() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut x = 3; $x = $x + 1; $x
|
mut x = 3; $x = $x + 1; $x
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "4");
|
assert_eq!(actual.out, "4");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mut_name_builtin_var() {
|
fn mut_name_builtin_var() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut in = 3
|
mut in = 3
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual
|
assert!(actual
|
||||||
.err
|
.err
|
||||||
@ -28,12 +22,9 @@ fn mut_name_builtin_var() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mut_name_builtin_var_with_dollar() {
|
fn mut_name_builtin_var_with_dollar() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut $env = 3
|
mut $env = 3
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual
|
assert!(actual
|
||||||
.err
|
.err
|
||||||
@ -42,139 +33,106 @@ fn mut_name_builtin_var_with_dollar() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mut_variable_in_loop() {
|
fn mut_variable_in_loop() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut x = 1; for i in 1..10 { $x = $x + $i}; $x
|
mut x = 1; for i in 1..10 { $x = $x + $i}; $x
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "56");
|
assert_eq!(actual.out, "56");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn capture_of_mutable_var() {
|
fn capture_of_mutable_var() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut x = 123; {|| $x }
|
mut x = 123; {|| $x }
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.err.contains("capture of mutable variable"));
|
assert!(actual.err.contains("capture of mutable variable"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mut_add_assign() {
|
fn mut_add_assign() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut y = 3; $y += 2; $y
|
mut y = 3; $y += 2; $y
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "5");
|
assert_eq!(actual.out, "5");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mut_minus_assign() {
|
fn mut_minus_assign() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut y = 3; $y -= 2; $y
|
mut y = 3; $y -= 2; $y
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "1");
|
assert_eq!(actual.out, "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mut_multiply_assign() {
|
fn mut_multiply_assign() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut y = 3; $y *= 2; $y
|
mut y = 3; $y *= 2; $y
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "6");
|
assert_eq!(actual.out, "6");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mut_divide_assign() {
|
fn mut_divide_assign() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut y = 8; $y /= 2; $y
|
mut y = 8; $y /= 2; $y
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "4");
|
assert_eq!(actual.out, "4");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mut_path_insert() {
|
fn mut_path_insert() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut y = {abc: 123}; $y.abc = 456; $y.abc
|
mut y = {abc: 123}; $y.abc = 456; $y.abc
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "456");
|
assert_eq!(actual.out, "456");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mut_path_insert_list() {
|
fn mut_path_insert_list() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut a = [0 1 2]; $a.3 = 3; $a | to nuon
|
mut a = [0 1 2]; $a.3 = 3; $a | to nuon
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "[0, 1, 2, 3]");
|
assert_eq!(actual.out, "[0, 1, 2, 3]");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mut_path_upsert() {
|
fn mut_path_upsert() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut a = {b:[{c:1}]}; $a.b.0.d = 11; $a.b.0.d
|
mut a = {b:[{c:1}]}; $a.b.0.d = 11; $a.b.0.d
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "11");
|
assert_eq!(actual.out, "11");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mut_path_upsert_list() {
|
fn mut_path_upsert_list() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut a = [[[3] 2] 1]; $a.0.0.1 = 0; $a.0.2 = 0; $a.2 = 0; $a | to nuon
|
mut a = [[[3] 2] 1]; $a.0.0.1 = 0; $a.0.2 = 0; $a.2 = 0; $a | to nuon
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "[[[3, 0], 2, 0], 1, 0]");
|
assert_eq!(actual.out, "[[[3, 0], 2, 0], 1, 0]");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mut_path_operator_assign() {
|
fn mut_path_operator_assign() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
mut a = {b:1}; $a.b += 3; $a.b -= 2; $a.b *= 10; $a.b /= 4; $a.b
|
mut a = {b:1}; $a.b += 3; $a.b -= 2; $a.b *= 10; $a.b /= 4; $a.b
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "5");
|
assert_eq!(actual.out, "5");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mut_records_update_properly() {
|
fn mut_records_update_properly() {
|
||||||
let actual = nu!(pipeline("mut a = {}; $a.b.c = 100; $a.b.c"));
|
let actual = nu!("mut a = {}; $a.b.c = 100; $a.b.c");
|
||||||
assert_eq!(actual.out, "100");
|
assert_eq!(actual.out, "100");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,12 +4,7 @@ use std::sync::mpsc;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn port_with_invalid_range() {
|
fn port_with_invalid_range() {
|
||||||
let actual = nu!(
|
let actual = nu!("port 4000 3999");
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
port 4000 3999
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.err.contains("Invalid range"))
|
assert!(actual.err.contains("Invalid range"))
|
||||||
}
|
}
|
||||||
@ -29,9 +24,7 @@ fn port_with_already_usage() {
|
|||||||
let _listener = TcpListener::bind(format!("127.0.0.1:{free_port}"));
|
let _listener = TcpListener::bind(format!("127.0.0.1:{free_port}"));
|
||||||
let _ = rx.recv();
|
let _ = rx.recv();
|
||||||
});
|
});
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(&format!("port {free_port} {free_port}")));
|
||||||
cwd: ".", pipeline(&format!("port {free_port} {free_port}"))
|
|
||||||
);
|
|
||||||
let _ = tx.send(true);
|
let _ = tx.send(true);
|
||||||
// make sure that the thread is closed and we release the port.
|
// make sure that the thread is closed and we release the port.
|
||||||
handler.join().unwrap();
|
handler.join().unwrap();
|
||||||
@ -46,12 +39,7 @@ fn port_with_already_usage() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn port_from_system_given() {
|
fn port_from_system_given() {
|
||||||
let actual = nu!(
|
let actual = nu!("port");
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
port
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
// check that we can get an integer port from system.
|
// check that we can get an integer port from system.
|
||||||
assert!(actual.out.parse::<u16>().unwrap() > 0)
|
assert!(actual.out.parse::<u16>().unwrap() > 0)
|
||||||
|
@ -291,12 +291,9 @@ fn open_ignore_ansi() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn open_no_parameter() {
|
fn open_no_parameter() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: "tests/fixtures/formats",
|
|
||||||
r#"
|
|
||||||
open
|
open
|
||||||
"#
|
"#);
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual.err.contains("needs filename"));
|
assert!(actual.err.contains("needs filename"));
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::nu;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn par_each_does_not_flatten_nested_structures() {
|
fn par_each_does_not_flatten_nested_structures() {
|
||||||
// This is a regression test for issue #8497
|
// This is a regression test for issue #8497
|
||||||
let actual = nu!(
|
let actual = nu!(r#"[1 2 3] | par-each { |it| [$it, $it] } | sort | to json --raw"#);
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"[1 2 3] | par-each { |it| [$it, $it] } | sort | to json --raw"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "[[1,1],[2,2],[3,3]]");
|
assert_eq!(actual.out, "[[1,1],[2,2],[3,3]]");
|
||||||
}
|
}
|
||||||
|
@ -192,10 +192,8 @@ mod regex {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_works_with_streaming() {
|
fn parse_works_with_streaming() {
|
||||||
let actual = nu!(
|
let actual =
|
||||||
cwd: ".", pipeline(
|
nu!(r#"seq char a z | each {|c| $c + " a"} | parse '{letter} {a}' | describe"#);
|
||||||
r#"seq char a z | each {|c| $c + " a"} | parse '{letter} {a}' | describe"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "table<letter: string, a: string> (stream)")
|
assert_eq!(actual.out, "table<letter: string, a: string> (stream)")
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,6 @@ fn checks_if_double_dot_exists() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn checks_tilde_relative_path_exists() {
|
fn checks_tilde_relative_path_exists() {
|
||||||
let actual = nu!(cwd: ".", "'~' | path exists");
|
let actual = nu!("'~' | path exists");
|
||||||
assert_eq!(actual.out, "true");
|
assert_eq!(actual.out, "true");
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,7 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ansi_shows_error_on_escape() {
|
fn test_ansi_shows_error_on_escape() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
ansi -e \
|
ansi -e \
|
||||||
"#
|
"#
|
||||||
|
@ -1,23 +1,15 @@
|
|||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::nu;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn print_to_stdout() {
|
fn print_to_stdout() {
|
||||||
let actual = nu!(
|
let actual = nu!("print 'hello world'");
|
||||||
cwd: ".", pipeline(
|
|
||||||
"print 'hello world'"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
assert!(actual.out.contains("hello world"));
|
assert!(actual.out.contains("hello world"));
|
||||||
assert!(actual.err.is_empty());
|
assert!(actual.err.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn print_to_stderr() {
|
fn print_to_stderr() {
|
||||||
let actual = nu!(
|
let actual = nu!("print -e 'hello world'");
|
||||||
cwd: ".", pipeline(
|
|
||||||
"print -e 'hello world'"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
assert!(actual.out.is_empty());
|
assert!(actual.out.is_empty());
|
||||||
assert!(actual.err.contains("hello world"));
|
assert!(actual.err.contains("hello world"));
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::nu;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generates_a_bool() {
|
fn generates_a_bool() {
|
||||||
let actual = nu!(
|
let actual = nu!("random bool");
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
random bool
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
let output = actual.out;
|
let output = actual.out;
|
||||||
let is_boolean_output = output == "true" || output == "false";
|
let is_boolean_output = output == "true" || output == "false";
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::nu;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generates_chars_of_specified_length() {
|
fn generates_chars_of_specified_length() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
random chars -l 15 | size | get chars
|
random chars -l 15 | size | get chars
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
let result = actual.out;
|
let result = actual.out;
|
||||||
assert_eq!(result, "15");
|
assert_eq!(result, "15");
|
||||||
|
@ -1,37 +1,22 @@
|
|||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::nu;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generates_a_decimal() {
|
fn generates_a_decimal() {
|
||||||
let actual = nu!(
|
let actual = nu!("random decimal 42..43");
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
random decimal 42..43
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains("42") || actual.out.contains("43"));
|
assert!(actual.out.contains("42") || actual.out.contains("43"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generates_55() {
|
fn generates_55() {
|
||||||
let actual = nu!(
|
let actual = nu!("random decimal 55..55");
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
random decimal 55..55
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains("55"));
|
assert!(actual.out.contains("55"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generates_0() {
|
fn generates_0() {
|
||||||
let actual = nu!(
|
let actual = nu!(" random decimal ..<1 ");
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
random decimal ..<1
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains('0'));
|
assert!(actual.out.contains('0'));
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::nu;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rolls_4_roll() {
|
fn rolls_4_roll() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
random dice -d 4 -s 10 | length
|
random dice -d 4 -s 10 | length
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "4");
|
assert_eq!(actual.out, "4");
|
||||||
}
|
}
|
||||||
|
@ -1,37 +1,22 @@
|
|||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::nu;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generates_an_integer() {
|
fn generates_an_integer() {
|
||||||
let actual = nu!(
|
let actual = nu!("random integer 42..43");
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
random integer 42..43
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains("42") || actual.out.contains("43"));
|
assert!(actual.out.contains("42") || actual.out.contains("43"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generates_55() {
|
fn generates_55() {
|
||||||
let actual = nu!(
|
let actual = nu!("random integer 55..55");
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
random integer 55..55
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains("55"));
|
assert!(actual.out.contains("55"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generates_0() {
|
fn generates_0() {
|
||||||
let actual = nu!(
|
let actual = nu!("random integer ..<1");
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
random integer ..<1
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains('0'));
|
assert!(actual.out.contains('0'));
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,7 @@ use uuid_crate::Uuid;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generates_valid_uuid4() {
|
fn generates_valid_uuid4() {
|
||||||
let actual = nu!(
|
let actual = nu!("random uuid");
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
random uuid
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
let result = Uuid::parse_str(actual.out.as_str());
|
let result = Uuid::parse_str(actual.out.as_str());
|
||||||
|
|
||||||
|
@ -2,8 +2,7 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reduce_table_column() {
|
fn reduce_table_column() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo "[{month:2,total:30}, {month:3,total:10}, {month:4,total:3}, {month:5,total:60}]"
|
echo "[{month:2,total:30}, {month:3,total:10}, {month:4,total:3}, {month:5,total:60}]"
|
||||||
| from json
|
| from json
|
||||||
@ -11,45 +10,39 @@ fn reduce_table_column() {
|
|||||||
| reduce -f 20 { |it, acc| $it + $acc ** 1.05}
|
| reduce -f 20 { |it, acc| $it + $acc ** 1.05}
|
||||||
| into string -d 1
|
| into string -d 1
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "180.6");
|
assert_eq!(actual.out, "180.6");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reduce_table_column_with_path() {
|
fn reduce_table_column_with_path() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[{month:2,total:30}, {month:3,total:10}, {month:4,total:3}, {month:5,total:60}]
|
[{month:2,total:30}, {month:3,total:10}, {month:4,total:3}, {month:5,total:60}]
|
||||||
| reduce -f 20 { |it, acc| $it.total + $acc ** 1.05}
|
| reduce -f 20 { |it, acc| $it.total + $acc ** 1.05}
|
||||||
| into string -d 1
|
| into string -d 1
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "180.6");
|
assert_eq!(actual.out, "180.6");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reduce_rows_example() {
|
fn reduce_rows_example() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[[a,b]; [1,2] [3,4]]
|
[[a,b]; [1,2] [3,4]]
|
||||||
| reduce -f 1.6 { |it, acc| $acc * ($it.a | into int) + ($it.b | into int) }
|
| reduce -f 1.6 { |it, acc| $acc * ($it.a | into int) + ($it.b | into int) }
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "14.8");
|
assert_eq!(actual.out, "14.8");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reduce_with_return_in_closure() {
|
fn reduce_with_return_in_closure() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[1, 2] | reduce --fold null { |it, state|
|
[1, 2] | reduce --fold null { |it, state|
|
||||||
if $it == 1 {
|
if $it == 1 {
|
||||||
@ -58,8 +51,7 @@ fn reduce_with_return_in_closure() {
|
|||||||
return ($it * $state)
|
return ($it * $state)
|
||||||
}
|
}
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "20");
|
assert_eq!(actual.out, "20");
|
||||||
assert!(actual.err.is_empty());
|
assert!(actual.err.is_empty());
|
||||||
@ -67,39 +59,34 @@ fn reduce_with_return_in_closure() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reduce_enumerate_example() {
|
fn reduce_enumerate_example() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo one longest three bar | enumerate
|
echo one longest three bar | enumerate
|
||||||
| reduce { |it, acc| if ($it.item | str length) > ($acc.item | str length) {echo $it} else {echo $acc}}
|
| reduce { |it, acc| if ($it.item | str length) > ($acc.item | str length) {echo $it} else {echo $acc}}
|
||||||
| get index
|
| get index
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "1");
|
assert_eq!(actual.out, "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reduce_enumerate_integer_addition_example() {
|
fn reduce_enumerate_integer_addition_example() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo [1 2 3 4]
|
echo [1 2 3 4]
|
||||||
| enumerate
|
| enumerate
|
||||||
| reduce { |it, acc| { index: ($it.index) item: ($acc.item + $it.item)} }
|
| reduce { |it, acc| { index: ($it.index) item: ($acc.item + $it.item)} }
|
||||||
| get item
|
| get item
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "10");
|
assert_eq!(actual.out, "10");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn folding_with_tables() {
|
fn folding_with_tables() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo [10 20 30 40]
|
echo [10 20 30 40]
|
||||||
| reduce -f [] { |it, acc|
|
| reduce -f [] { |it, acc|
|
||||||
@ -109,47 +96,40 @@ fn folding_with_tables() {
|
|||||||
}
|
}
|
||||||
| math sum
|
| math sum
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "1000");
|
assert_eq!(actual.out, "1000");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_reduce_fold_type_mismatch() {
|
fn error_reduce_fold_type_mismatch() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo a b c | reduce -f 0 { |it, acc| $acc + $it }
|
echo a b c | reduce -f 0 { |it, acc| $acc + $it }
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual.err.contains("mismatch"));
|
assert!(actual.err.contains("mismatch"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_reduce_empty() {
|
fn error_reduce_empty() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
reduce { |it, acc| $acc + $it }
|
reduce { |it, acc| $acc + $it }
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual.err.contains("needs input"));
|
assert!(actual.err.contains("needs input"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn enumerate_reduce_example() {
|
fn enumerate_reduce_example() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[one longest three bar] | enumerate | reduce {|it, acc| if ($it.item | str length) > ($acc.item | str length) { $it } else { $acc }} | get index
|
[one longest three bar] | enumerate | reduce {|it, acc| if ($it.item | str length) > ($acc.item | str length) { $it } else { $acc }} | get index
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "1");
|
assert_eq!(actual.out, "1");
|
||||||
}
|
}
|
||||||
|
@ -2,24 +2,18 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn early_return_if_true() {
|
fn early_return_if_true() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
def foo [x] { if true { return 2 }; $x }; foo 100
|
def foo [x] { if true { return 2 }; $x }; foo 100
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, r#"2"#);
|
assert_eq!(actual.out, r#"2"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn early_return_if_false() {
|
fn early_return_if_false() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
def foo [x] { if false { return 2 }; $x }; foo 100
|
def foo [x] { if false { return 2 }; $x }; foo 100
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, r#"100"#);
|
assert_eq!(actual.out, r#"100"#);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::nu;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_get_reverse_first() {
|
fn can_get_reverse_first() {
|
||||||
@ -12,7 +12,7 @@ fn can_get_reverse_first() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fail_on_non_iterator() {
|
fn fail_on_non_iterator() {
|
||||||
let actual = nu!(cwd: ".", pipeline("1 | reverse"));
|
let actual = nu!("1 | reverse");
|
||||||
|
|
||||||
assert!(actual.err.contains("command doesn't support"));
|
assert!(actual.err.contains("command doesn't support"));
|
||||||
}
|
}
|
||||||
|
@ -19,26 +19,34 @@ mod rows {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_roll_down() {
|
fn can_roll_down() {
|
||||||
let actual = nu!(
|
let actual = nu!(format!(
|
||||||
cwd: ".",
|
"{} | {}",
|
||||||
format!("{} | {}", table(), pipeline(r#"
|
table(),
|
||||||
|
pipeline(
|
||||||
|
r#"
|
||||||
roll down
|
roll down
|
||||||
| first
|
| first
|
||||||
| get status
|
| get status
|
||||||
"#)));
|
"#
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
assert_eq!(actual.out, "HERE");
|
assert_eq!(actual.out, "HERE");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_roll_up() {
|
fn can_roll_up() {
|
||||||
let actual = nu!(
|
let actual = nu!(format!(
|
||||||
cwd: ".",
|
"{} | {}",
|
||||||
format!("{} | {}", table(), pipeline(r#"
|
table(),
|
||||||
|
pipeline(
|
||||||
|
r#"
|
||||||
roll up --by 3
|
roll up --by 3
|
||||||
| first
|
| first
|
||||||
| get status
|
| get status
|
||||||
"#)));
|
"#
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
assert_eq!(actual.out, "HERE");
|
assert_eq!(actual.out, "HERE");
|
||||||
}
|
}
|
||||||
@ -64,26 +72,34 @@ mod columns {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_roll_left() {
|
fn can_roll_left() {
|
||||||
let actual = nu!(
|
let actual = nu!(format!(
|
||||||
cwd: ".",
|
"{} | {}",
|
||||||
format!("{} | {}", table(), pipeline(r#"
|
table(),
|
||||||
|
pipeline(
|
||||||
|
r#"
|
||||||
roll left
|
roll left
|
||||||
| columns
|
| columns
|
||||||
| str join "-"
|
| str join "-"
|
||||||
"#)));
|
"#
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
assert_eq!(actual.out, "origin-stars-commit_author");
|
assert_eq!(actual.out, "origin-stars-commit_author");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_roll_right() {
|
fn can_roll_right() {
|
||||||
let actual = nu!(
|
let actual = nu!(format!(
|
||||||
cwd: ".",
|
"{} | {}",
|
||||||
format!("{} | {}", table(), pipeline(r#"
|
table(),
|
||||||
|
pipeline(
|
||||||
|
r#"
|
||||||
roll right --by 2
|
roll right --by 2
|
||||||
| columns
|
| columns
|
||||||
| str join "-"
|
| str join "-"
|
||||||
"#)));
|
"#
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
assert_eq!(actual.out, "origin-stars-commit_author");
|
assert_eq!(actual.out, "origin-stars-commit_author");
|
||||||
}
|
}
|
||||||
@ -95,10 +111,9 @@ mod columns {
|
|||||||
let four_bitstring = bitstring_to_nu_row_pipeline("00000100");
|
let four_bitstring = bitstring_to_nu_row_pipeline("00000100");
|
||||||
let expected_value = ThirtyTwo(32, "bit1-bit2-bit3-bit4-bit5-bit6-bit7-bit8");
|
let expected_value = ThirtyTwo(32, "bit1-bit2-bit3-bit4-bit5-bit6-bit7-bit8");
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(format!(
|
||||||
cwd: ".",
|
"{four_bitstring} | roll right --by 3 --cells-only | columns | str join '-' "
|
||||||
format!("{four_bitstring} | roll right --by 3 --cells-only | columns | str join '-' ")
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, expected_value.1);
|
assert_eq!(actual.out, expected_value.1);
|
||||||
}
|
}
|
||||||
@ -146,7 +161,6 @@ mod columns {
|
|||||||
"{bitstring_as_nu_row_pipeline} | roll left --by 3 | {nu_row_literal_bitstring_to_decimal_value_pipeline}"
|
"{bitstring_as_nu_row_pipeline} | roll left --by 3 | {nu_row_literal_bitstring_to_decimal_value_pipeline}"
|
||||||
);
|
);
|
||||||
nu!(
|
nu!(
|
||||||
cwd: ".",
|
|
||||||
format!("{bitstring_as_nu_row_pipeline} | roll left --by 3 | {nu_row_literal_bitstring_to_decimal_value_pipeline}")
|
format!("{bitstring_as_nu_row_pipeline} | roll left --by 3 | {nu_row_literal_bitstring_to_decimal_value_pipeline}")
|
||||||
).out
|
).out
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ fn counter_clockwise() {
|
|||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected = nu!(cwd: ".", pipeline(
|
let expected = nu!(pipeline(
|
||||||
r#"
|
r#"
|
||||||
echo [
|
echo [
|
||||||
[ column0, column1, column2, column3];
|
[ column0, column1, column2, column3];
|
||||||
@ -29,14 +29,18 @@ fn counter_clockwise() {
|
|||||||
"#,
|
"#,
|
||||||
));
|
));
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(format!(
|
||||||
cwd: ".",
|
"{} | {}",
|
||||||
format!("{} | {}", table, pipeline(r#"
|
table,
|
||||||
|
pipeline(
|
||||||
|
r#"
|
||||||
rotate --ccw
|
rotate --ccw
|
||||||
| where column0 == EXPECTED
|
| where column0 == EXPECTED
|
||||||
| get column1 column2 column3
|
| get column1 column2 column3
|
||||||
| str join "-"
|
| str join "-"
|
||||||
"#)));
|
"#
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
assert_eq!(actual.out, expected.out);
|
assert_eq!(actual.out, expected.out);
|
||||||
}
|
}
|
||||||
@ -55,7 +59,7 @@ fn clockwise() {
|
|||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected = nu!(cwd: ".", pipeline(
|
let expected = nu!(pipeline(
|
||||||
r#"
|
r#"
|
||||||
echo [
|
echo [
|
||||||
[ column0, column1, column2, column3];
|
[ column0, column1, column2, column3];
|
||||||
@ -70,14 +74,18 @@ fn clockwise() {
|
|||||||
"#,
|
"#,
|
||||||
));
|
));
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(format!(
|
||||||
cwd: ".",
|
"{} | {}",
|
||||||
format!("{} | {}", table, pipeline(r#"
|
table,
|
||||||
|
pipeline(
|
||||||
|
r#"
|
||||||
rotate
|
rotate
|
||||||
| where column3 == EXPECTED
|
| where column3 == EXPECTED
|
||||||
| get column0 column1 column2
|
| get column0 column1 column2
|
||||||
| str join "-"
|
| str join "-"
|
||||||
"#)));
|
"#
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
assert_eq!(actual.out, expected.out);
|
assert_eq!(actual.out, expected.out);
|
||||||
}
|
}
|
||||||
|
@ -312,7 +312,7 @@ fn can_run_batch_files_without_bat_extension() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn quotes_trimmed_when_shelling_out() {
|
fn quotes_trimmed_when_shelling_out() {
|
||||||
// regression test for a bug where we weren't trimming quotes around string args before shelling out to cmd.exe
|
// regression test for a bug where we weren't trimming quotes around string args before shelling out to cmd.exe
|
||||||
let actual = nu!(cwd: ".", pipeline(
|
let actual = nu!(pipeline(
|
||||||
r#"
|
r#"
|
||||||
^echo "foo"
|
^echo "foo"
|
||||||
"#
|
"#
|
||||||
|
@ -17,7 +17,7 @@ fn binary_skip() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fail_on_non_iterator() {
|
fn fail_on_non_iterator() {
|
||||||
let actual = nu!(cwd: ".", pipeline("1 | skip 2"));
|
let actual = nu!("1 | skip 2");
|
||||||
|
|
||||||
assert!(actual.err.contains("command doesn't support"));
|
assert!(actual.err.contains("command doesn't support"));
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ fn condition_is_met() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fail_on_non_iterator() {
|
fn fail_on_non_iterator() {
|
||||||
let actual = nu!(cwd: ".", pipeline("1 | skip until {|row| $row == 2}"));
|
let actual = nu!("1 | skip until {|row| $row == 2}");
|
||||||
|
|
||||||
assert!(actual.err.contains("command doesn't support"));
|
assert!(actual.err.contains("command doesn't support"));
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ fn condition_is_met() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fail_on_non_iterator() {
|
fn fail_on_non_iterator() {
|
||||||
let actual = nu!(cwd: ".", pipeline("1 | skip while {|row| $row == 2}"));
|
let actual = nu!("1 | skip while {|row| $row == 2}");
|
||||||
|
|
||||||
assert!(actual.err.contains("command doesn't support"));
|
assert!(actual.err.contains("command doesn't support"));
|
||||||
}
|
}
|
||||||
|
@ -2,39 +2,33 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_1() {
|
fn test_1() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo 1..5 | into string | str join
|
echo 1..5 | into string | str join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "12345");
|
assert_eq!(actual.out, "12345");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_2() {
|
fn test_2() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo [a b c d] | str join "<sep>"
|
echo [a b c d] | str join "<sep>"
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "a<sep>b<sep>c<sep>d");
|
assert_eq!(actual.out, "a<sep>b<sep>c<sep>d");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn construct_a_path() {
|
fn construct_a_path() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo [sample txt] | str join "."
|
echo [sample txt] | str join "."
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "sample.txt");
|
assert_eq!(actual.out, "sample.txt");
|
||||||
}
|
}
|
||||||
|
@ -4,65 +4,45 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_range() {
|
fn from_range() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo 1..5 | into string | to json -r
|
echo 1..5 | into string | to json -r
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "[\"1\",\"2\",\"3\",\"4\",\"5\"]");
|
assert_eq!(actual.out, "[\"1\",\"2\",\"3\",\"4\",\"5\"]");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_number() {
|
fn from_number() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo 5 | into string
|
echo 5 | into string
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "5");
|
assert_eq!(actual.out, "5");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_decimal() {
|
fn from_decimal() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo 1.5 | into string
|
echo 1.5 | into string
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "1.5");
|
assert_eq!(actual.out, "1.5");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_boolean() {
|
fn from_boolean() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo true | into string
|
echo true | into string
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "true");
|
assert_eq!(actual.out, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_string() {
|
fn from_string() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo "one" | into string
|
echo "one" | into string
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "one");
|
assert_eq!(actual.out, "one");
|
||||||
}
|
}
|
||||||
@ -111,44 +91,34 @@ fn from_filesize() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_decimal_correct_trailing_zeros() {
|
fn from_decimal_correct_trailing_zeros() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
1.23000 | into string -d 3
|
1.23000 | into string -d 3
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains("1.230"));
|
assert!(actual.out.contains("1.230"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_int_decimal_correct_trailing_zeros() {
|
fn from_int_decimal_correct_trailing_zeros() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
1.00000 | into string -d 3
|
1.00000 | into string -d 3
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains("1.000"));
|
assert!(actual.out.contains("1.000"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_int_decimal_trim_trailing_zeros() {
|
fn from_int_decimal_trim_trailing_zeros() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
1.00000 | into string | $"($in) flat"
|
1.00000 | into string | $"($in) flat"
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains("1 flat")); // "1" would match "1.0"
|
assert!(actual.out.contains("1 flat")); // "1" would match "1.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_table() {
|
fn from_table() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo '[{"name": "foo", "weight": 32.377}, {"name": "bar", "weight": 15.2}]'
|
echo '[{"name": "foo", "weight": 32.377}, {"name": "bar", "weight": 15.2}]'
|
||||||
| from json
|
| from json
|
||||||
@ -162,24 +132,18 @@ fn from_table() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_nothing() {
|
fn from_nothing() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
null | into string
|
null | into string
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "");
|
assert_eq!(actual.out, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn int_into_string() {
|
fn int_into_string() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
10 | into string
|
10 | into string
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "10");
|
assert_eq!(actual.out, "10");
|
||||||
}
|
}
|
||||||
|
@ -27,13 +27,11 @@ fn trims() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_trim_multiple_chars() {
|
fn error_trim_multiple_chars() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo "does it work now?!" | str trim -c "?!"
|
echo "does it work now?!" | str trim -c "?!"
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual.err.contains("char"));
|
assert!(actual.err.contains("char"));
|
||||||
}
|
}
|
||||||
@ -120,8 +118,7 @@ fn camelcases() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn converts_to_int() {
|
fn converts_to_int() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo '[{number_as_string: "1"}]'
|
echo '[{number_as_string: "1"}]'
|
||||||
| from json
|
| from json
|
||||||
@ -138,8 +135,7 @@ fn converts_to_int() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn converts_to_decimal() {
|
fn converts_to_decimal() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo "3.1, 0.0415"
|
echo "3.1, 0.0415"
|
||||||
| split row ","
|
| split row ","
|
||||||
@ -366,24 +362,18 @@ fn substrings_the_input_and_treats_end_index_as_length_if_blank_end_index_given(
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn str_reverse() {
|
fn str_reverse() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo "nushell" | str reverse
|
echo "nushell" | str reverse
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.out.contains("llehsun"));
|
assert!(actual.out.contains("llehsun"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_redirection_trim() {
|
fn test_redirection_trim() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
let x = (nu --testbin cococo niceone); $x | str trim | str length
|
let x = (nu --testbin cococo niceone); $x | str trim | str length
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "7");
|
assert_eq!(actual.out, "7");
|
||||||
}
|
}
|
||||||
|
@ -32,24 +32,14 @@ fn rows() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rows_with_no_arguments_should_lead_to_error() {
|
fn rows_with_no_arguments_should_lead_to_error() {
|
||||||
Playground::setup("take_test_2", |dirs, _sandbox| {
|
let actual = nu!("[1 2 3] | take");
|
||||||
let actual = nu!(
|
|
||||||
cwd: dirs.test(), pipeline(
|
|
||||||
r#"[1 2 3] | take"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.err.contains("missing_positional"));
|
assert!(actual.err.contains("missing_positional"));
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fails_on_string() {
|
fn fails_on_string() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#""foo bar" | take 2"#);
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
"foo bar" | take 2
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.err.contains("command doesn't support"));
|
assert!(actual.err.contains("command doesn't support"));
|
||||||
}
|
}
|
||||||
@ -57,12 +47,9 @@ fn fails_on_string() {
|
|||||||
#[test]
|
#[test]
|
||||||
// covers a situation where `take` used to behave strangely on list<binary> input
|
// covers a situation where `take` used to behave strangely on list<binary> input
|
||||||
fn works_with_binary_list() {
|
fn works_with_binary_list() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
([0x[01 11]] | take 1 | get 0) == 0x[01 11]
|
||||||
r#"
|
"#);
|
||||||
([0x[01 11]] | take 1 | get 0) == 0x[01 11]
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "true");
|
assert_eq!(actual.out, "true");
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ fn condition_is_met() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fail_on_non_iterator() {
|
fn fail_on_non_iterator() {
|
||||||
let actual = nu!(cwd: ".", pipeline("1 | take until {|row| $row == 2}"));
|
let actual = nu!("1 | take until {|row| $row == 2}");
|
||||||
|
|
||||||
assert!(actual.err.contains("command doesn't support"));
|
assert!(actual.err.contains("command doesn't support"));
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ fn condition_is_met() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fail_on_non_iterator() {
|
fn fail_on_non_iterator() {
|
||||||
let actual = nu!(cwd: ".", pipeline("1 | take while {|row| $row == 2}"));
|
let actual = nu!("1 | take while {|row| $row == 2}");
|
||||||
|
|
||||||
assert!(actual.err.contains("command doesn't support"));
|
assert!(actual.err.contains("command doesn't support"));
|
||||||
}
|
}
|
||||||
|
@ -2,83 +2,61 @@ use nu_test_support::nu;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn try_succeed() {
|
fn try_succeed() {
|
||||||
let output = nu!(
|
let output = nu!("try { 345 } catch { echo 'hello' }");
|
||||||
cwd: ".",
|
|
||||||
"try { 345 } catch { echo 'hello' }"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(output.out.contains("345"));
|
assert!(output.out.contains("345"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn try_catch() {
|
fn try_catch() {
|
||||||
let output = nu!(
|
let output = nu!("try { foobarbaz } catch { echo 'hello' }");
|
||||||
cwd: ".",
|
|
||||||
"try { foobarbaz } catch { echo 'hello' }"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(output.out.contains("hello"));
|
assert!(output.out.contains("hello"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn catch_can_access_error() {
|
fn catch_can_access_error() {
|
||||||
let output = nu!(
|
let output = nu!("try { foobarbaz } catch { |err| $err | get raw }");
|
||||||
cwd: ".",
|
|
||||||
"try { foobarbaz } catch { |err| $err | get raw }"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(output.err.contains("External command failed"));
|
assert!(output.err.contains("External command failed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn catch_can_access_error_as_dollar_in() {
|
fn catch_can_access_error_as_dollar_in() {
|
||||||
let output = nu!(
|
let output = nu!("try { foobarbaz } catch { $in | get raw }");
|
||||||
cwd: ".",
|
|
||||||
"try { foobarbaz } catch { $in | get raw }"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(output.err.contains("External command failed"));
|
assert!(output.err.contains("External command failed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn external_failed_should_be_caught() {
|
fn external_failed_should_be_caught() {
|
||||||
let output = nu!(
|
let output = nu!("try { nu --testbin fail; echo 'success' } catch { echo 'fail' }");
|
||||||
cwd: ".",
|
|
||||||
"try { nu --testbin fail; echo 'success' } catch { echo 'fail' }"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(output.out.contains("fail"));
|
assert!(output.out.contains("fail"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn loop_try_break_should_be_successful() {
|
fn loop_try_break_should_be_successful() {
|
||||||
let output = nu!(
|
let output =
|
||||||
cwd: ".",
|
nu!("loop { try { print 'successful'; break } catch { print 'failed'; continue } }");
|
||||||
"loop { try { print 'successful'; break } catch { print 'failed'; continue } }"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(output.out, "successful");
|
assert_eq!(output.out, "successful");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn loop_catch_break_should_show_failed() {
|
fn loop_catch_break_should_show_failed() {
|
||||||
let output = nu!(
|
let output = nu!("loop {
|
||||||
cwd: ".",
|
|
||||||
"loop {
|
|
||||||
try { invalid 1;
|
try { invalid 1;
|
||||||
continue; } catch { print 'failed'; break }
|
continue; } catch { print 'failed'; break }
|
||||||
}
|
}
|
||||||
"
|
");
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(output.out, "failed");
|
assert_eq!(output.out, "failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn loop_try_ignores_continue() {
|
fn loop_try_ignores_continue() {
|
||||||
let output = nu!(
|
let output = nu!("mut total = 0;
|
||||||
cwd: ".",
|
|
||||||
"mut total = 0;
|
|
||||||
for i in 0..10 {
|
for i in 0..10 {
|
||||||
try { if ($i mod 2) == 0 {
|
try { if ($i mod 2) == 0 {
|
||||||
continue;}
|
continue;}
|
||||||
@ -86,27 +64,20 @@ fn loop_try_ignores_continue() {
|
|||||||
} catch { echo 'failed'; break }
|
} catch { echo 'failed'; break }
|
||||||
}
|
}
|
||||||
echo $total
|
echo $total
|
||||||
"
|
");
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(output.out, "5");
|
assert_eq!(output.out, "5");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn loop_try_break_on_command_should_show_successful() {
|
fn loop_try_break_on_command_should_show_successful() {
|
||||||
let output = nu!(
|
let output = nu!("loop { try { ls; break } catch { echo 'failed';continue }}");
|
||||||
cwd: ".",
|
|
||||||
"loop { try { ls; break } catch { echo 'failed';continue }}"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(!output.out.contains("failed"));
|
assert!(!output.out.contains("failed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn catch_block_can_use_error_object() {
|
fn catch_block_can_use_error_object() {
|
||||||
let output = nu!(
|
let output = nu!("try {1 / 0} catch {|err| print ($err | get msg)}");
|
||||||
cwd: ".",
|
|
||||||
"try {1 / 0} catch {|err| print ($err | get msg)}"
|
|
||||||
);
|
|
||||||
assert_eq!(output.out, "Division by zero.")
|
assert_eq!(output.out, "Division by zero.")
|
||||||
}
|
}
|
||||||
|
@ -68,9 +68,8 @@ fn sets_the_column_from_a_subexpression() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn upsert_uses_enumerate_index_inserting() {
|
fn upsert_uses_enumerate_index_inserting() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"[[a]; [7] [6]] | enumerate | upsert b {|el| $el.index + 1 + $el.item.a } | flatten | to nuon"#
|
r#"[[a]; [7] [6]] | enumerate | upsert b {|el| $el.index + 1 + $el.item.a } | flatten | to nuon"#
|
||||||
));
|
);
|
||||||
|
|
||||||
assert_eq!(actual.out, "[[index, a, b]; [0, 7, 8], [1, 6, 8]]");
|
assert_eq!(actual.out, "[[index, a, b]; [0, 7, 8], [1, 6, 8]]");
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,8 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_simple() {
|
fn url_join_simple() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"username": "",
|
"username": "",
|
||||||
@ -13,17 +12,15 @@ fn url_join_simple() {
|
|||||||
"port": "",
|
"port": "",
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "http://localhost");
|
assert_eq!(actual.out, "http://localhost");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_with_only_user() {
|
fn url_join_with_only_user() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"username": "usr",
|
"username": "usr",
|
||||||
@ -32,17 +29,15 @@ fn url_join_with_only_user() {
|
|||||||
"port": "",
|
"port": "",
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "http://localhost");
|
assert_eq!(actual.out, "http://localhost");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_with_only_pwd() {
|
fn url_join_with_only_pwd() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"username": "",
|
"username": "",
|
||||||
@ -51,17 +46,15 @@ fn url_join_with_only_pwd() {
|
|||||||
"port": "",
|
"port": "",
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "http://localhost");
|
assert_eq!(actual.out, "http://localhost");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_with_user_and_pwd() {
|
fn url_join_with_user_and_pwd() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"username": "usr",
|
"username": "usr",
|
||||||
@ -70,17 +63,15 @@ fn url_join_with_user_and_pwd() {
|
|||||||
"port": "",
|
"port": "",
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "http://usr:pwd@localhost");
|
assert_eq!(actual.out, "http://usr:pwd@localhost");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_with_query() {
|
fn url_join_with_query() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"username": "usr",
|
"username": "usr",
|
||||||
@ -90,17 +81,15 @@ fn url_join_with_query() {
|
|||||||
"port": "",
|
"port": "",
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "http://usr:pwd@localhost?par_1=aaa&par_2=bbb");
|
assert_eq!(actual.out, "http://usr:pwd@localhost?par_1=aaa&par_2=bbb");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_with_params() {
|
fn url_join_with_params() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"username": "usr",
|
"username": "usr",
|
||||||
@ -113,8 +102,7 @@ fn url_join_with_params() {
|
|||||||
"port": "1234",
|
"port": "1234",
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
actual.out,
|
actual.out,
|
||||||
@ -124,9 +112,8 @@ fn url_join_with_params() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_with_same_query_and_params() {
|
fn url_join_with_same_query_and_params() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"username": "usr",
|
"username": "usr",
|
||||||
@ -140,8 +127,7 @@ fn url_join_with_same_query_and_params() {
|
|||||||
"port": "1234",
|
"port": "1234",
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
actual.out,
|
actual.out,
|
||||||
@ -151,9 +137,8 @@ fn url_join_with_same_query_and_params() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_with_different_query_and_params() {
|
fn url_join_with_different_query_and_params() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"username": "usr",
|
"username": "usr",
|
||||||
@ -167,8 +152,7 @@ fn url_join_with_different_query_and_params() {
|
|||||||
"port": "1234",
|
"port": "1234",
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual
|
assert!(actual
|
||||||
.err
|
.err
|
||||||
@ -177,9 +161,8 @@ fn url_join_with_different_query_and_params() {
|
|||||||
.err
|
.err
|
||||||
.contains("instead query is: ?par_1=aaa&par_2=bbb"));
|
.contains("instead query is: ?par_1=aaa&par_2=bbb"));
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"username": "usr",
|
"username": "usr",
|
||||||
@ -193,8 +176,7 @@ fn url_join_with_different_query_and_params() {
|
|||||||
"port": "1234",
|
"port": "1234",
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual
|
assert!(actual
|
||||||
.err
|
.err
|
||||||
@ -206,9 +188,8 @@ fn url_join_with_different_query_and_params() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_with_invalid_params() {
|
fn url_join_with_invalid_params() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"username": "usr",
|
"username": "usr",
|
||||||
@ -218,72 +199,63 @@ fn url_join_with_invalid_params() {
|
|||||||
"port": "1234",
|
"port": "1234",
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual.err.contains("Key params has to be a record"));
|
assert!(actual.err.contains("Key params has to be a record"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_with_port() {
|
fn url_join_with_port() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"host": "localhost",
|
"host": "localhost",
|
||||||
"port": "1234",
|
"port": "1234",
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "http://localhost:1234");
|
assert_eq!(actual.out, "http://localhost:1234");
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"host": "localhost",
|
"host": "localhost",
|
||||||
"port": 1234,
|
"port": 1234,
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "http://localhost:1234");
|
assert_eq!(actual.out, "http://localhost:1234");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_with_invalid_port() {
|
fn url_join_with_invalid_port() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"host": "localhost",
|
"host": "localhost",
|
||||||
"port": "aaaa",
|
"port": "aaaa",
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual
|
assert!(actual
|
||||||
.err
|
.err
|
||||||
.contains("Port parameter should represent an unsigned integer"));
|
.contains("Port parameter should represent an unsigned integer"));
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"host": "localhost",
|
"host": "localhost",
|
||||||
"port": [],
|
"port": [],
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual
|
assert!(actual
|
||||||
.err
|
.err
|
||||||
@ -292,39 +264,34 @@ fn url_join_with_invalid_port() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_with_missing_scheme() {
|
fn url_join_with_missing_scheme() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"host": "localhost"
|
"host": "localhost"
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual.err.contains("missing parameter: scheme"));
|
assert!(actual.err.contains("missing parameter: scheme"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_with_missing_host() {
|
fn url_join_with_missing_host() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "https"
|
"scheme": "https"
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert!(actual.err.contains("missing parameter: host"));
|
assert!(actual.err.contains("missing parameter: host"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_with_fragment() {
|
fn url_join_with_fragment() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"username": "usr",
|
"username": "usr",
|
||||||
@ -334,17 +301,15 @@ fn url_join_with_fragment() {
|
|||||||
"port": "1234",
|
"port": "1234",
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "http://usr:pwd@localhost:1234#frag");
|
assert_eq!(actual.out, "http://usr:pwd@localhost:1234#frag");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_with_fragment_and_params() {
|
fn url_join_with_fragment_and_params() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "http",
|
"scheme": "http",
|
||||||
"username": "usr",
|
"username": "usr",
|
||||||
@ -358,8 +323,7 @@ fn url_join_with_fragment_and_params() {
|
|||||||
"fragment": "frag"
|
"fragment": "frag"
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
actual.out,
|
actual.out,
|
||||||
@ -369,9 +333,8 @@ fn url_join_with_fragment_and_params() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_join_with_empty_params() {
|
fn url_join_with_empty_params() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
{
|
{
|
||||||
"scheme": "https",
|
"scheme": "https",
|
||||||
"host": "localhost",
|
"host": "localhost",
|
||||||
@ -379,8 +342,7 @@ fn url_join_with_empty_params() {
|
|||||||
"params": {}
|
"params": {}
|
||||||
} | url join
|
} | url join
|
||||||
"#
|
"#
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "https://localhost/foo");
|
assert_eq!(actual.out, "https://localhost/foo");
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,8 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_parse_simple() {
|
fn url_parse_simple() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
("https://www.abc.com"
|
("https://www.abc.com"
|
||||||
| url parse)
|
| url parse)
|
||||||
== {
|
== {
|
||||||
@ -25,9 +24,8 @@ fn url_parse_simple() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_parse_with_port() {
|
fn url_parse_with_port() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
("https://www.abc.com:8011"
|
("https://www.abc.com:8011"
|
||||||
| url parse)
|
| url parse)
|
||||||
== {
|
== {
|
||||||
@ -49,9 +47,8 @@ fn url_parse_with_port() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_parse_with_path() {
|
fn url_parse_with_path() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
("http://www.abc.com:8811/def/ghj"
|
("http://www.abc.com:8811/def/ghj"
|
||||||
| url parse)
|
| url parse)
|
||||||
== {
|
== {
|
||||||
@ -73,9 +70,8 @@ fn url_parse_with_path() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_parse_with_params() {
|
fn url_parse_with_params() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
("http://www.abc.com:8811/def/ghj?param1=11¶m2="
|
("http://www.abc.com:8811/def/ghj?param1=11¶m2="
|
||||||
| url parse)
|
| url parse)
|
||||||
== {
|
== {
|
||||||
@ -97,9 +93,8 @@ fn url_parse_with_params() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_parse_with_fragment() {
|
fn url_parse_with_fragment() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
("http://www.abc.com:8811/def/ghj?param1=11¶m2=#hello-fragment"
|
("http://www.abc.com:8811/def/ghj?param1=11¶m2=#hello-fragment"
|
||||||
| url parse)
|
| url parse)
|
||||||
== {
|
== {
|
||||||
@ -121,9 +116,8 @@ fn url_parse_with_fragment() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_parse_with_username_and_password() {
|
fn url_parse_with_username_and_password() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
("http://user123:password567@www.abc.com:8811/def/ghj?param1=11¶m2=#hello-fragment"
|
("http://user123:password567@www.abc.com:8811/def/ghj?param1=11¶m2=#hello-fragment"
|
||||||
| url parse)
|
| url parse)
|
||||||
== {
|
== {
|
||||||
@ -145,13 +139,7 @@ fn url_parse_with_username_and_password() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_parse_error_empty_url() {
|
fn url_parse_error_empty_url() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#""" | url parse"#);
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
""
|
|
||||||
| url parse
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert!(actual.err.contains(
|
assert!(actual.err.contains(
|
||||||
"Incomplete or incorrect URL. Expected a full URL, e.g., https://www.example.com"
|
"Incomplete or incorrect URL. Expected a full URL, e.g., https://www.example.com"
|
||||||
|
@ -186,13 +186,9 @@ fn use_export_env_combined() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn use_module_creates_accurate_did_you_mean_1() {
|
fn use_module_creates_accurate_did_you_mean_1() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
module spam { export def foo [] { "foo" } }; use spam; foo
|
module spam { export def foo [] { "foo" } }; use spam; foo
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
assert!(actual.err.contains(
|
assert!(actual.err.contains(
|
||||||
"command 'foo' was not found but it was imported from module 'spam'; try using `spam foo`"
|
"command 'foo' was not found but it was imported from module 'spam'; try using `spam foo`"
|
||||||
));
|
));
|
||||||
@ -200,13 +196,9 @@ fn use_module_creates_accurate_did_you_mean_1() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn use_module_creates_accurate_did_you_mean_2() {
|
fn use_module_creates_accurate_did_you_mean_2() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
module spam { export def foo [] { "foo" } }; foo
|
module spam { export def foo [] { "foo" } }; foo
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
assert!(actual.err.contains(
|
assert!(actual.err.contains(
|
||||||
"command 'foo' was not found but it exists in module 'spam'; try importing it with `use`"
|
"command 'foo' was not found but it exists in module 'spam'; try importing it with `use`"
|
||||||
));
|
));
|
||||||
@ -220,7 +212,7 @@ fn use_main_1() {
|
|||||||
r#"spam"#,
|
r#"spam"#,
|
||||||
];
|
];
|
||||||
|
|
||||||
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
|
let actual = nu!(&inp.join("; "));
|
||||||
|
|
||||||
assert_eq!(actual.out, "spam");
|
assert_eq!(actual.out, "spam");
|
||||||
}
|
}
|
||||||
@ -233,7 +225,7 @@ fn use_main_2() {
|
|||||||
r#"spam"#,
|
r#"spam"#,
|
||||||
];
|
];
|
||||||
|
|
||||||
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
|
let actual = nu!(&inp.join("; "));
|
||||||
|
|
||||||
assert_eq!(actual.out, "spam");
|
assert_eq!(actual.out, "spam");
|
||||||
}
|
}
|
||||||
@ -246,7 +238,7 @@ fn use_main_3() {
|
|||||||
r#"spam"#,
|
r#"spam"#,
|
||||||
];
|
];
|
||||||
|
|
||||||
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
|
let actual = nu!(&inp.join("; "));
|
||||||
|
|
||||||
assert_eq!(actual.out, "spam");
|
assert_eq!(actual.out, "spam");
|
||||||
}
|
}
|
||||||
@ -259,7 +251,7 @@ fn use_main_4() {
|
|||||||
r#"spam"#,
|
r#"spam"#,
|
||||||
];
|
];
|
||||||
|
|
||||||
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
|
let actual = nu!(&inp.join("; "));
|
||||||
|
|
||||||
assert_eq!(actual.out, "spam");
|
assert_eq!(actual.out, "spam");
|
||||||
}
|
}
|
||||||
@ -273,7 +265,7 @@ fn use_main_def_env() {
|
|||||||
r#"$env.SPAM"#,
|
r#"$env.SPAM"#,
|
||||||
];
|
];
|
||||||
|
|
||||||
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
|
let actual = nu!(&inp.join("; "));
|
||||||
|
|
||||||
assert_eq!(actual.out, "spam");
|
assert_eq!(actual.out, "spam");
|
||||||
}
|
}
|
||||||
@ -287,7 +279,7 @@ fn use_main_def_known_external() {
|
|||||||
r#"cargo --version"#,
|
r#"cargo --version"#,
|
||||||
];
|
];
|
||||||
|
|
||||||
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
|
let actual = nu!(&inp.join("; "));
|
||||||
|
|
||||||
assert!(actual.out.contains("cargo"));
|
assert!(actual.out.contains("cargo"));
|
||||||
}
|
}
|
||||||
@ -300,7 +292,7 @@ fn use_main_not_exported() {
|
|||||||
r#"spam"#,
|
r#"spam"#,
|
||||||
];
|
];
|
||||||
|
|
||||||
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
|
let actual = nu!(&inp.join("; "));
|
||||||
|
|
||||||
assert!(actual.err.contains("external_command"));
|
assert!(actual.err.contains("external_command"));
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,7 @@ fn filters_with_nothing_comparison() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn where_inside_block_works() {
|
fn where_inside_block_works() {
|
||||||
let actual = nu!(
|
let actual = nu!("{|x| ls | where $it =~ 'foo' } | describe");
|
||||||
cwd: ".",
|
|
||||||
"{|x| ls | where $it =~ 'foo' } | describe"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "closure");
|
assert_eq!(actual.out, "closure");
|
||||||
}
|
}
|
||||||
@ -178,7 +175,7 @@ fn contains_operator() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fail_on_non_iterator() {
|
fn fail_on_non_iterator() {
|
||||||
let actual = nu!(cwd: ".", pipeline(r#"{"name": "foo", "size": 3} | where name == "foo""#));
|
let actual = nu!(r#"{"name": "foo", "size": 3} | where name == "foo""#);
|
||||||
|
|
||||||
assert!(actual.err.contains("command doesn't support"));
|
assert!(actual.err.contains("command doesn't support"));
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,7 @@ use nu_test_support::nu;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn which_ls() {
|
fn which_ls() {
|
||||||
let actual = nu!(
|
let actual = nu!("which ls | get path.0 | str trim");
|
||||||
cwd: ".",
|
|
||||||
"which ls | get path.0 | str trim"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "Nushell built-in command");
|
assert_eq!(actual.out, "Nushell built-in command");
|
||||||
}
|
}
|
||||||
@ -13,20 +10,14 @@ fn which_ls() {
|
|||||||
#[ignore = "TODO: Can't have alias recursion"]
|
#[ignore = "TODO: Can't have alias recursion"]
|
||||||
#[test]
|
#[test]
|
||||||
fn which_alias_ls() {
|
fn which_alias_ls() {
|
||||||
let actual = nu!(
|
let actual = nu!("alias ls = ls -a; which ls | get path.0 | str trim");
|
||||||
cwd: ".",
|
|
||||||
"alias ls = ls -a; which ls | get path.0 | str trim"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "Nushell alias: ls -a");
|
assert_eq!(actual.out, "Nushell alias: ls -a");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn which_custom_alias() {
|
fn which_custom_alias() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"alias foo = print "foo!"; which foo | to nuon"#);
|
||||||
cwd: ".",
|
|
||||||
r#"alias foo = print "foo!"; which foo | to nuon"#
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
actual.out,
|
actual.out,
|
||||||
@ -36,10 +27,7 @@ fn which_custom_alias() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn which_def_ls() {
|
fn which_def_ls() {
|
||||||
let actual = nu!(
|
let actual = nu!("def ls [] {echo def}; which ls | get path.0 | str trim");
|
||||||
cwd: ".",
|
|
||||||
"def ls [] {echo def}; which ls | get path.0 | str trim"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "Nushell custom command");
|
assert_eq!(actual.out, "Nushell custom command");
|
||||||
}
|
}
|
||||||
@ -47,10 +35,8 @@ fn which_def_ls() {
|
|||||||
#[ignore = "TODO: Can't have alias with the same name as command"]
|
#[ignore = "TODO: Can't have alias with the same name as command"]
|
||||||
#[test]
|
#[test]
|
||||||
fn correct_precedence_alias_def_custom() {
|
fn correct_precedence_alias_def_custom() {
|
||||||
let actual = nu!(
|
let actual =
|
||||||
cwd: ".",
|
nu!("def ls [] {echo def}; alias ls = echo alias; which ls | get path.0 | str trim");
|
||||||
"def ls [] {echo def}; alias ls = echo alias; which ls | get path.0 | str trim"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "Nushell alias: echo alias");
|
assert_eq!(actual.out, "Nushell alias: echo alias");
|
||||||
}
|
}
|
||||||
@ -58,10 +44,7 @@ fn correct_precedence_alias_def_custom() {
|
|||||||
#[ignore = "TODO: Can't have alias with the same name as command"]
|
#[ignore = "TODO: Can't have alias with the same name as command"]
|
||||||
#[test]
|
#[test]
|
||||||
fn multiple_reports_for_alias_def_custom() {
|
fn multiple_reports_for_alias_def_custom() {
|
||||||
let actual = nu!(
|
let actual = nu!("def ls [] {echo def}; alias ls = echo alias; which -a ls | length");
|
||||||
cwd: ".",
|
|
||||||
"def ls [] {echo def}; alias ls = echo alias; which -a ls | length"
|
|
||||||
);
|
|
||||||
|
|
||||||
let length: i32 = actual.out.parse().unwrap();
|
let length: i32 = actual.out.parse().unwrap();
|
||||||
assert!(length >= 2);
|
assert!(length >= 2);
|
||||||
@ -75,30 +58,24 @@ fn multiple_reports_for_alias_def_custom() {
|
|||||||
#[ignore]
|
#[ignore]
|
||||||
#[test]
|
#[test]
|
||||||
fn correctly_report_of_shadowed_alias() {
|
fn correctly_report_of_shadowed_alias() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"alias xaz = echo alias1
|
||||||
cwd: ".",
|
|
||||||
r#"alias xaz = echo alias1
|
|
||||||
def helper [] {
|
def helper [] {
|
||||||
alias xaz = echo alias2
|
alias xaz = echo alias2
|
||||||
which -a xaz
|
which -a xaz
|
||||||
}
|
}
|
||||||
helper | get path | str contains alias2"#
|
helper | get path | str contains alias2"#);
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "true");
|
assert_eq!(actual.out, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn one_report_of_multiple_defs() {
|
fn one_report_of_multiple_defs() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"def xaz [] { echo def1 }
|
||||||
cwd: ".",
|
|
||||||
r#"def xaz [] { echo def1 }
|
|
||||||
def helper [] {
|
def helper [] {
|
||||||
def xaz [] { echo def2 }
|
def xaz [] { echo def2 }
|
||||||
which -a xaz
|
which -a xaz
|
||||||
}
|
}
|
||||||
helper | length"#
|
helper | length"#);
|
||||||
);
|
|
||||||
|
|
||||||
let length: i32 = actual.out.parse().unwrap();
|
let length: i32 = actual.out.parse().unwrap();
|
||||||
assert_eq!(length, 1);
|
assert_eq!(length, 1);
|
||||||
@ -106,10 +83,7 @@ fn one_report_of_multiple_defs() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn def_only_seen_once() {
|
fn def_only_seen_once() {
|
||||||
let actual = nu!(
|
let actual = nu!("def xaz [] {echo def1}; which -a xaz | length");
|
||||||
cwd: ".",
|
|
||||||
"def xaz [] {echo def1}; which -a xaz | length"
|
|
||||||
);
|
|
||||||
|
|
||||||
let length: i32 = actual.out.parse().unwrap();
|
let length: i32 = actual.out.parse().unwrap();
|
||||||
assert_eq!(length, 1);
|
assert_eq!(length, 1);
|
||||||
@ -117,12 +91,9 @@ fn def_only_seen_once() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn do_not_show_hidden_aliases() {
|
fn do_not_show_hidden_aliases() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"alias foo = echo foo
|
||||||
cwd: ".",
|
|
||||||
r#"alias foo = echo foo
|
|
||||||
hide foo
|
hide foo
|
||||||
which foo | length"#
|
which foo | length"#);
|
||||||
);
|
|
||||||
|
|
||||||
let length: i32 = actual.out.parse().unwrap();
|
let length: i32 = actual.out.parse().unwrap();
|
||||||
assert_eq!(length, 0);
|
assert_eq!(length, 0);
|
||||||
@ -130,12 +101,9 @@ fn do_not_show_hidden_aliases() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn do_not_show_hidden_commands() {
|
fn do_not_show_hidden_commands() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"def foo [] { echo foo }
|
||||||
cwd: ".",
|
|
||||||
r#"def foo [] { echo foo }
|
|
||||||
hide foo
|
hide foo
|
||||||
which foo | length"#
|
which foo | length"#);
|
||||||
);
|
|
||||||
|
|
||||||
let length: i32 = actual.out.parse().unwrap();
|
let length: i32 = actual.out.parse().unwrap();
|
||||||
assert_eq!(length, 0);
|
assert_eq!(length, 0);
|
||||||
|
@ -3,7 +3,6 @@ use nu_test_support::nu;
|
|||||||
#[test]
|
#[test]
|
||||||
fn while_sum() {
|
fn while_sum() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
|
||||||
"mut total = 0; mut x = 0; while $x <= 10 { $total = $total + $x; $x = $x + 1 }; $total"
|
"mut total = 0; mut x = 0; while $x <= 10 { $total = $total + $x; $x = $x + 1 }; $total"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -12,10 +11,7 @@ fn while_sum() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn while_doesnt_auto_print_in_each_iteration() {
|
fn while_doesnt_auto_print_in_each_iteration() {
|
||||||
let actual = nu!(
|
let actual = nu!("mut total = 0; while $total < 2 { $total = $total + 1; echo 1 }");
|
||||||
cwd: ".",
|
|
||||||
"mut total = 0; while $total < 2 { $total = $total + 1; echo 1 }"
|
|
||||||
);
|
|
||||||
// Make sure we don't see any of these values in the output
|
// Make sure we don't see any of these values in the output
|
||||||
// As we do not auto-print loops anymore
|
// As we do not auto-print loops anymore
|
||||||
assert!(!actual.out.contains('1'));
|
assert!(!actual.out.contains('1'));
|
||||||
@ -23,10 +19,8 @@ fn while_doesnt_auto_print_in_each_iteration() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn while_break_on_external_failed() {
|
fn while_break_on_external_failed() {
|
||||||
let actual = nu!(
|
let actual =
|
||||||
cwd: ".",
|
nu!("mut total = 0; while $total < 2 { $total = $total + 1; print 1; nu --testbin fail }");
|
||||||
"mut total = 0; while $total < 2 { $total = $total + 1; print 1; nu --testbin fail }"
|
|
||||||
);
|
|
||||||
// Note: nu! macro auto replace "\n" and "\r\n" with ""
|
// Note: nu! macro auto replace "\n" and "\r\n" with ""
|
||||||
// so our output will be `1`
|
// so our output will be `1`
|
||||||
assert_eq!(actual.out, "1");
|
assert_eq!(actual.out, "1");
|
||||||
@ -34,9 +28,7 @@ fn while_break_on_external_failed() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn failed_while_should_break_running() {
|
fn failed_while_should_break_running() {
|
||||||
let actual = nu!(
|
let actual =
|
||||||
cwd: ".",
|
nu!("mut total = 0; while $total < 2 { $total = $total + 1; nu --testbin fail }; print 3");
|
||||||
"mut total = 0; while $total < 2 { $total = $total + 1; nu --testbin fail }; print 3"
|
|
||||||
);
|
|
||||||
assert!(!actual.out.contains('3'));
|
assert!(!actual.out.contains('3'));
|
||||||
}
|
}
|
||||||
|
@ -2,97 +2,71 @@ use nu_test_support::nu;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn with_env_extends_environment() {
|
fn with_env_extends_environment() {
|
||||||
let actual = nu!(
|
let actual = nu!("with-env [FOO BARRRR] {echo $env} | get FOO");
|
||||||
cwd: "tests/fixtures/formats",
|
|
||||||
"with-env [FOO BARRRR] {echo $env} | get FOO"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "BARRRR");
|
assert_eq!(actual.out, "BARRRR");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn with_env_shorthand() {
|
fn with_env_shorthand() {
|
||||||
let actual = nu!(
|
let actual = nu!("FOO=BARRRR echo $env | get FOO");
|
||||||
cwd: "tests/fixtures/formats",
|
|
||||||
"FOO=BARRRR echo $env | get FOO"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "BARRRR");
|
assert_eq!(actual.out, "BARRRR");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn shorthand_doesnt_reorder_arguments() {
|
fn shorthand_doesnt_reorder_arguments() {
|
||||||
let actual = nu!(
|
let actual = nu!("FOO=BARRRR nu --testbin cococo first second");
|
||||||
cwd: "tests/fixtures/formats",
|
|
||||||
"FOO=BARRRR nu --testbin cococo first second"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "first second");
|
assert_eq!(actual.out, "first second");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn with_env_shorthand_trims_quotes() {
|
fn with_env_shorthand_trims_quotes() {
|
||||||
let actual = nu!(
|
let actual = nu!("FOO='BARRRR' echo $env | get FOO");
|
||||||
cwd: "tests/fixtures/formats",
|
|
||||||
"FOO='BARRRR' echo $env | get FOO"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "BARRRR");
|
assert_eq!(actual.out, "BARRRR");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn with_env_and_shorthand_same_result() {
|
fn with_env_and_shorthand_same_result() {
|
||||||
let actual_shorthand = nu!(
|
let actual_shorthand = nu!("FOO='BARRRR' echo $env | get FOO");
|
||||||
cwd: "tests/fixtures/formats",
|
|
||||||
"FOO='BARRRR' echo $env | get FOO"
|
|
||||||
);
|
|
||||||
|
|
||||||
let actual_normal = nu!(
|
let actual_normal = nu!("with-env [FOO BARRRR] {echo $env} | get FOO");
|
||||||
cwd: "tests/fixtures/formats",
|
|
||||||
"with-env [FOO BARRRR] {echo $env} | get FOO"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual_shorthand.out, actual_normal.out);
|
assert_eq!(actual_shorthand.out, actual_normal.out);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_redirection2() {
|
fn test_redirection2() {
|
||||||
let actual = nu!(
|
let actual =
|
||||||
cwd: "tests/fixtures/formats",
|
nu!("let x = (FOO=BAR nu --testbin cococo niceenvvar); $x | str trim | str length");
|
||||||
"let x = (FOO=BAR nu --testbin cococo niceenvvar); $x | str trim | str length"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "10");
|
assert_eq!(actual.out, "10");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn with_env_hides_variables_in_parent_scope() {
|
fn with_env_hides_variables_in_parent_scope() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: "tests/fixtures/formats",
|
|
||||||
r#"
|
|
||||||
$env.FOO = "1"
|
$env.FOO = "1"
|
||||||
print $env.FOO
|
print $env.FOO
|
||||||
with-env [FOO null] {
|
with-env [FOO null] {
|
||||||
echo $env.FOO
|
echo $env.FOO
|
||||||
}
|
}
|
||||||
print $env.FOO
|
print $env.FOO
|
||||||
"#
|
"#);
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "11");
|
assert_eq!(actual.out, "11");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn with_env_shorthand_can_not_hide_variables() {
|
fn with_env_shorthand_can_not_hide_variables() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: "tests/fixtures/formats",
|
|
||||||
r#"
|
|
||||||
$env.FOO = "1"
|
$env.FOO = "1"
|
||||||
print $env.FOO
|
print $env.FOO
|
||||||
FOO=null print $env.FOO
|
FOO=null print $env.FOO
|
||||||
print $env.FOO
|
print $env.FOO
|
||||||
"#
|
"#);
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "1null1");
|
assert_eq!(actual.out, "1null1");
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,8 @@ fn zips_two_tables() {
|
|||||||
&format!("{ZIP_POWERED_TEST_ASSERTION_SCRIPT}\n"),
|
&format!("{ZIP_POWERED_TEST_ASSERTION_SCRIPT}\n"),
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(&format!(
|
||||||
cwd: ".", pipeline(
|
r#"
|
||||||
&format!(
|
|
||||||
r#"
|
|
||||||
use {} expect ;
|
use {} expect ;
|
||||||
|
|
||||||
let contributors = ([
|
let contributors = ([
|
||||||
@ -38,9 +36,8 @@ fn zips_two_tables() {
|
|||||||
|
|
||||||
expect $actual --to-eq [[name, commits]; [andres, 20] [jt, 30]]
|
expect $actual --to-eq [[name, commits]; [andres, 20] [jt, 30]]
|
||||||
"#,
|
"#,
|
||||||
dirs.test().join("zip_test.nu").display()
|
dirs.test().join("zip_test.nu").display()
|
||||||
)
|
)));
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "true");
|
assert_eq!(actual.out, "true");
|
||||||
})
|
})
|
||||||
@ -48,12 +45,9 @@ fn zips_two_tables() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn zips_two_lists() {
|
fn zips_two_lists() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo [0 2 4 6 8] | zip [1 3 5 7 9] | flatten | into string | str join '-'
|
echo [0 2 4 6 8] | zip [1 3 5 7 9] | flatten | into string | str join '-'
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "0-1-2-3-4-5-6-7-8-9");
|
assert_eq!(actual.out, "0-1-2-3-4-5-6-7-8-9");
|
||||||
}
|
}
|
||||||
|
@ -372,8 +372,7 @@ fn from_csv_text_with_wrong_type_separator() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn table_with_record_error() {
|
fn table_with_record_error() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[[a b]; [1 2] [3 {a: 1 b: 2}]]
|
[[a b]; [1 2] [3 {a: 1 b: 2}]]
|
||||||
| to csv
|
| to csv
|
||||||
@ -385,8 +384,7 @@ fn table_with_record_error() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn list_not_table_error() {
|
fn list_not_table_error() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[{a: 1 b: 2} {a: 3 b: 4} 1]
|
[{a: 1 b: 2} {a: 3 b: 4} 1]
|
||||||
| to csv
|
| to csv
|
||||||
@ -398,8 +396,7 @@ fn list_not_table_error() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn string_to_csv_error() {
|
fn string_to_csv_error() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
'qwe' | to csv
|
'qwe' | to csv
|
||||||
"#
|
"#
|
||||||
|
@ -2,8 +2,7 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn out_html_simple() {
|
fn out_html_simple() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
echo 3 | to html
|
echo 3 | to html
|
||||||
"#
|
"#
|
||||||
@ -17,12 +16,9 @@ fn out_html_simple() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn out_html_partial() {
|
fn out_html_partial() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo 3 | to html -p
|
echo 3 | to html -p
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
actual.out,
|
actual.out,
|
||||||
@ -32,12 +28,9 @@ fn out_html_partial() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn out_html_table() {
|
fn out_html_table() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo '{"name": "darren"}' | from json | to html
|
echo '{"name": "darren"}' | from json | to html
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
actual.out,
|
actual.out,
|
||||||
@ -48,13 +41,9 @@ fn out_html_table() {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn test_cd_html_color_flag_dark_false() {
|
fn test_cd_html_color_flag_dark_false() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
cd --help | to html --html-color
|
cd --help | to html --html-color
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
actual.out,
|
actual.out,
|
||||||
r"<html><style>body { background-color:white;color:black; }</style><body>Change directory.<br><br><span style='color:green;'>Usage<span style='color:black;font-weight:normal;'>:<br> > cd (path) <br><br></span></span><span style='color:green;'>Flags<span style='color:black;font-weight:normal;'>:<br> </span></span><span style='color:#037979;'>-h</span>,<span style='color:black;font-weight:normal;'> </span><span style='color:#037979;'>--help<span style='color:black;font-weight:normal;'> - Display the help message for this command<br><br></span><span style='color:green;'>Signatures<span style='color:black;font-weight:normal;'>:<br> <nothing> | cd <string?> -> <nothing><br> <string> | cd <string?> -> <nothing><br><br></span></span><span style='color:green;'>Parameters<span style='color:black;font-weight:normal;'>:<br> (optional) </span></span></span><span style='color:#037979;'>path<span style='color:black;font-weight:normal;'> <</span><span style='color:blue;font-weight:bold;'>directory<span style='color:black;font-weight:normal;'>>: the path to change to<br><br></span></span><span style='color:green;'>Examples<span style='color:black;font-weight:normal;'>:<br> Change to your home directory<br> > </span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'> </span></span></span></span><span style='color:#037979;'>~<span style='color:black;font-weight:normal;'><br><br> Change to a directory via abbreviations<br> > </span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'> </span></span></span><span style='color:#037979;'>d/s/9<span style='color:black;font-weight:normal;'><br><br> Change to the previous working directory ($OLDPWD)<br> > </span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'> </span></span></span><span style='color:#037979;'>-<span style='color:black;font-weight:normal;'><br><br></body></html></span></span>"
|
r"<html><style>body { background-color:white;color:black; }</style><body>Change directory.<br><br><span style='color:green;'>Usage<span style='color:black;font-weight:normal;'>:<br> > cd (path) <br><br></span></span><span style='color:green;'>Flags<span style='color:black;font-weight:normal;'>:<br> </span></span><span style='color:#037979;'>-h</span>,<span style='color:black;font-weight:normal;'> </span><span style='color:#037979;'>--help<span style='color:black;font-weight:normal;'> - Display the help message for this command<br><br></span><span style='color:green;'>Signatures<span style='color:black;font-weight:normal;'>:<br> <nothing> | cd <string?> -> <nothing><br> <string> | cd <string?> -> <nothing><br><br></span></span><span style='color:green;'>Parameters<span style='color:black;font-weight:normal;'>:<br> (optional) </span></span></span><span style='color:#037979;'>path<span style='color:black;font-weight:normal;'> <</span><span style='color:blue;font-weight:bold;'>directory<span style='color:black;font-weight:normal;'>>: the path to change to<br><br></span></span><span style='color:green;'>Examples<span style='color:black;font-weight:normal;'>:<br> Change to your home directory<br> > </span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'> </span></span></span></span><span style='color:#037979;'>~<span style='color:black;font-weight:normal;'><br><br> Change to a directory via abbreviations<br> > </span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'> </span></span></span><span style='color:#037979;'>d/s/9<span style='color:black;font-weight:normal;'><br><br> Change to the previous working directory ($OLDPWD)<br> > </span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'> </span></span></span><span style='color:#037979;'>-<span style='color:black;font-weight:normal;'><br><br></body></html></span></span>"
|
||||||
@ -63,13 +52,9 @@ fn test_cd_html_color_flag_dark_false() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_no_color_flag() {
|
fn test_no_color_flag() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
cd --help | to html --no-color
|
cd --help | to html --no-color
|
||||||
"#
|
"#);
|
||||||
)
|
|
||||||
);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
actual.out,
|
actual.out,
|
||||||
r"<html><style>body { background-color:white;color:black; }</style><body>Change directory.<br><br>Usage:<br> > cd (path) <br><br>Flags:<br> -h, --help - Display the help message for this command<br><br>Signatures:<br> <nothing> | cd <string?> -> <nothing><br> <string> | cd <string?> -> <nothing><br><br>Parameters:<br> path <directory>: the path to change to (optional)<br><br>Examples:<br> Change to your home directory<br> > cd ~<br><br> Change to a directory via abbreviations<br> > cd d/s/9<br><br> Change to the previous working directory ($OLDPWD)<br> > cd -<br><br></body></html>"
|
r"<html><style>body { background-color:white;color:black; }</style><body>Change directory.<br><br>Usage:<br> > cd (path) <br><br>Flags:<br> -h, --help - Display the help message for this command<br><br>Signatures:<br> <nothing> | cd <string?> -> <nothing><br> <string> | cd <string?> -> <nothing><br><br>Parameters:<br> path <directory>: the path to change to (optional)<br><br>Examples:<br> Change to your home directory<br> > cd ~<br><br> Change to a directory via abbreviations<br> > cd d/s/9<br><br> Change to the previous working directory ($OLDPWD)<br> > cd -<br><br></body></html>"
|
||||||
@ -78,10 +63,7 @@ fn test_no_color_flag() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_list() {
|
fn test_list() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"to html --list | where name == C64 | get 0 | to nuon"#);
|
||||||
cwd: ".",
|
|
||||||
r#"to html --list | where name == C64 | get 0 | to nuon"#
|
|
||||||
);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
actual.out,
|
actual.out,
|
||||||
r##"{name: "C64", black: "#090300", red: "#883932", green: "#55a049", yellow: "#bfce72", blue: "#40318d", purple: "#8b3f96", cyan: "#67b6bd", white: "#ffffff", brightBlack: "#000000", brightRed: "#883932", brightGreen: "#55a049", brightYellow: "#bfce72", brightBlue: "#40318d", brightPurple: "#8b3f96", brightCyan: "#67b6bd", brightWhite: "#f7f7f7", background: "#40318d", foreground: "#7869c4"}"##
|
r##"{name: "C64", black: "#090300", red: "#883932", green: "#55a049", yellow: "#bfce72", blue: "#40318d", purple: "#8b3f96", cyan: "#67b6bd", white: "#ffffff", brightBlack: "#000000", brightRed: "#883932", brightGreen: "#55a049", brightYellow: "#bfce72", brightBlue: "#40318d", brightPurple: "#8b3f96", brightCyan: "#67b6bd", brightWhite: "#f7f7f7", background: "#40318d", foreground: "#7869c4"}"##
|
||||||
|
@ -2,80 +2,61 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn md_empty() {
|
fn md_empty() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo [[]; []] | from json | to md
|
echo [[]; []] | from json | to md
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "");
|
assert_eq!(actual.out, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn md_empty_pretty() {
|
fn md_empty_pretty() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo "{}" | from json | to md -p
|
echo "{}" | from json | to md -p
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "");
|
assert_eq!(actual.out, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn md_simple() {
|
fn md_simple() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo 3 | to md
|
echo 3 | to md
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "3");
|
assert_eq!(actual.out, "3");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn md_simple_pretty() {
|
fn md_simple_pretty() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo 3 | to md -p
|
echo 3 | to md -p
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "3");
|
assert_eq!(actual.out, "3");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn md_table() {
|
fn md_table() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo [[name]; [jason]] | to md
|
echo [[name]; [jason]] | to md
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "|name||-||jason|");
|
assert_eq!(actual.out, "|name||-||jason|");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn md_table_pretty() {
|
fn md_table_pretty() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
|
||||||
echo [[name]; [joseph]] | to md -p
|
echo [[name]; [joseph]] | to md -p
|
||||||
"#
|
"#);
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "| name || ------ || joseph |");
|
assert_eq!(actual.out, "| name || ------ || joseph |");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn md_combined() {
|
fn md_combined() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: ".", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
def title [] {
|
def title [] {
|
||||||
echo [[H1]; ["Nu top meals"]]
|
echo [[H1]; ["Nu top meals"]]
|
||||||
|
@ -17,8 +17,7 @@ fn to_nuon_correct_compaction() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_list_of_numbers() {
|
fn to_nuon_list_of_numbers() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[1, 2, 3, 4]
|
[1, 2, 3, 4]
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -32,8 +31,7 @@ fn to_nuon_list_of_numbers() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_list_of_strings() {
|
fn to_nuon_list_of_strings() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[abc, xyz, def]
|
[abc, xyz, def]
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -47,8 +45,7 @@ fn to_nuon_list_of_strings() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_table() {
|
fn to_nuon_table() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
[[my, columns]; [abc, xyz], [def, ijk]]
|
[[my, columns]; [abc, xyz], [def, ijk]]
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -62,8 +59,7 @@ fn to_nuon_table() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_bool() {
|
fn to_nuon_bool() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
false
|
false
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -76,8 +72,7 @@ fn to_nuon_bool() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_escaping() {
|
fn to_nuon_escaping() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
"hello\"world"
|
"hello\"world"
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -90,8 +85,7 @@ fn to_nuon_escaping() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_escaping2() {
|
fn to_nuon_escaping2() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
"hello\\world"
|
"hello\\world"
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -104,8 +98,7 @@ fn to_nuon_escaping2() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_escaping3() {
|
fn to_nuon_escaping3() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
["hello\\world"]
|
["hello\\world"]
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -119,8 +112,7 @@ fn to_nuon_escaping3() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_escaping4() {
|
fn to_nuon_escaping4() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
["hello\"world"]
|
["hello\"world"]
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -134,8 +126,7 @@ fn to_nuon_escaping4() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_escaping5() {
|
fn to_nuon_escaping5() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
{s: "hello\"world"}
|
{s: "hello\"world"}
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -149,8 +140,7 @@ fn to_nuon_escaping5() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_negative_int() {
|
fn to_nuon_negative_int() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
-1
|
-1
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -163,8 +153,7 @@ fn to_nuon_negative_int() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_records() {
|
fn to_nuon_records() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
{name: "foo bar", age: 100, height: 10}
|
{name: "foo bar", age: 100, height: 10}
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -178,8 +167,7 @@ fn to_nuon_records() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_range() {
|
fn to_nuon_range() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1..42
|
1..42
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -191,8 +179,7 @@ fn to_nuon_range() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_nuon_range() {
|
fn from_nuon_range() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
"1..42"
|
"1..42"
|
||||||
| from nuon
|
| from nuon
|
||||||
@ -205,8 +192,7 @@ fn from_nuon_range() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_filesize() {
|
fn to_nuon_filesize() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1kib
|
1kib
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -218,8 +204,7 @@ fn to_nuon_filesize() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_nuon_filesize() {
|
fn from_nuon_filesize() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
"1024b"
|
"1024b"
|
||||||
| from nuon
|
| from nuon
|
||||||
@ -232,8 +217,7 @@ fn from_nuon_filesize() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_duration() {
|
fn to_nuon_duration() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1min
|
1min
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -245,8 +229,7 @@ fn to_nuon_duration() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_nuon_duration() {
|
fn from_nuon_duration() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
"60000000000ns"
|
"60000000000ns"
|
||||||
| from nuon
|
| from nuon
|
||||||
@ -259,8 +242,7 @@ fn from_nuon_duration() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_datetime() {
|
fn to_nuon_datetime() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
2019-05-10
|
2019-05-10
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -272,8 +254,7 @@ fn to_nuon_datetime() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_nuon_datetime() {
|
fn from_nuon_datetime() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
"2019-05-10T00:00:00+00:00"
|
"2019-05-10T00:00:00+00:00"
|
||||||
| from nuon
|
| from nuon
|
||||||
@ -286,8 +267,7 @@ fn from_nuon_datetime() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_errs_on_closure() {
|
fn to_nuon_errs_on_closure() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
{|| to nuon}
|
{|| to nuon}
|
||||||
| to nuon
|
| to nuon
|
||||||
@ -299,8 +279,7 @@ fn to_nuon_errs_on_closure() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn binary_to() {
|
fn binary_to() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
0x[ab cd ef] | to nuon
|
0x[ab cd ef] | to nuon
|
||||||
"#
|
"#
|
||||||
@ -311,8 +290,7 @@ fn binary_to() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn binary_roundtrip() {
|
fn binary_roundtrip() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
"0x[1f ff]" | from nuon | to nuon
|
"0x[1f ff]" | from nuon | to nuon
|
||||||
"#
|
"#
|
||||||
@ -359,8 +337,7 @@ fn read_bool() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn float_doesnt_become_int() {
|
fn float_doesnt_become_int() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
1.0 | to nuon
|
1.0 | to nuon
|
||||||
"#
|
"#
|
||||||
@ -371,8 +348,7 @@ fn float_doesnt_become_int() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn float_inf_parsed_properly() {
|
fn float_inf_parsed_properly() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
inf | to nuon
|
inf | to nuon
|
||||||
"#
|
"#
|
||||||
@ -383,8 +359,7 @@ fn float_inf_parsed_properly() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn float_neg_inf_parsed_properly() {
|
fn float_neg_inf_parsed_properly() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
-inf | to nuon
|
-inf | to nuon
|
||||||
"#
|
"#
|
||||||
@ -395,8 +370,7 @@ fn float_neg_inf_parsed_properly() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn float_nan_parsed_properly() {
|
fn float_nan_parsed_properly() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
NaN | to nuon
|
NaN | to nuon
|
||||||
"#
|
"#
|
||||||
@ -407,9 +381,8 @@ fn float_nan_parsed_properly() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_converts_columns_with_spaces() {
|
fn to_nuon_converts_columns_with_spaces() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
let test = [[a, b, "c d"]; [1 2 3] [4 5 6]]; $test | to nuon | from nuon
|
let test = [[a, b, "c d"]; [1 2 3] [4 5 6]]; $test | to nuon | from nuon
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
@ -418,9 +391,8 @@ fn to_nuon_converts_columns_with_spaces() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_quotes_empty_string() {
|
fn to_nuon_quotes_empty_string() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
let test = ""; $test | to nuon
|
let test = ""; $test | to nuon
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
@ -430,9 +402,8 @@ fn to_nuon_quotes_empty_string() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_quotes_empty_string_in_list() {
|
fn to_nuon_quotes_empty_string_in_list() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
let test = [""]; $test | to nuon | from nuon | $in == [""]
|
let test = [""]; $test | to nuon | from nuon | $in == [""]
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
@ -442,9 +413,8 @@ fn to_nuon_quotes_empty_string_in_list() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_nuon_quotes_empty_string_in_table() {
|
fn to_nuon_quotes_empty_string_in_table() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
let test = [[a, b]; ['', la] [le lu]]; $test | to nuon | from nuon
|
let test = [[a, b]; ['', la] [le lu]]; $test | to nuon | from nuon
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
@ -453,16 +423,14 @@ fn to_nuon_quotes_empty_string_in_table() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn does_not_quote_strings_unnecessarily() {
|
fn does_not_quote_strings_unnecessarily() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
let test = [["a", "b", "c d"]; [1 2 3] [4 5 6]]; $test | to nuon
|
let test = [["a", "b", "c d"]; [1 2 3] [4 5 6]]; $test | to nuon
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
assert_eq!(actual.out, "[[a, b, \"c d\"]; [1, 2, 3], [4, 5, 6]]");
|
assert_eq!(actual.out, "[[a, b, \"c d\"]; [1, 2, 3], [4, 5, 6]]");
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
r#"
|
||||||
r#"
|
|
||||||
let a = {"ro name": "sam" rank: 10}; $a | to nuon
|
let a = {"ro name": "sam" rank: 10}; $a | to nuon
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
@ -471,8 +439,7 @@ fn does_not_quote_strings_unnecessarily() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn quotes_some_strings_necessarily() {
|
fn quotes_some_strings_necessarily() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
['true','false','null',
|
['true','false','null',
|
||||||
'NaN','NAN','nan','+nan','-nan',
|
'NaN','NAN','nan','+nan','-nan',
|
||||||
|
@ -2,8 +2,7 @@ use nu_test_support::{nu, pipeline};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn record_map_to_toml() {
|
fn record_map_to_toml() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
{a: 1 b: 2 c: 'qwe'}
|
{a: 1 b: 2 c: 'qwe'}
|
||||||
| to toml
|
| to toml
|
||||||
@ -17,8 +16,7 @@ fn record_map_to_toml() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn nested_records_to_toml() {
|
fn nested_records_to_toml() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
{a: {a: a b: b} c: 1}
|
{a: {a: a b: b} c: 1}
|
||||||
| to toml
|
| to toml
|
||||||
@ -32,8 +30,7 @@ fn nested_records_to_toml() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn records_with_tables_to_toml() {
|
fn records_with_tables_to_toml() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
{a: [[a b]; [1 2] [3 4]] b: [[c d e]; [1 2 3]]}
|
{a: [[a b]; [1 2] [3 4]] b: [[c d e]; [1 2 3]]}
|
||||||
| to toml
|
| to toml
|
||||||
@ -47,8 +44,7 @@ fn records_with_tables_to_toml() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn nested_tables_to_toml() {
|
fn nested_tables_to_toml() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
{c: [[f g]; [[[h k]; [1 2] [3 4]] 1]]}
|
{c: [[f g]; [[[h k]; [1 2] [3 4]] 1]]}
|
||||||
| to toml
|
| to toml
|
||||||
@ -63,8 +59,7 @@ fn nested_tables_to_toml() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn table_to_toml_fails() {
|
fn table_to_toml_fails() {
|
||||||
// Tables can't be represented in toml
|
// Tables can't be represented in toml
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
try { [[a b]; [1 2] [5 6]] | to toml | false } catch { true }
|
try { [[a b]; [1 2] [5 6]] | to toml | false } catch { true }
|
||||||
"#
|
"#
|
||||||
@ -76,8 +71,7 @@ fn table_to_toml_fails() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn string_to_toml_fails() {
|
fn string_to_toml_fails() {
|
||||||
// Strings are not a top-level toml structure
|
// Strings are not a top-level toml structure
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
try { 'not a valid toml' | to toml | false } catch { true }
|
try { 'not a valid toml' | to toml | false } catch { true }
|
||||||
"#
|
"#
|
||||||
|
@ -17,8 +17,7 @@ fn table_to_yaml_text_and_from_yaml_text_back_into_table() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn convert_dict_to_yaml_with_boolean_key() {
|
fn convert_dict_to_yaml_with_boolean_key() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
"true: BooleanKey " | from yaml
|
"true: BooleanKey " | from yaml
|
||||||
"#
|
"#
|
||||||
@ -29,8 +28,7 @@ fn convert_dict_to_yaml_with_boolean_key() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn convert_dict_to_yaml_with_integer_key() {
|
fn convert_dict_to_yaml_with_integer_key() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
"200: [] " | from yaml
|
"200: [] " | from yaml
|
||||||
"#
|
"#
|
||||||
@ -42,8 +40,7 @@ fn convert_dict_to_yaml_with_integer_key() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn convert_dict_to_yaml_with_integer_floats_key() {
|
fn convert_dict_to_yaml_with_integer_floats_key() {
|
||||||
let actual = nu!(
|
let actual = nu!(pipeline(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
|
||||||
r#"
|
r#"
|
||||||
"2.11: "1" " | from yaml
|
"2.11: "1" " | from yaml
|
||||||
"#
|
"#
|
||||||
|
@ -2,27 +2,33 @@ use nu_test_support::{nu, nu_repl_code};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn config_is_mutable() {
|
fn config_is_mutable() {
|
||||||
let actual = nu!(cwd: ".", nu_repl_code(&[r"$env.config = { ls: { clickable_links: true } }",
|
let actual = nu!(nu_repl_code(&[
|
||||||
|
r"$env.config = { ls: { clickable_links: true } }",
|
||||||
"$env.config.ls.clickable_links = false;",
|
"$env.config.ls.clickable_links = false;",
|
||||||
"$env.config.ls.clickable_links"]));
|
"$env.config.ls.clickable_links"
|
||||||
|
]));
|
||||||
|
|
||||||
assert_eq!(actual.out, "false");
|
assert_eq!(actual.out, "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn config_preserved_after_do() {
|
fn config_preserved_after_do() {
|
||||||
let actual = nu!(cwd: ".", nu_repl_code(&[r"$env.config = { ls: { clickable_links: true } }",
|
let actual = nu!(nu_repl_code(&[
|
||||||
|
r"$env.config = { ls: { clickable_links: true } }",
|
||||||
"do -i { $env.config.ls.clickable_links = false }",
|
"do -i { $env.config.ls.clickable_links = false }",
|
||||||
"$env.config.ls.clickable_links"]));
|
"$env.config.ls.clickable_links"
|
||||||
|
]));
|
||||||
|
|
||||||
assert_eq!(actual.out, "true");
|
assert_eq!(actual.out, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn config_affected_when_mutated() {
|
fn config_affected_when_mutated() {
|
||||||
let actual = nu!(cwd: ".", nu_repl_code(&[r#"$env.config = { filesize: { metric: false, format:"auto" } }"#,
|
let actual = nu!(nu_repl_code(&[
|
||||||
|
r#"$env.config = { filesize: { metric: false, format:"auto" } }"#,
|
||||||
r#"$env.config = { filesize: { metric: true, format:"auto" } }"#,
|
r#"$env.config = { filesize: { metric: true, format:"auto" } }"#,
|
||||||
"20mib | into string"]));
|
"20mib | into string"
|
||||||
|
]));
|
||||||
|
|
||||||
assert_eq!(actual.out, "21.0 MB");
|
assert_eq!(actual.out, "21.0 MB");
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ fn filesize_metric_true() {
|
|||||||
r#"$env.config = { filesize: { metric: true, format:"mb" } }"#,
|
r#"$env.config = { filesize: { metric: true, format:"mb" } }"#,
|
||||||
r#"20mib | into string"#,
|
r#"20mib | into string"#,
|
||||||
];
|
];
|
||||||
let actual = nu!(cwd: ".", nu_repl_code( code ));
|
let actual = nu!(nu_repl_code(code));
|
||||||
assert_eq!(actual.out, "21.0 MB");
|
assert_eq!(actual.out, "21.0 MB");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ fn filesize_metric_false() {
|
|||||||
r#"$env.config = { filesize: { metric: false, format:"mib" } }"#,
|
r#"$env.config = { filesize: { metric: false, format:"mib" } }"#,
|
||||||
r#"20mib | into string"#,
|
r#"20mib | into string"#,
|
||||||
];
|
];
|
||||||
let actual = nu!(cwd: ".", nu_repl_code( code ));
|
let actual = nu!(nu_repl_code(code));
|
||||||
assert_eq!(actual.out, "20.0 MiB");
|
assert_eq!(actual.out, "20.0 MiB");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ fn filesize_metric_overrides_format() {
|
|||||||
r#"$env.config = { filesize: { metric: false, format:"mb" } }"#,
|
r#"$env.config = { filesize: { metric: false, format:"mb" } }"#,
|
||||||
r#"20mib | into string"#,
|
r#"20mib | into string"#,
|
||||||
];
|
];
|
||||||
let actual = nu!(cwd: ".", nu_repl_code( code ));
|
let actual = nu!(nu_repl_code(code));
|
||||||
assert_eq!(actual.out, "20.0 MiB");
|
assert_eq!(actual.out, "20.0 MiB");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ fn filesize_format_auto_metric_true() {
|
|||||||
r#"$env.config = { filesize: { metric: true, format:"auto" } }"#,
|
r#"$env.config = { filesize: { metric: true, format:"auto" } }"#,
|
||||||
r#"[2mb 2gb 2tb] | into string | to nuon"#,
|
r#"[2mb 2gb 2tb] | into string | to nuon"#,
|
||||||
];
|
];
|
||||||
let actual = nu!(cwd: ".", nu_repl_code( code ));
|
let actual = nu!(nu_repl_code(code));
|
||||||
assert_eq!(actual.out, r#"["2.0 MB", "2.0 GB", "2.0 TB"]"#);
|
assert_eq!(actual.out, r#"["2.0 MB", "2.0 GB", "2.0 TB"]"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +46,6 @@ fn filesize_format_auto_metric_false() {
|
|||||||
r#"$env.config = { filesize: { metric: false, format:"auto" } }"#,
|
r#"$env.config = { filesize: { metric: false, format:"auto" } }"#,
|
||||||
r#"[2mb 2gb 2tb] | into string | to nuon"#,
|
r#"[2mb 2gb 2tb] | into string | to nuon"#,
|
||||||
];
|
];
|
||||||
let actual = nu!(cwd: ".", nu_repl_code( code ));
|
let actual = nu!(nu_repl_code(code));
|
||||||
assert_eq!(actual.out, r#"["1.9 MiB", "1.9 GiB", "1.8 TiB"]"#);
|
assert_eq!(actual.out, r#"["1.9 MiB", "1.9 GiB", "1.8 TiB"]"#);
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ fn override_table() -> TestResult {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn override_table_eval_file() {
|
fn override_table_eval_file() {
|
||||||
let actual = nu!(cwd: ".", r#"def table [] { "hi" }; table"#);
|
let actual = nu!(r#"def table [] { "hi" }; table"#);
|
||||||
assert_eq!(actual.out, "hi");
|
assert_eq!(actual.out, "hi");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,11 +153,8 @@ fn override_table_eval_file() {
|
|||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn infinite_recursion_does_not_panic() {
|
fn infinite_recursion_does_not_panic() {
|
||||||
let actual = nu!(
|
let actual = nu!(r#"
|
||||||
cwd: ".",
|
|
||||||
r#"
|
|
||||||
def bang [] { bang }; bang
|
def bang [] { bang }; bang
|
||||||
"#
|
"#);
|
||||||
);
|
|
||||||
assert!(actual.err.contains("Recursion limit (50) reached"));
|
assert!(actual.err.contains("Recursion limit (50) reached"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user