Fix: remove unnecessary r#"..."# (#8670) (#9764)

<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description
<!--
Thank you for improving Nushell. Please, check our [contributing
guide](../CONTRIBUTING.md) and talk to the core team before making major
changes.

Description of your pull request goes here. **Provide examples and/or
screenshots** if your changes affect the user experience.
-->
This PR is related to **Tests: clean up unnecessary use of cwd,
pipeline(), etc.
[#8670](https://github.com/nushell/nushell/issues/8670)**

- Removed the `r#"..."#` raw string literal syntax, which is unnecessary
when there are no special characters that need quoting from the tests
that use the `nu!` macro.
- `cwd:` and `pipeline()` has not changed


# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
This commit is contained in:
Vikrant A P 2023-07-21 21:02:37 +05:30 committed by GitHub
parent cdc4fb1011
commit 75180d07de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 341 additions and 418 deletions

View File

@ -109,7 +109,7 @@ fn def_fails_with_invalid_name() {
let actual = nu!(r#"def 5gib = echo "test""#);
assert!(actual.err.contains(err_msg));
let actual = nu!(r#"def ^foo [] {}"#);
let actual = nu!("def ^foo [] {}");
assert!(actual.err.contains(err_msg));
}

View File

@ -136,17 +136,13 @@ fn capture_error_with_both_stdout_stderr_messages_not_hang_nushell() {
// check for stdout
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
do -c {bash test.sh} | complete | get stdout | str trim
"#,
"do -c {bash test.sh} | complete | get stdout | str trim",
));
assert_eq!(actual.out, expect_body);
// check for stderr
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
do -c {bash test.sh} | complete | get stderr | str trim
"#,
"do -c {bash test.sh} | complete | get stderr | str trim",
));
assert_eq!(actual.out, expect_body);
},

View File

