mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
unify the *-BuiltinVar
parser errors (#8944)
# Description this pr condenses `MutBuiltinVar`, `LetBuiltinVar` and `ConstBuiltinVar` into one error: ```nu Error: nu::parser::name_is_builtin_var × `in` used as variable name. ╭─[entry #69:1:1] 1 │ let in = 420 · ─┬ · ╰── already a builtin variable ╰──── help: 'in' is the name of a builtin Nushell variable and cannot be used as a variable name ``` it also fixes this case which was previously not handled ```nu let $nu = 420 # this variable would have been 'lost' ```
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn let_parse_error() {
|
||||
fn let_name_builtin_var() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
|
@ -12,6 +12,34 @@ fn mut_variable() {
|
||||
assert_eq!(actual.out, "4");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mut_name_builtin_var() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
mut in = 3
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("'in' is the name of a builtin Nushell variable"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mut_name_builtin_var_with_dollar() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
mut $env = 3
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("'env' is the name of a builtin Nushell variable"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mut_variable_in_loop() {
|
||||
let actual = nu!(
|
||||
|
Reference in New Issue
Block a user