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() {
|
2022-12-28 00:00:44 +01:00
|
|
|
let err_msg = "alias name can't be a number, a filesize, or contain a hash # or caret ^";
|
2022-09-29 00:08:38 +02:00
|
|
|
let actual = nu!(
|
2022-12-28 00:00:44 +01:00
|
|
|
cwd: ".", pipeline(
|
2022-09-29 00:08:38 +02:00
|
|
|
r#"
|
2022-12-30 16:44:37 +01:00
|
|
|
alias 1234 = echo "test"
|
2022-09-29 00:08:38 +02:00
|
|
|
"#
|
|
|
|
));
|
2022-12-28 00:00:44 +01:00
|
|
|
assert!(actual.err.contains(err_msg));
|
2022-12-22 21:31:34 +01:00
|
|
|
|
2022-09-29 00:08:38 +02:00
|
|
|
let actual = nu!(
|
2022-12-28 00:00:44 +01:00
|
|
|
cwd: ".", pipeline(
|
2022-09-29 00:08:38 +02:00
|
|
|
r#"
|
2022-12-30 16:44:37 +01:00
|
|
|
alias 5gib = echo "test"
|
2022-09-29 00:08:38 +02:00
|
|
|
"#
|
|
|
|
));
|
2022-12-28 00:00:44 +01:00
|
|
|
assert!(actual.err.contains(err_msg));
|
2022-12-22 21:31:34 +01:00
|
|
|
|
|
|
|
let actual = nu!(
|
2022-12-28 00:00:44 +01:00
|
|
|
cwd: ".", pipeline(
|
2022-12-22 21:31:34 +01:00
|
|
|
r#"
|
2022-12-30 16:44:37 +01:00
|
|
|
alias "te#t" = echo "test"
|
2022-12-22 21:31:34 +01:00
|
|
|
"#
|
|
|
|
));
|
2022-12-28 00:00:44 +01:00
|
|
|
assert!(actual.err.contains(err_msg));
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
alias ^foo = "bar"
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
assert!(actual.err.contains(err_msg));
|
2022-09-29 00:08:38 +02:00
|
|
|
}
|
2022-10-14 21:51:44 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn alias_alone_lists_aliases() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
alias a = 3; alias
|
|
|
|
"#
|
|
|
|
));
|
2022-12-30 16:44:37 +01:00
|
|
|
assert!(actual.out.contains("name") && actual.out.contains("expansion"));
|
2022-10-14 21:51:44 +02:00
|
|
|
}
|