@ -35,9 +35,7 @@ fn flatten_nested_tables_that_have_many_columns() {
#[test]
fn flatten_nested_tables() {
let actual = nu!(pipeline(
r#"
echo [[Andrés, Nicolás, Robalino]] | flatten | get 1
"#
"echo [[Andrés, Nicolás, Robalino]] | flatten | get 1"
));
assert_eq!(actual.out, "Nicolás");

View File

@ -2,10 +2,10 @@ use nu_test_support::nu;
#[test]
fn for_doesnt_auto_print_in_each_iteration() {
let actual = nu!(r#"
let actual = nu!("
for i in 1..2 {
echo 1
}"#);
}");
// Make sure we don't see any of these values in the output
// As we do not auto-print loops anymore
assert!(!actual.out.contains('1'));
@ -13,11 +13,11 @@ fn for_doesnt_auto_print_in_each_iteration() {
#[test]
fn for_break_on_external_failed() {
let actual = nu!(r#"
let actual = nu!("
for i in 1..2 {
print 1;
nu --testbin fail
}"#);
}");
// Note: nu! macro auto replace "\n" and "\r\n" with ""
// so our output will be `1`
assert_eq!(actual.out, "1");
@ -25,18 +25,18 @@ fn for_break_on_external_failed() {
#[test]
fn failed_for_should_break_running() {
let actual = nu!(r#"
let actual = nu!("
for i in 1..2 {
nu --testbin fail
}
print 3"#);
print 3");
assert!(!actual.out.contains('3'));
let actual = nu!(r#"
let actual = nu!("
let x = [1 2]
for i in $x {
nu --testbin fail
}
print 3"#);
print 3");
assert!(!actual.out.contains('3'));
}

View File

@ -66,12 +66,12 @@ fn format_filesize_works() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls
| format filesize KB size
| get size
| first
"#
"
));
assert_eq!(actual.out, "0.0 KB");

View File

@ -189,7 +189,7 @@ fn quoted_column_access() {
#[test]
fn get_does_not_delve_too_deep_in_nested_lists() {
let actual = nu!(r#"[[{foo: bar}]] | get foo"#);
let actual = nu!("[[{foo: bar}]] | get foo");
assert!(actual.err.contains("cannot find column"));
}

View File

@ -86,10 +86,10 @@ fn errors_if_column_not_found() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open los_tres_caballeros.csv
| group-by ttype
"#
"
));
assert!(actual.err.contains("did you mean 'type'"),);

View File

@ -4,12 +4,12 @@ use nu_test_support::{nu, pipeline};
fn headers_uses_first_row_as_header() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample_headers.xlsx
| get Sheet1
| headers
| get header0
| to json --raw"#
| to json --raw"
));
assert_eq!(actual.out, r#"["r1c0","r2c0"]"#)
@ -19,12 +19,12 @@ fn headers_uses_first_row_as_header() {
fn headers_adds_missing_column_name() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample_headers.xlsx
| get Sheet1
| headers
| get column1
| to json --raw"#
| to json --raw"
));
assert_eq!(actual.out, r#"["r1c1","r2c1"]"#)
@ -33,11 +33,11 @@ fn headers_adds_missing_column_name() {
#[test]
fn headers_handles_missing_values() {
let actual = nu!(pipeline(
r#"
"
[{x: a, y: b}, {x: 1, y: 2}, {x: 1, z: 3}]
| headers
| to nuon --raw
"#
"
));
assert_eq!(actual.out, "[{a: 1, b: 2}, {a: 1}]")
@ -46,9 +46,9 @@ fn headers_handles_missing_values() {
#[test]
fn headers_invalid_column_type_empty_record() {
let actual = nu!(pipeline(
r#"
"
[[a b]; [{}, 2], [3,4] ]
| headers"#
| headers"
));
assert!(actual
@ -59,9 +59,9 @@ fn headers_invalid_column_type_empty_record() {
#[test]
fn headers_invalid_column_type_record() {
let actual = nu!(pipeline(
r#"
"
[[a b]; [1 (scope aliases)] [2 2]]
| headers"#
| headers"
));
assert!(actual
@ -72,9 +72,9 @@ fn headers_invalid_column_type_record() {
#[test]
fn headers_invalid_column_type_array() {
let actual = nu!(pipeline(
r#"
"
[[a b]; [[f,g], 2], [3,4] ]
| headers"#
| headers"
));
assert!(actual
@ -85,9 +85,9 @@ fn headers_invalid_column_type_array() {
#[test]
fn headers_invalid_column_type_range() {
let actual = nu!(pipeline(
r#"
"
[[a b]; [(1..5), 2], [3,4] ]
| headers"#
| headers"
));
assert!(actual
@ -98,9 +98,9 @@ fn headers_invalid_column_type_range() {
#[test]
fn headers_invalid_column_type_duration() {
let actual = nu!(pipeline(
r#"
"
[[a b]; [((date now) - (date now)), 2], [3,4] ]
| headers"#
| headers"
));
assert!(actual

View File

@ -105,13 +105,13 @@ fn help() {
#[test]
fn count() {
let actual = nu!(pipeline(
r#"
"
echo [[bit]; [1] [0] [0] [0] [0] [0] [0] [1] [1]]
| histogram bit --percentage-type relative
| sort-by count
| reject frequency
| to json
"#
"
));
let bit_json = r#"[ { "bit": 1, "count": 3, "quantile": 0.5, "percentage": "50.00%" }, { "bit": 0, "count": 6, "quantile": 1, "percentage": "100.00%" }]"#;
@ -122,13 +122,13 @@ fn count() {
#[test]
fn count_with_normalize_percentage() {
let actual = nu!(pipeline(
r#"
"
echo [[bit]; [1] [0] [0] [0] [0] [0] [0] [1]]
| histogram bit --percentage-type normalize
| sort-by count
| reject frequency
| to json
"#
"
));
let bit_json = r#"[ { "bit": 1, "count": 2, "quantile": 0.25, "percentage": "25.00%" }, { "bit": 0, "count": 6, "quantile": 0.75, "percentage": "75.00%" }]"#;

View File

@ -16,7 +16,7 @@ fn insert_the_column() {
#[test]
fn doesnt_convert_record_to_table() {
let actual = nu!(r#"{a:1} | insert b 2 | to nuon"#);
let actual = nu!("{a:1} | insert b 2 | to nuon");
assert_eq!(actual.out, "{a: 1, b: 2}");
}
@ -38,36 +38,28 @@ fn insert_the_column_conflict() {
#[test]
fn insert_into_list() {
let actual = nu!(r#"
[1, 2, 3] | insert 1 abc | to json -r
"#);
let actual = nu!("[1, 2, 3] | insert 1 abc | to json -r");
assert_eq!(actual.out, r#"[1,"abc",2,3]"#);
}
#[test]
fn insert_into_list_begin() {
let actual = nu!(r#"
[1, 2, 3] | insert 0 abc | to json -r
"#);
let actual = nu!("[1, 2, 3] | insert 0 abc | to json -r");
assert_eq!(actual.out, r#"["abc",1,2,3]"#);
}
#[test]
fn insert_into_list_end() {
let actual = nu!(r#"
[1, 2, 3] | insert 3 abc | to json -r
"#);
let actual = nu!("[1, 2, 3] | insert 3 abc | to json -r");
assert_eq!(actual.out, r#"[1,2,3,"abc"]"#);
}
#[test]
fn insert_past_end_list() {
let actual = nu!(r#"
[1, 2, 3] | insert 5 abc | to json -r
"#);
let actual = nu!("[1, 2, 3] | insert 5 abc | to json -r");
assert_eq!(actual.out, r#"[1,2,3,null,null,"abc"]"#);
}
@ -75,7 +67,7 @@ fn insert_past_end_list() {
#[test]
fn insert_uses_enumerate_index() {
let actual = nu!(
r#"[[a]; [7] [6]] | enumerate | insert b {|el| $el.index + 1 + $el.item.a } | flatten | to nuon"#
"[[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]]");

View File

@ -2,18 +2,14 @@ use nu_test_support::{nu, pipeline};
#[test]
fn into_filesize_int() {
let actual = nu!(r#"
1 | into filesize
"#);
let actual = nu!("1 | into filesize");
assert!(actual.out.contains("1 B"));
}
#[test]
fn into_filesize_decimal() {
let actual = nu!(r#"
1.2 | into filesize
"#);
let actual = nu!("1.2 | into filesize");
assert!(actual.out.contains("1 B"));
}
@ -54,18 +50,14 @@ fn into_filesize_str_many_newlines() {
#[test]
fn into_filesize_filesize() {
let actual = nu!(r#"
3kib | into filesize
"#);
let actual = nu!("3kib | into filesize");
assert!(actual.out.contains("3.0 KiB"));
}
#[test]
fn into_filesize_negative_filesize() {
let actual = nu!(r#"
-3kib | into filesize
"#);
let actual = nu!("-3kib | into filesize");
assert!(actual.out.contains("-3.0 KiB"));
}

View File

@ -5,36 +5,28 @@ use nu_test_support::nu;
#[test]
fn into_int_filesize() {
let actual = nu!(r#"
echo 1kb | into int | each { |it| $it / 1000 }
"#);
let actual = nu!("echo 1kb | into int | each { |it| $it / 1000 }");
assert!(actual.out.contains('1'));
}
#[test]
fn into_int_filesize2() {
let actual = nu!(r#"
echo 1kib | into int | each { |it| $it / 1024 }
"#);
let actual = nu!("echo 1kib | into int | each { |it| $it / 1024 }");
assert!(actual.out.contains('1'));
}
#[test]
fn into_int_int() {
let actual = nu!(r#"
echo 1024 | into int | each { |it| $it / 1024 }
"#);
let actual = nu!("echo 1024 | into int | each { |it| $it / 1024 }");
assert!(actual.out.contains('1'));
}
#[test]
fn into_int_binary() {
let actual = nu!(r#"
echo 0x[01010101] | into int
"#);
let actual = nu!("echo 0x[01010101] | into int");
assert!(actual.out.contains("16843009"));
}

View File

@ -23,12 +23,12 @@ fn lines() {
fn lines_proper_buffering() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open lines_test.txt -r
| lines
| str length
| to json -r
"#
"
));
assert_eq!(actual.out, "[8193,3]");
@ -38,12 +38,12 @@ fn lines_proper_buffering() {
fn lines_multi_value_split() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample-simple.json
| get first second
| lines
| length
"#
"
));
assert_eq!(actual.out, "6");

View File

@ -2,7 +2,7 @@ use nu_test_support::nu;
#[test]
fn loop_doesnt_auto_print_in_each_iteration() {
let actual = nu!(r#"
let actual = nu!("
mut total = 0;
loop {
if $total == 3 {
@ -11,7 +11,7 @@ fn loop_doesnt_auto_print_in_each_iteration() {
$total += 1;
}
echo 1
}"#);
}");
// Make sure we don't see any of these values in the output
// As we do not auto-print loops anymore
assert!(!actual.out.contains('1'));
@ -19,7 +19,7 @@ fn loop_doesnt_auto_print_in_each_iteration() {
#[test]
fn loop_break_on_external_failed() {
let actual = nu!(r#"
let actual = nu!("
mut total = 0;
loop {
if $total == 3 {
@ -29,7 +29,7 @@ fn loop_break_on_external_failed() {
}
print 1;
nu --testbin fail;
}"#);
}");
// Note: nu! macro auto replace "\n" and "\r\n" with ""
// so our output will be `1`.
assert_eq!(actual.out, "1");
@ -37,7 +37,7 @@ fn loop_break_on_external_failed() {
#[test]
fn failed_loop_should_break_running() {
let actual = nu!(r#"
let actual = nu!("
mut total = 0;
loop {
if $total == 3 {
@ -47,6 +47,6 @@ fn failed_loop_should_break_running() {
}
nu --testbin fail;
}
print 3"#);
print 3");
assert!(!actual.out.contains('3'));
}

View File

@ -13,10 +13,10 @@ fn lists_regular_files() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls
| length
"#
"
));
assert_eq!(actual.out, "3");
@ -35,10 +35,10 @@ fn lists_regular_files_using_asterisk_wildcard() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls *.txt
| length
"#
"
));
assert_eq!(actual.out, "3");
@ -57,10 +57,10 @@ fn lists_regular_files_using_question_mark_wildcard() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls *.??.txt
| length
"#
"
));
assert_eq!(actual.out, "3");
@ -82,11 +82,11 @@ fn lists_all_files_in_directories_from_stream() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
echo dir_a dir_b
| each { |it| ls $it }
| flatten | length
"#
"
));
assert_eq!(actual.out, "4");
@ -100,10 +100,10 @@ fn does_not_fail_if_glob_matches_empty_directory() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls dir_a
| length
"#
"
));
assert_eq!(actual.out, "0");
@ -138,9 +138,9 @@ fn list_files_from_two_parents_up_using_multiple_dots() {
let actual = nu!(
cwd: dirs.test().join("foo/bar"),
r#"
"
ls ... | length
"#
"
);
assert_eq!(actual.out, "5");
@ -160,10 +160,10 @@ fn lists_hidden_file_when_explicitly_specified() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls .testdotfile
| length
"#
"
));
assert_eq!(actual.out, "1");
@ -194,10 +194,10 @@ fn lists_all_hidden_files_when_glob_contains_dot() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls **/.*
| length
"#
"
));
assert_eq!(actual.out, "3");
@ -231,10 +231,10 @@ fn lists_all_hidden_files_when_glob_does_not_contain_dot() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls **/*
| length
"#
"
));
assert_eq!(actual.out, "5");
@ -255,10 +255,10 @@ fn glob_with_hidden_directory() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls **/*
| length
"#
"
));
assert_eq!(actual.out, "");
@ -267,10 +267,10 @@ fn glob_with_hidden_directory() {
// will list files if provide `-a` flag.
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls -a **/*
| length
"#
"
));
assert_eq!(actual.out, "4");
@ -287,16 +287,16 @@ fn fails_with_ls_to_dir_without_permission() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
chmod 000 dir_a; ls dir_a
"#
"
));
let check_not_root = nu!(
cwd: dirs.test(), pipeline(
r#"
"
id -u
"#
"
));
assert!(
@ -321,10 +321,10 @@ fn lists_files_including_starting_with_dot() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls -a
| length
"#
"
));
assert_eq!(actual.out, "5");
@ -426,12 +426,12 @@ fn lists_with_directory_flag_without_argument() {
// Test if there are some files in the current directory
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
cd dir_files;
ls --directory
| get name
| to text
"#
"
));
let expected = ".";
assert_eq!(
@ -441,12 +441,12 @@ fn lists_with_directory_flag_without_argument() {
// Test if there is no file in the current directory
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
cd dir_empty;
ls -D
| get name
| to text
"#
"
));
let expected = ".";
assert_eq!(
@ -497,7 +497,7 @@ fn can_list_system_folder() {
let ls_with_filter = nu!(
cwd: "C:\\Windows\\System32", pipeline(
r#"ls | where size > 10mb"#
"ls | where size > 10mb"
));
assert_eq!(ls_with_filter.err, "");
}
@ -547,9 +547,9 @@ fn list_ignores_ansi() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls | find .txt | each {|| ls $in.name }
"#
"
));
assert!(actual.err.is_empty());

View File

@ -18,7 +18,7 @@ fn match_for_range_unmatched() {
#[test]
fn match_for_record() {
let actual = nu!(r#"match {a: 11} { {a: $b} => { print $b }}"#);
let actual = nu!("match {a: 11} { {a: $b} => { print $b }}");
// Make sure we don't see any of these values in the output
// As we do not auto-print loops anymore
assert_eq!(actual.out, "11");
@ -26,7 +26,7 @@ fn match_for_record() {
#[test]
fn match_for_record_shorthand() {
let actual = nu!(r#"match {a: 12} { {$a} => { print $a }}"#);
let actual = nu!("match {a: 12} { {$a} => { print $a }}");
// Make sure we don't see any of these values in the output
// As we do not auto-print loops anymore
assert_eq!(actual.out, "12");
@ -164,7 +164,7 @@ fn match_or_pattern_overlap_2() {
#[test]
fn match_doesnt_overwrite_variable() {
let actual = nu!(r#"let b = 100; match 55 { $b => {} }; print $b"#);
let actual = nu!("let b = 100; match 55 { $b => {} }; print $b");
// Make sure we don't see any of these values in the output
// As we do not auto-print loops anymore
assert_eq!(actual.out, "100");

View File

@ -44,9 +44,9 @@ fn row() {
#[test]
fn single_record_no_overwrite() {
assert_eq!(
nu!(r#"
nu!("
{a: 1, b: 5} | merge {c: 2} | to nuon
"#)
")
.out,
"{a: 1, b: 5, c: 2}"
);
@ -55,9 +55,9 @@ fn single_record_no_overwrite() {
#[test]
fn single_record_overwrite() {
assert_eq!(
nu!(r#"
nu!("
{a: 1, b: 2} | merge {a: 2} | to nuon
"#)
")
.out,
"{a: 2, b: 2}"
);
@ -66,9 +66,9 @@ fn single_record_overwrite() {
#[test]
fn single_row_table_overwrite() {
assert_eq!(
nu!(r#"
nu!("
[[a b]; [1 4]] | merge [[a b]; [2 4]] | to nuon
"#)
")
.out,
"[[a, b]; [2, 4]]"
);
@ -77,9 +77,9 @@ fn single_row_table_overwrite() {
#[test]
fn single_row_table_no_overwrite() {
assert_eq!(
nu!(r#"
nu!("
[[a b]; [1 4]] | merge [[c d]; [2 4]] | to nuon
"#)
")
.out,
"[[a, b, c, d]; [1, 4, 2, 4]]"
);
@ -88,9 +88,9 @@ fn single_row_table_no_overwrite() {
#[test]
fn multi_row_table_no_overwrite() {
assert_eq!(
nu!(r#"
nu!("
[[a b]; [1 4] [8 9] [9 9]] | merge [[c d]; [2 4]] | to nuon
"#)
")
.out,
"[{a: 1, b: 4, c: 2, d: 4}, {a: 8, b: 9}, {a: 9, b: 9}]"
);
@ -99,9 +99,9 @@ fn multi_row_table_no_overwrite() {
#[test]
fn multi_row_table_overwrite() {
assert_eq!(
nu!(r#"
nu!("
[[a b]; [1 4] [8 9] [9 9]] | merge [[a b]; [7 7]] | to nuon
"#)
")
.out,
"[[a, b]; [7, 7], [8, 9], [9, 9]]"
);

View File

@ -68,9 +68,7 @@ fn print_created_paths() {
let actual = nu!(
cwd: dirs.test(),
pipeline(
r#"
mkdir -v dir_1 dir_2 dir_3
"#
"mkdir -v dir_1 dir_2 dir_3"
));
assert!(files_exist_at(

View File

@ -2,18 +2,14 @@ use nu_test_support::nu;
#[test]
fn mut_variable() {
let actual = nu!(r#"
mut x = 3; $x = $x + 1; $x
"#);
let actual = nu!("mut x = 3; $x = $x + 1; $x");
assert_eq!(actual.out, "4");
}
#[test]
fn mut_name_builtin_var() {
let actual = nu!(r#"
mut in = 3
"#);
let actual = nu!("mut in = 3");
assert!(actual
.err
@ -22,9 +18,7 @@ fn mut_name_builtin_var() {
#[test]
fn mut_name_builtin_var_with_dollar() {
let actual = nu!(r#"
mut $env = 3
"#);
let actual = nu!("mut $env = 3");
assert!(actual
.err
@ -33,99 +27,77 @@ fn mut_name_builtin_var_with_dollar() {
#[test]
fn mut_variable_in_loop() {
let actual = nu!(r#"
mut x = 1; for i in 1..10 { $x = $x + $i}; $x
"#);
let actual = nu!("mut x = 1; for i in 1..10 { $x = $x + $i}; $x");
assert_eq!(actual.out, "56");
}
#[test]
fn capture_of_mutable_var() {
let actual = nu!(r#"
mut x = 123; {|| $x }
"#);
let actual = nu!("mut x = 123; {|| $x }");
assert!(actual.err.contains("capture of mutable variable"));
}
#[test]
fn mut_add_assign() {
let actual = nu!(r#"
mut y = 3; $y += 2; $y
"#);
let actual = nu!("mut y = 3; $y += 2; $y");
assert_eq!(actual.out, "5");
}
#[test]
fn mut_minus_assign() {
let actual = nu!(r#"
mut y = 3; $y -= 2; $y
"#);
let actual = nu!("mut y = 3; $y -= 2; $y");
assert_eq!(actual.out, "1");
}
#[test]
fn mut_multiply_assign() {
let actual = nu!(r#"
mut y = 3; $y *= 2; $y
"#);
let actual = nu!("mut y = 3; $y *= 2; $y");
assert_eq!(actual.out, "6");
}
#[test]
fn mut_divide_assign() {
let actual = nu!(r#"
mut y = 8; $y /= 2; $y
"#);
let actual = nu!("mut y = 8; $y /= 2; $y");
assert_eq!(actual.out, "4");
}
#[test]
fn mut_path_insert() {
let actual = nu!(r#"
mut y = {abc: 123}; $y.abc = 456; $y.abc
"#);
let actual = nu!("mut y = {abc: 123}; $y.abc = 456; $y.abc");
assert_eq!(actual.out, "456");
}
#[test]
fn mut_path_insert_list() {
let actual = nu!(r#"
mut a = [0 1 2]; $a.3 = 3; $a | to nuon
"#);
let actual = nu!("mut a = [0 1 2]; $a.3 = 3; $a | to nuon");
assert_eq!(actual.out, "[0, 1, 2, 3]");
}
#[test]
fn mut_path_upsert() {
let actual = nu!(r#"
mut a = {b:[{c:1}]}; $a.b.0.d = 11; $a.b.0.d
"#);
let actual = nu!("mut a = {b:[{c:1}]}; $a.b.0.d = 11; $a.b.0.d");
assert_eq!(actual.out, "11");
}
#[test]
fn mut_path_upsert_list() {
let actual = nu!(r#"
mut a = [[[3] 2] 1]; $a.0.0.1 = 0; $a.0.2 = 0; $a.2 = 0; $a | to nuon
"#);
let actual = nu!("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]");
}
#[test]
fn mut_path_operator_assign() {
let actual = nu!(r#"
mut a = {b:1}; $a.b += 3; $a.b -= 2; $a.b *= 10; $a.b /= 4; $a.b
"#);
let actual = nu!("mut a = {b:1}; $a.b += 3; $a.b -= 2; $a.b *= 10; $a.b /= 4; $a.b");
assert_eq!(actual.out, "5");
}

View File

@ -18,9 +18,9 @@ fn parse_script_success() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
nu-check script.nu
"#
"
));
assert!(actual.err.is_empty());
@ -43,9 +43,9 @@ fn parse_script_with_wrong_type() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
nu-check -d --as-module script.nu
"#
"
));
assert!(actual.err.contains("Failed to parse content"));
@ -67,9 +67,9 @@ fn parse_script_failure() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
nu-check -d script.nu
"#
"
));
assert!(actual.err.contains("Unexpected end of code"));
@ -96,9 +96,9 @@ fn parse_module_success() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
nu-check --as-module foo.nu
"#
"
));
assert!(actual.err.is_empty());
@ -125,9 +125,9 @@ fn parse_module_with_wrong_type() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
nu-check -d foo.nu
"#
"
));
assert!(actual.err.contains("Failed to parse content"));
@ -153,9 +153,9 @@ fn parse_module_failure() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
nu-check -d --as-module foo.nu
"#
"
));
assert!(actual.err.contains("Unexpected end of code"));
@ -167,9 +167,9 @@ fn file_not_exist() {
Playground::setup("nu_check_test_7", |dirs, _sandbox| {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
nu-check --as-module foo.nu
"#
"
));
assert!(actual.err.contains("file not found"));
@ -196,9 +196,9 @@ fn parse_unsupported_file() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
nu-check --as-module foo.txt
"#
"
));
assert!(actual
@ -211,9 +211,9 @@ fn parse_dir_failure() {
Playground::setup("nu_check_test_9", |dirs, _sandbox| {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
nu-check --as-module ~
"#
"
));
assert!(actual
@ -236,9 +236,9 @@ fn parse_module_success_2() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
nu-check --as-module foo.nu
"#
"
));
assert!(actual.err.is_empty());
@ -261,9 +261,9 @@ fn parse_script_success_with_raw_stream() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open script.nu | nu-check
"#
"
));
assert!(actual.err.is_empty());
@ -290,9 +290,9 @@ fn parse_module_success_with_raw_stream() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open foo.nu | nu-check --as-module
"#
"
));
assert!(actual.err.is_empty());
@ -348,9 +348,9 @@ fn parse_module_success_with_internal_stream() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open foo.nu | lines | nu-check --as-module
"#
"
));
assert!(actual.err.is_empty());
@ -397,9 +397,9 @@ fn parse_script_success_with_complex_internal_stream() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open grep.nu | lines | nu-check
"#
"
));
assert!(actual.err.is_empty());
@ -446,9 +446,9 @@ fn parse_script_failure_with_complex_internal_stream() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open grep.nu | lines | nu-check
"#
"
));
assert_eq!(actual.out, "false".to_string());
@ -495,9 +495,9 @@ fn parse_script_success_with_complex_external_stream() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open grep.nu | nu-check
"#
"
));
assert!(actual.err.is_empty());
@ -544,9 +544,9 @@ fn parse_module_success_with_complex_external_stream() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open grep.nu | nu-check -d --as-module
"#
"
));
assert!(actual.err.is_empty());
@ -593,9 +593,9 @@ fn parse_with_flag_all_success_for_complex_external_stream() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open grep.nu | nu-check -ad
"#
"
));
assert!(actual.err.is_empty());
@ -642,9 +642,9 @@ fn parse_with_flag_all_failure_for_complex_external_stream() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open grep.nu | nu-check -ad
"#
"
));
assert!(actual.err.contains("syntax error"));
@ -691,9 +691,9 @@ fn parse_with_flag_all_failure_for_complex_list_stream() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open grep.nu | lines | nu-check -ad
"#
"
));
assert!(actual.err.contains("syntax error"));
@ -716,9 +716,9 @@ fn parse_failure_due_conflicted_flags() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
nu-check -a --as-module script.nu
"#
"
));
assert!(actual
@ -755,9 +755,9 @@ fn parse_script_with_nested_scripts_success() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
nu-check lol/lol.nu
"#
"
));
assert_eq!(actual.out, "true");
@ -784,10 +784,10 @@ fn nu_check_respects_file_pwd() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
source-env lol/lol.nu;
$env.RETURN
"#
"
));
assert_eq!(actual.out, "true");

View File

@ -113,11 +113,11 @@ fn parses_more_bson_complexity() {
fn parses_sqlite() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample.db
| columns
| length
"#
"
));
assert_eq!(actual.out, "3");
@ -128,11 +128,11 @@ fn parses_sqlite() {
fn parses_sqlite_get_column_name() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample.db
| get strings
| get x.0
"#
"
));
assert_eq!(actual.out, "hello");
@ -152,11 +152,11 @@ fn parses_toml() {
fn parses_tsv() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open caco3_plastics.tsv
| first
| get origin
"#
"
));
assert_eq!(actual.out, "SPAIN")
@ -166,10 +166,10 @@ fn parses_tsv() {
fn parses_json() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sgml_description.json
| get glossary.GlossDiv.GlossList.GlossEntry.GlossSee
"#
"
));
assert_eq!(actual.out, "markup")
@ -179,7 +179,7 @@ fn parses_json() {
fn parses_xml() {
let actual = nu!(
cwd: "tests/fixtures/formats",
pipeline(r#"
pipeline("
open jt.xml
| get content
| where tag == channel
@ -190,7 +190,7 @@ fn parses_xml() {
| flatten
| where tag == guid
| get content.0.content.0
"#)
")
);
assert_eq!(actual.out, "https://www.jntrnr.com/off-to-new-adventures/")
@ -201,12 +201,12 @@ fn parses_xml() {
fn parses_arrow_ipc() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
dfr open caco3_plastics.arrow
| dfr into-nu
| first
| get origin
"#
"
));
assert_eq!(actual.out, "SPAIN")
@ -236,9 +236,9 @@ fn errors_if_file_not_found() {
fn open_wildcard() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open *.nu | where $it =~ echo | length
"#
"
));
assert_eq!(actual.out, "3")
@ -248,9 +248,9 @@ fn open_wildcard() {
fn open_multiple_files() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open caco3_plastics.csv caco3_plastics.tsv | get tariff_item | math sum
"#
"
));
assert_eq!(actual.out, "58309279992")
@ -280,9 +280,9 @@ fn open_ignore_ansi() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls | find nu.zion | get 0 | get name | open $in
"#
"
));
assert!(actual.err.is_empty());
@ -291,9 +291,7 @@ fn open_ignore_ansi() {
#[test]
fn open_no_parameter() {
let actual = nu!(r#"
open
"#);
let actual = nu!("open");
assert!(actual.err.contains("needs filename"));
}

View File

@ -3,7 +3,7 @@ use nu_test_support::nu;
#[test]
fn par_each_does_not_flatten_nested_structures() {
// This is a regression test for issue #8497
let actual = nu!(r#"[1 2 3] | par-each { |it| [$it, $it] } | sort | to json --raw"#);
let actual = nu!("[1 2 3] | par-each { |it| [$it, $it] } | sort | to json --raw");
assert_eq!(actual.out, "[[1,1],[2,2],[3,3]]");
}

View File

@ -9,12 +9,12 @@ fn selects_a_row() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls
| sort-by name
| range 0..0
| get name.0
"#
"
));
assert_eq!(actual.out, "notes.txt");
@ -32,12 +32,12 @@ fn selects_some_rows() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls
| get name
| range 1..2
| length
"#
"
));
assert_eq!(actual.out, "2");
@ -55,12 +55,12 @@ fn negative_indices() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls
| get name
| range (-1..)
| length
"#
"
));
assert_eq!(actual.out, "1");

View File

@ -104,7 +104,7 @@ fn separate_redirection() {
sandbox.with_files(vec![FileWithContent("test.sh", script_body)]);
nu!(
cwd: dirs.test(),
r#"bash test.sh out> out.txt err> err.txt"#
"bash test.sh out> out.txt err> err.txt"
);
}
#[cfg(windows)]
@ -112,7 +112,7 @@ fn separate_redirection() {
sandbox.with_files(vec![FileWithContent("test.bat", script_body)]);
nu!(
cwd: dirs.test(),
r#"cmd /D /c test.bat out> out.txt err> err.txt"#
"cmd /D /c test.bat out> out.txt err> err.txt"
);
}
// check for stdout redirection file.
@ -142,10 +142,10 @@ fn same_target_redirection_with_too_much_stderr_not_hang_nushell() {
nu!(
cwd: dirs.test(), pipeline(
r#"
"
$env.LARGE = (open --raw a_large_file.txt);
nu --testbin echo_env_stderr LARGE out+err> another_large_file.txt
"#
"
),
);
@ -166,7 +166,7 @@ fn redirection_keep_exit_codes() {
sandbox.with_files(vec![FileWithContent("test.sh", script_body)]);
nu!(
cwd: dirs.test(),
r#"bash test.sh out> out.txt err> err.txt; echo $env.LAST_EXIT_CODE"#
"bash test.sh out> out.txt err> err.txt; echo $env.LAST_EXIT_CODE"
)
};
#[cfg(windows)]
@ -174,7 +174,7 @@ fn redirection_keep_exit_codes() {
sandbox.with_files(vec![FileWithContent("test.bat", script_body)]);
nu!(
cwd: dirs.test(),
r#"cmd /D /c test.bat out> out.txt err> err.txt; echo $env.LAST_EXIT_CODE"#
"cmd /D /c test.bat out> out.txt err> err.txt; echo $env.LAST_EXIT_CODE"
)
};
assert_eq!(output.out, "10")
@ -196,7 +196,7 @@ fn redirection_with_pipeline_works() {
nu!(
cwd: dirs.test(),
r#"bash test.sh out> out.txt | describe"#
"bash test.sh out> out.txt | describe"
);
// check for stdout redirection file.
let expected_out_file = dirs.test().join("out.txt");

View File

@ -18,11 +18,11 @@ fn reduce_table_column() {
#[test]
fn reduce_table_column_with_path() {
let actual = nu!(pipeline(
r#"
"
[{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}
| into string -d 1
"#
"
));
assert_eq!(actual.out, "180.6");
@ -31,10 +31,10 @@ fn reduce_table_column_with_path() {
#[test]
fn reduce_rows_example() {
let actual = nu!(pipeline(
r#"
"
[[a,b]; [1,2] [3,4]]
| reduce -f 1.6 { |it, acc| $acc * ($it.a | into int) + ($it.b | into int) }
"#
"
));
assert_eq!(actual.out, "14.8");
@ -43,14 +43,14 @@ fn reduce_rows_example() {
#[test]
fn reduce_with_return_in_closure() {
let actual = nu!(pipeline(
r#"
"
[1, 2] | reduce --fold null { |it, state|
if $it == 1 {
return 10
};
return ($it * $state)
}
"#
"
));
assert_eq!(actual.out, "20");
@ -60,11 +60,11 @@ fn reduce_with_return_in_closure() {
#[test]
fn reduce_enumerate_example() {
let actual = nu!(pipeline(
r#"
"
echo one longest three bar | enumerate
| reduce { |it, acc| if ($it.item | str length) > ($acc.item | str length) {echo $it} else {echo $acc}}
| get index
"#
"
));
assert_eq!(actual.out, "1");
@ -73,12 +73,12 @@ fn reduce_enumerate_example() {
#[test]
fn reduce_enumerate_integer_addition_example() {
let actual = nu!(pipeline(
r#"
"
echo [1 2 3 4]
| enumerate
| reduce { |it, acc| { index: ($it.index) item: ($acc.item + $it.item)} }
| get item
"#
"
));
assert_eq!(actual.out, "10");
@ -87,7 +87,7 @@ fn reduce_enumerate_integer_addition_example() {
#[test]
fn folding_with_tables() {
let actual = nu!(pipeline(
r#"
"
echo [10 20 30 40]
| reduce -f [] { |it, acc|
with-env [value $it] {
@ -95,7 +95,7 @@ fn folding_with_tables() {
}
}
| math sum
"#
"
));
assert_eq!(actual.out, "1000");
@ -104,9 +104,7 @@ fn folding_with_tables() {
#[test]
fn error_reduce_fold_type_mismatch() {
let actual = nu!(pipeline(
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"));
@ -114,11 +112,7 @@ fn error_reduce_fold_type_mismatch() {
#[test]
fn error_reduce_empty() {
let actual = nu!(pipeline(
r#"
reduce { |it, acc| $acc + $it }
"#
));
let actual = nu!(pipeline("reduce { |it, acc| $acc + $it }"));
assert!(actual.err.contains("needs input"));
}
@ -126,9 +120,7 @@ fn error_reduce_empty() {
#[test]
fn enumerate_reduce_example() {
let actual = nu!(pipeline(
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");

View File

@ -17,14 +17,14 @@ fn changes_the_column_name() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open los_cuatro_mosqueteros.txt
| lines
| wrap name
| rename mosqueteros
| get mosqueteros
| length
"#
"
));
assert_eq!(actual.out, "4");
@ -76,11 +76,11 @@ fn errors_if_no_columns_present() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open los_cuatro_mosqueteros.txt
| lines
| rename mosqueteros
"#
"
));
assert!(actual.err.contains("command doesn't support"));

View File

@ -2,18 +2,14 @@ use nu_test_support::{nu, pipeline};
#[test]
fn early_return_if_true() {
let actual = nu!(r#"
def foo [x] { if true { return 2 }; $x }; foo 100
"#);
let actual = nu!("def foo [x] { if true { return 2 }; $x }; foo 100");
assert_eq!(actual.out, r#"2"#);
}
#[test]
fn early_return_if_false() {
let actual = nu!(r#"
def foo [x] { if false { return 2 }; $x }; foo 100
"#);
let actual = nu!("def foo [x] { if false { return 2 }; $x }; foo 100");
assert_eq!(actual.out, r#"100"#);
}
@ -22,9 +18,7 @@ fn early_return_if_false() {
fn return_works_in_script_without_def_main() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
nu early_return.nu
"#
"nu early_return.nu"
));
assert!(actual.err.is_empty());

View File

@ -313,7 +313,7 @@ fn rm_wildcard_leading_dot_deletes_dotfiles() {
nu!(
cwd: dirs.test(),
r#"rm .*"#
"rm .*"
);
assert!(files_exist_at(vec!["foo"], dirs.test()));

View File

@ -23,11 +23,11 @@ mod rows {
"{} | {}",
table(),
pipeline(
r#"
roll down
| first
| get status
"#
"
roll down
| first
| get status
"
)
));
@ -40,11 +40,11 @@ mod rows {
"{} | {}",
table(),
pipeline(
r#"
roll up --by 3
| first
| get status
"#
"
roll up --by 3
| first
| get status
"
)
));

View File

@ -7,9 +7,9 @@ use nu_test_support::{nu, pipeline};
fn better_empty_redirection() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
ls | each { |it| nu --testbin cococo $it.name } | ignore
"#
"
));
eprintln!("out: {}", actual.out);
@ -50,9 +50,9 @@ fn bare_word_expand_path_glob() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
^ls *.txt
"#
"
));
assert!(actual.out.contains("D&D_volume_1.txt"));
@ -130,9 +130,9 @@ fn failed_command_with_semicolon_will_not_execute_following_cmds() {
Playground::setup("external failed command with semicolon", |dirs, _| {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
^ls *.abc; echo done
"#
"
));
assert!(!actual.out.contains("done"));
@ -228,7 +228,7 @@ fn external_command_expand_tilde_with_back_quotes() {
fn external_command_receives_raw_binary_data() {
Playground::setup("external command receives raw binary data", |dirs, _| {
let actual =
nu!(cwd: dirs.test(), pipeline(r#"0x[deadbeef] | nu --testbin input_bytes_length"#));
nu!(cwd: dirs.test(), pipeline("0x[deadbeef] | nu --testbin input_bytes_length"));
assert_eq!(actual.out, r#"4"#);
})
}
@ -239,9 +239,9 @@ fn failed_command_with_semicolon_will_not_execute_following_cmds_windows() {
Playground::setup("external failed command with semicolon", |dirs, _| {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
^cargo asdf; echo done
"#
"
));
assert!(!actual.out.contains("done"));

View File

@ -30,7 +30,7 @@ fn writes_out_list() {
nu!(
cwd: dirs.root(),
r#"[a b c d] | save save_test_3/list_sample.txt"#,
"[a b c d] | save save_test_3/list_sample.txt",
);
let actual = file_contents(expected_file);
@ -185,7 +185,7 @@ fn save_failure_not_overrides() {
nu!(
cwd: dirs.root(),
// Writing number to file as toml fails
r#"3 | save save_test_10/result.toml -f"#
"3 | save save_test_10/result.toml -f"
);
let actual = file_contents(expected_file);
assert_eq!(actual, "Old content");
@ -272,7 +272,7 @@ fn save_list_stream() {
nu!(
cwd: dirs.root(),
r#"[a b c d] | each {|i| $i} | save -r save_test_13/list_sample.txt"#,
"[a b c d] | each {|i| $i} | save -r save_test_13/list_sample.txt",
);
let actual = file_contents(expected_file);
@ -289,7 +289,7 @@ fn writes_out_range() {
nu!(
cwd: dirs.root(),
r#"1..3 | save save_test_14/list_sample.json"#,
"1..3 | save save_test_14/list_sample.json",
);
let actual = file_contents(expected_file);

View File

@ -129,12 +129,12 @@ fn selects_a_row() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls
| sort-by name
| select 0
| get name.0
"#
"
));
assert_eq!(actual.out, "arepas.txt");
@ -148,12 +148,12 @@ fn selects_many_rows() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls
| get name
| select 1 0
| length
"#
"
));
assert_eq!(actual.out, "2");

View File

@ -20,14 +20,14 @@ fn by_invalid_types() {
fn sort_primitive_values() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open cargo_sample.toml --raw
| lines
| skip 1
| first 6
| sort
| first
"#
"
));
assert_eq!(actual.out, "authors = [\"The Nushell Project Developers\"]");

View File

@ -54,12 +54,12 @@ fn sort_by_empty() {
fn ls_sort_by_name_sensitive() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample-ls-output.json
| sort-by name
| select name
| to json --raw
"#
"
));
let json_output = r#"[{"name": "B.txt"},{"name": "C"},{"name": "a.txt"}]"#;
@ -71,12 +71,12 @@ fn ls_sort_by_name_sensitive() {
fn ls_sort_by_name_insensitive() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample-ls-output.json
| sort-by -i name
| select name
| to json --raw
"#
"
));
let json_output = r#"[{"name": "a.txt"},{"name": "B.txt"},{"name": "C"}]"#;
@ -87,12 +87,12 @@ fn ls_sort_by_name_insensitive() {
fn ls_sort_by_type_name_sensitive() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample-ls-output.json
| sort-by type name
| select name type
| to json --raw
"#
"
));
let json_output = r#"[{"name": "C","type": "Dir"},{"name": "B.txt","type": "File"},{"name": "a.txt","type": "File"}]"#;
@ -103,12 +103,12 @@ fn ls_sort_by_type_name_sensitive() {
fn ls_sort_by_type_name_insensitive() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample-ls-output.json
| sort-by -i type name
| select name type
| to json --raw
"#
"
));
let json_output = r#"[{"name": "C","type": "Dir"},{"name": "a.txt","type": "File"},{"name": "B.txt","type": "File"}]"#;

View File

@ -37,11 +37,11 @@ fn sources_also_files_under_custom_lib_dirs_path() {
let actual = nu!(
cwd: ".", pipeline(
r#"
"
source-env my_library.nu ;
hello
"#
"
));
assert_eq!(actual.out, "hello nu");
@ -319,9 +319,9 @@ fn source_env_const_file() {
fn source_respects_early_return() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
source early_return.nu
"#
"
));
assert!(actual.err.is_empty());

View File

@ -42,11 +42,11 @@ fn errors_if_no_table_given_as_input() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls
| get name
| split-by type
"#
"
));
assert!(actual.err.contains("requires a table"));

File diff suppressed because one or more lines are too long

View File

@ -105,7 +105,7 @@ fn not_create_file_if_it_not_exists() {
Playground::setup("change_time_test_28", |dirs, _sandbox| {
nu!(
cwd: dirs.test(),
r#"touch -c file.txt"#
"touch -c file.txt"
);
let path = dirs.test().join("file.txt");
@ -114,7 +114,7 @@ fn not_create_file_if_it_not_exists() {
nu!(
cwd: dirs.test(),
r#"touch -c file.txt"#
"touch -c file.txt"
);
let path = dirs.test().join("file.txt");

View File

@ -19,11 +19,11 @@ fn removes_duplicate_rows() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open los_tres_caballeros.csv
| uniq
| length
"#
"
));
assert_eq!(actual.out, "3");
@ -47,12 +47,12 @@ fn uniq_values() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open los_tres_caballeros.csv
| select type
| uniq
| length
"#
"
));
assert_eq!(actual.out, "2");
@ -119,11 +119,11 @@ fn nested_json_structures() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open nested_json_structures.json
| uniq
| length
"#
"
));
assert_eq!(actual.out, "3");
})
@ -195,10 +195,10 @@ fn uniq_simple_vals_strs() {
#[test]
fn table() {
let actual = nu!(pipeline(
r#"
"
[[fruit day]; [apple monday] [apple friday] [Apple friday] [apple monday] [pear monday] [orange tuesday]]
| uniq
"#
"
));
let expected = nu!("[[fruit day]; [apple monday] [apple friday] [Apple friday] [pear monday] [orange tuesday]]");

View File

@ -18,11 +18,11 @@ fn removes_duplicate_rows() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open los_tres_caballeros.csv
| uniq-by last_name
| length
"#
"
));
assert_eq!(actual.out, "3");
@ -69,12 +69,12 @@ fn uniq_counting() {
#[test]
fn uniq_unique() {
let actual = nu!(pipeline(
r#"
"
echo [1 2 3 4 1 5]
| wrap item
| uniq-by item --unique
| get item
"#
"
));
let expected = nu!("[2 3 4 5]");
assert_eq!(actual.out, expected.out);
@ -83,16 +83,16 @@ fn uniq_unique() {
#[test]
fn table() {
let actual = nu!(pipeline(
r#"
"
[[fruit day]; [apple monday] [apple friday] [Apple friday] [apple monday] [pear monday] [orange tuesday]]
| uniq-by fruit
"#
"
));
let expected = nu!(pipeline(
r#"
"
echo [[fruit day]; [apple monday] [Apple friday] [pear monday] [orange tuesday]]
"#
"
));
print!("{}", actual.out);
print!("{}", expected.out);
@ -109,16 +109,16 @@ fn uniq_by_empty() {
#[test]
fn uniq_by_multiple_columns() {
let actual = nu!(pipeline(
r#"
"
[[fruit day]; [apple monday] [apple friday] [Apple friday] [apple monday] [pear monday] [orange tuesday]]
| uniq-by fruit day
"#
"
));
let expected = nu!(pipeline(
r#"
"
echo [[fruit day]; [apple monday] [apple friday] [Apple friday] [pear monday] [orange tuesday]]
"#
"
));
assert_eq!(actual.out, expected.out);
}

View File

@ -26,11 +26,11 @@ fn doesnt_convert_record_to_table() {
fn sets_the_column_from_a_block_run_output() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open cargo_sample.toml
| update dev-dependencies.pretty_assertions { open cargo_sample.toml | get dev-dependencies.pretty_assertions | inc --minor }
| get dev-dependencies.pretty_assertions
"#
"
));
assert_eq!(actual.out, "0.7.0");

View File

@ -25,11 +25,11 @@ fn doesnt_convert_record_to_table() {
fn sets_the_column_from_a_block_run_output() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open cargo_sample.toml
| upsert dev-dependencies.pretty_assertions { open cargo_sample.toml | get dev-dependencies.pretty_assertions | inc --minor }
| get dev-dependencies.pretty_assertions
"#
"
));
assert_eq!(actual.out, "0.7.0");
@ -68,7 +68,7 @@ fn sets_the_column_from_a_subexpression() {
#[test]
fn upsert_uses_enumerate_index_inserting() {
let actual = nu!(
r#"[[a]; [7] [6]] | enumerate | upsert b {|el| $el.index + 1 + $el.item.a } | flatten | to nuon"#
"[[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]]");

View File

@ -20,13 +20,13 @@ fn use_module_file_within_block() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
def bar [] {
use spam.nu foo;
foo
};
bar
"#
"
)
);
@ -53,10 +53,10 @@ fn use_keeps_doc_comments() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
use spam.nu foo;
help foo
"#
"
)
);

View File

@ -81,65 +81,65 @@ fn where_uses_enumerate_index() {
fn binary_operator_comparisons() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample.db
| get ints
| first 4
| where z > 4200
| get z.0
"#
"
));
assert_eq!(actual.out, "4253");
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample.db
| get ints
| first 4
| where z >= 4253
| get z.0
"#
"
));
assert_eq!(actual.out, "4253");
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample.db
| get ints
| first 4
| where z < 10
| get z.0
"#
"
));
assert_eq!(actual.out, "1");
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample.db
| get ints
| first 4
| where z <= 1
| get z.0
"#
"
));
assert_eq!(actual.out, "1");
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample.db
| get ints
| where z != 1
| first
| get z
"#
"
));
assert_eq!(actual.out, "42");
@ -150,24 +150,24 @@ fn binary_operator_comparisons() {
fn contains_operator() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample.db
| get strings
| where x =~ ell
| length
"#
"
));
assert_eq!(actual.out, "4");
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"
open sample.db
| get strings
| where x !~ ell
| length
"#
"
));
assert_eq!(actual.out, "2");

View File

@ -17,14 +17,14 @@ fn wrap_rows_into_a_row() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open los_tres_caballeros.txt
| from csv
| wrap caballeros
| get caballeros
| get 0
| get last_name
"#
"
));
assert_eq!(actual.out, "Robalino");
@ -46,14 +46,14 @@ fn wrap_rows_into_a_table() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open los_tres_caballeros.txt
| from csv
| get last_name
| wrap caballero
| get 2
| get caballero
"#
"
));
assert_eq!(actual.out, "Katz");

View File

@ -23,7 +23,7 @@ fn zips_two_tables() {
)]);
let actual = nu!(pipeline(&format!(
r#"
"
use {} expect ;
let contributors = ([
@ -35,7 +35,7 @@ fn zips_two_tables() {
let actual = ($contributors | upsert commits {{ |i| ($i.commits + 10) }});
expect $actual --to-eq [[name, commits]; [andres, 20] [jt, 30]]
"#,
",
dirs.test().join("zip_test.nu").display()
)));