mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 00:13:21 +01:00
Add const support for all overlay commands (#7720)
This commit is contained in:
parent
1ae9157985
commit
57cf805e12
@ -2315,16 +2315,16 @@ pub fn parse_overlay_new(
|
||||
};
|
||||
|
||||
let (overlay_name, _) = if let Some(expr) = call.positional_nth(0) {
|
||||
if let Some(s) = expr.as_string() {
|
||||
(s, expr.span)
|
||||
} else {
|
||||
return (
|
||||
garbage_pipeline(spans),
|
||||
Some(ParseError::UnknownState(
|
||||
"internal error: Module name not a string".into(),
|
||||
expr.span,
|
||||
)),
|
||||
);
|
||||
match eval_constant(working_set, expr) {
|
||||
Ok(val) => match value_as_string(val, expr.span) {
|
||||
Ok(s) => (s, expr.span),
|
||||
Err(err) => {
|
||||
return (garbage_pipeline(spans), Some(err));
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
return (garbage_pipeline(spans), Some(err));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return (
|
||||
@ -2721,16 +2721,16 @@ pub fn parse_overlay_hide(
|
||||
};
|
||||
|
||||
let (overlay_name, overlay_name_span) = if let Some(expr) = call.positional_nth(0) {
|
||||
if let Some(s) = expr.as_string() {
|
||||
(s, expr.span)
|
||||
} else {
|
||||
return (
|
||||
garbage_pipeline(spans),
|
||||
Some(ParseError::UnknownState(
|
||||
"internal error: Module name not a string".into(),
|
||||
expr.span,
|
||||
)),
|
||||
);
|
||||
match eval_constant(working_set, expr) {
|
||||
Ok(val) => match value_as_string(val, expr.span) {
|
||||
Ok(s) => (s, expr.span),
|
||||
Err(err) => {
|
||||
return (garbage_pipeline(spans), Some(err));
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
return (garbage_pipeline(spans), Some(err));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
(
|
||||
|
@ -196,6 +196,33 @@ fn add_overlay_from_const_module_name_decl() {
|
||||
assert_eq!(actual.out, "foo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_overlay_from_const_name() {
|
||||
let inp = &[
|
||||
r#"const mod = 'spam'"#,
|
||||
r#"overlay new $mod"#,
|
||||
r#"overlay list | last"#,
|
||||
];
|
||||
|
||||
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||
|
||||
assert_eq!(actual.out, "spam");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hide_overlay_from_const_name() {
|
||||
let inp = &[
|
||||
r#"const mod = 'spam'"#,
|
||||
r#"overlay new $mod"#,
|
||||
r#"overlay hide $mod"#,
|
||||
r#"overlay list | str join ' '"#,
|
||||
];
|
||||
|
||||
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||
|
||||
assert!(!actual.out.contains("spam"));
|
||||
}
|
||||
|
||||
// This one tests that the `nu_repl()` loop works correctly
|
||||
#[test]
|
||||
fn add_overlay_from_file_decl_cd() {
|
||||
|
Loading…
Reference in New Issue
Block a user