2022-03-17 23:35:50 +01:00
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn alias_simple() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
2022-08-31 22:32:56 +02:00
|
|
|
alias bar = use sample_def.nu greet;
|
|
|
|
bar;
|
|
|
|
greet
|
2022-03-17 23:35:50 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "hello");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-08-31 22:32:56 +02:00
|
|
|
fn alias_hiding_1() {
|
2022-03-17 23:35:50 +01:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
2022-08-31 22:32:56 +02:00
|
|
|
overlay use ./activate-foo.nu;
|
|
|
|
$nu.scope.aliases | find deactivate-foo | length
|
2022-03-17 23:35:50 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "1");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-08-31 22:32:56 +02:00
|
|
|
fn alias_hiding_2() {
|
2022-03-17 23:35:50 +01:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
2022-08-31 22:32:56 +02:00
|
|
|
overlay use ./activate-foo.nu;
|
|
|
|
deactivate-foo;
|
|
|
|
$nu.scope.aliases | find deactivate-foo | length
|
2022-03-17 23:35:50 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "0");
|
|
|
|
}
|
2022-09-29 00:08:38 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn alias_fails_with_invalid_name() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
alias 1234 = echo "test"
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
assert!(actual
|
|
|
|
.err
|
|
|
|
.contains("alias name can't be a number or a filesize"));
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
alias 5gib = echo "test"
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
assert!(actual
|
|
|
|
.err
|
|
|
|
.contains("alias name can't be a number or a filesize"));
|
|
|
|
}
|
2022-10-14 21:51:44 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn alias_alone_lists_aliases() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
alias a = 3; alias
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
assert!(actual.out.contains("alias") && actual.out.contains("expansion"));
|
|
|
|
}
|