allow register to accept a const argument (#8758)

# Description

this pr allows `register` to be used with const variables
```nu
const math_plugin = "~/.config/nushell/plugins/nu_plugin_math"
register $math_plugin
```

should close #8208, previous work #8435
This commit is contained in:
mike
2023-04-08 23:04:57 +03:00
committed by GitHub
parent 5afbfb5c2c
commit 637283ffad
3 changed files with 51 additions and 15 deletions

View File

@ -487,3 +487,36 @@ fn unbalanced_delimiter2() -> TestResult {
fn unbalanced_delimiter3() -> TestResult {
fail_test(r#"{"#, "Unexpected end of code")
}
#[test]
fn register_with_string_literal() -> TestResult {
fail_test(r#"register 'nu-plugin-math'"#, "File not found")
}
#[test]
fn register_with_string_constant() -> TestResult {
let input = "\
const file = 'nu-plugin-math'
register $file
";
// should not fail with `not a constant`
fail_test(input, "File not found")
}
#[test]
fn register_with_string_variable() -> TestResult {
let input = "\
let file = 'nu-plugin-math'
register $file
";
fail_test(input, "Value is not a parse-time constant")
}
#[test]
fn register_with_non_string_constant() -> TestResult {
let input = "\
const file = 6
register $file
";
fail_test(input, "expected string, found int")
}