Allow expanding aliases before keywords, improve hiding (#4858)

* Allow aliasing source

* Add test

* improve hiding

* Finish adding tests

* fix test
This commit is contained in:
JT
2022-03-18 11:35:50 +13:00
committed by GitHub
parent 0986eefb64
commit d0cbb2d12c
11 changed files with 90 additions and 15 deletions

View File

@ -113,7 +113,7 @@ impl Command for Hide {
} else if !import_pattern.hidden.contains(&import_pattern.head.name)
&& stack.remove_env_var(engine_state, &head_name_str).is_none()
{
return Err(ShellError::NotFound(call.positional[0].span));
// TODO: we may want to error in the future
}
Ok(PipelineData::new(call.head))

View File

@ -0,0 +1,40 @@
use nu_test_support::{nu, pipeline};
#[test]
fn alias_simple() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
alias bar = source sample_def.nu; bar; greet
"#
));
assert_eq!(actual.out, "hello");
}
#[test]
fn alias_hiding1() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
source ./activate-foo.nu;
$nu.scope.aliases | find deactivate-foo | length
"#
));
assert_eq!(actual.out, "1");
}
#[test]
fn alias_hiding2() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
source ./activate-foo.nu;
deactivate-foo;
$nu.scope.aliases | find deactivate-foo | length
"#
));
assert_eq!(actual.out, "0");
}

View File

@ -18,8 +18,8 @@ fn can_average_numbers() {
fn can_average_bytes() {
let actual = nu!(
cwd: "tests/fixtures/formats",
"ls | sort-by name | skip 1 | first 2 | get size | math avg | to json -r"
"[100kb, 10b, 100mib] | math avg | to json -r"
);
assert_eq!(actual.out, "1600");
assert_eq!(actual.out, "34985870");
}

View File

@ -1,3 +1,4 @@
mod alias;
mod all;
mod any;
mod append;