mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 04:45:04 +02:00
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:
@ -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))
|
||||
|
40
crates/nu-command/tests/commands/alias.rs
Normal file
40
crates/nu-command/tests/commands/alias.rs
Normal 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");
|
||||
}
|
@ -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");
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
mod alias;
|
||||
mod all;
|
||||
mod any;
|
||||
mod append;
|
||||
|
Reference in New Issue
Block a user