forked from extern/nushell
Fix 6529 - Trim overlay name (#6555)
* trim overlay name * format * Update tests/overlays/mod.rs Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com> * cleanup * new tests Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
parent
f0ae6ffe12
commit
35a521d762
@ -1,4 +1,5 @@
|
|||||||
use nu_engine::{eval_block, find_in_dirs_env, redirect_env, CallExt};
|
use nu_engine::{eval_block, find_in_dirs_env, redirect_env, CallExt};
|
||||||
|
use nu_parser::trim_quotes_str;
|
||||||
use nu_protocol::ast::{Call, Expr};
|
use nu_protocol::ast::{Call, Expr};
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
@ -55,7 +56,8 @@ impl Command for OverlayUse {
|
|||||||
call: &Call,
|
call: &Call,
|
||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let name_arg: Spanned<String> = call.req(engine_state, caller_stack, 0)?;
|
let mut name_arg: Spanned<String> = call.req(engine_state, caller_stack, 0)?;
|
||||||
|
name_arg.item = trim_quotes_str(&name_arg.item).to_string();
|
||||||
|
|
||||||
let origin_module_id = if let Some(overlay_expr) = call.positional_nth(0) {
|
let origin_module_id = if let Some(overlay_expr) = call.positional_nth(0) {
|
||||||
if let Expr::Overlay(module_id) = overlay_expr.expr {
|
if let Expr::Overlay(module_id) = overlay_expr.expr {
|
||||||
|
@ -993,3 +993,65 @@ fn overlay_preserve_hidden_alias() {
|
|||||||
assert_eq!(actual.out, "foo");
|
assert_eq!(actual.out, "foo");
|
||||||
assert_eq!(actual_repl.out, "foo");
|
assert_eq!(actual_repl.out, "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn overlay_trim_single_quote() {
|
||||||
|
let inp = &[
|
||||||
|
r#"module spam { export def foo [] { "foo" } }"#,
|
||||||
|
r#"overlay use 'spam'"#,
|
||||||
|
r#"overlay list | last "#,
|
||||||
|
];
|
||||||
|
|
||||||
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "spam");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn overlay_trim_single_quote_hide() {
|
||||||
|
let inp = &[
|
||||||
|
r#"module spam { export def foo [] { "foo" } }"#,
|
||||||
|
r#"overlay use 'spam'"#,
|
||||||
|
r#"overlay hide spam "#,
|
||||||
|
r#"foo"#,
|
||||||
|
];
|
||||||
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
|
let actual_repl = nu!(cwd: "tests/overlays", nu_repl_code(inp));
|
||||||
|
|
||||||
|
assert!(!actual.err.is_empty());
|
||||||
|
#[cfg(windows)]
|
||||||
|
assert!(actual_repl.out != "foo");
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
assert!(!actual_repl.err.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn overlay_trim_double_quote() {
|
||||||
|
let inp = &[
|
||||||
|
r#"module spam { export def foo [] { "foo" } }"#,
|
||||||
|
r#"overlay use "spam" "#,
|
||||||
|
r#"overlay list | last "#,
|
||||||
|
];
|
||||||
|
|
||||||
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "spam");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn overlay_trim_double_quote_hide() {
|
||||||
|
let inp = &[
|
||||||
|
r#"module spam { export def foo [] { "foo" } }"#,
|
||||||
|
r#"overlay use "spam" "#,
|
||||||
|
r#"overlay hide spam "#,
|
||||||
|
r#"foo"#,
|
||||||
|
];
|
||||||
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
|
let actual_repl = nu!(cwd: "tests/overlays", nu_repl_code(inp));
|
||||||
|
|
||||||
|
assert!(!actual.err.is_empty());
|
||||||
|
#[cfg(windows)]
|
||||||
|
assert!(actual_repl.out != "foo");
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
assert!(!actual_repl.err.is_empty());
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user