forked from extern/nushell
normalize special characters in module names to allow variable access (#14353)
Fixes #14252 # User-Facing Changes - Special characters in module names are replaced with underscores when importing constants, preventing "expected valid variable name": ```nushell > module foo-bar { export const baz = 1 } > use foo-bar > $foo_bar.baz ``` - "expected valid variable name" errors now include a suggestion list: ```nushell > module foo-bar { export const baz = 1 } > use foo-bar > $foo-bar Error: nu::parser::parse_mismatch_with_did_you_mean × Parse mismatch during operation. ╭─[entry #1:1:1] 1 │ $foo-bar; · ────┬─── · ╰── expected valid variable name. Did you mean '$foo_bar'? ╰──── ```
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
use crate::repl::tests::{fail_test, run_test, TestResult};
|
||||
use rstest::rstest;
|
||||
|
||||
#[test]
|
||||
fn module_def_imports_1() -> TestResult {
|
||||
@ -145,6 +146,28 @@ fn export_module_which_defined_const() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case("spam-mod")]
|
||||
#[case("spam/mod")]
|
||||
#[case("spam=mod")]
|
||||
fn export_module_with_normalized_var_name(#[case] name: &str) -> TestResult {
|
||||
let def = format!(
|
||||
"module {name} {{ export const b = 3; export module {name}2 {{ export const c = 4 }} }}"
|
||||
);
|
||||
run_test(&format!("{def}; use {name}; $spam_mod.b"), "3")?;
|
||||
run_test(&format!("{def}; use {name} *; $spam_mod2.c"), "4")
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case("spam-mod")]
|
||||
#[case("spam/mod")]
|
||||
fn use_module_with_invalid_var_name(#[case] name: &str) -> TestResult {
|
||||
fail_test(
|
||||
&format!("module {name} {{ export const b = 3 }}; use {name}; ${name}"),
|
||||
"expected valid variable name. Did you mean '$spam_mod'",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_export_private_const() -> TestResult {
|
||||
fail_test(
|
||||
|
Reference in New Issue
Block a user