mirror of
https://github.com/nushell/nushell
synced 2025-01-13 13:49:21 +00:00
Only allow unaliasing in current scope, add tests (#3936)
* unalias only removes aliases in the current scope * Add a test and fix previous ones which did not function as expected
This commit is contained in:
parent
ead4029d49
commit
6db5692be4
2 changed files with 31 additions and 10 deletions
|
@ -408,7 +408,7 @@ impl ParserScope for Scope {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_alias(&self, name: &str) {
|
fn remove_alias(&self, name: &str) {
|
||||||
for frame in self.frames.lock().iter_mut().rev() {
|
if let Some(frame) = self.frames.lock().last_mut() {
|
||||||
frame.aliases.remove(name);
|
frame.aliases.remove(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1150,23 +1150,44 @@ fn unalias_shadowing() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
cwd: ".", pipeline(
|
||||||
r#"
|
r#"
|
||||||
alias ll = ls -l
|
def test-shadowing [] {
|
||||||
let xyz = { ll -a }
|
alias greet = echo hello;
|
||||||
unalias ll
|
let xyz = { greet };
|
||||||
do $xyz
|
unalias greet;
|
||||||
|
do $xyz
|
||||||
|
};
|
||||||
|
test-shadowing
|
||||||
"#)
|
"#)
|
||||||
);
|
);
|
||||||
|
assert_eq!(actual.out, "hello");
|
||||||
|
}
|
||||||
|
|
||||||
assert_eq!(actual.out, "");
|
#[test]
|
||||||
|
fn unalias_does_not_escape_scope() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: ".", pipeline(
|
||||||
|
r#"
|
||||||
|
def test-alias [] {
|
||||||
|
alias greet = echo hello;
|
||||||
|
(unalias greet);
|
||||||
|
greet
|
||||||
|
};
|
||||||
|
test-alias
|
||||||
|
"#)
|
||||||
|
);
|
||||||
|
assert_eq!(actual.out, "hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unalias_hides_alias() {
|
fn unalias_hides_alias() {
|
||||||
let actual = nu!(cwd: ".", pipeline(
|
let actual = nu!(cwd: ".", pipeline(
|
||||||
r#"alias ll = ls -l
|
r#"
|
||||||
ll
|
def test-alias [] {
|
||||||
unalias ll
|
alias ll = ls -l;
|
||||||
ll
|
unalias ll;
|
||||||
|
ll
|
||||||
|
};
|
||||||
|
test-alias
|
||||||
"#)
|
"#)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue