forked from extern/nushell
Add tests and cover edge cases of the :: delim.
This commit is contained in:
parent
cbda1b1650
commit
5163dbb7a1
@ -171,6 +171,10 @@ pub enum ParseError {
|
|||||||
#[diagnostic(code(nu::parser::missing_import_pattern), url(docsrs))]
|
#[diagnostic(code(nu::parser::missing_import_pattern), url(docsrs))]
|
||||||
MissingImportPattern(#[label = "needs an import pattern"] Span),
|
MissingImportPattern(#[label = "needs an import pattern"] Span),
|
||||||
|
|
||||||
|
#[error("Wrong import pattern structure.")]
|
||||||
|
#[diagnostic(code(nu::parser::missing_import_pattern), url(docsrs))]
|
||||||
|
WrongImportPattern(#[label = "invalid import pattern structure"] Span),
|
||||||
|
|
||||||
#[error("Module export not found.")]
|
#[error("Module export not found.")]
|
||||||
#[diagnostic(code(nu::parser::export_not_found), url(docsrs))]
|
#[diagnostic(code(nu::parser::export_not_found), url(docsrs))]
|
||||||
ExportNotFound(#[label = "could not find imports"] Span),
|
ExportNotFound(#[label = "could not find imports"] Span),
|
||||||
|
@ -1711,6 +1711,33 @@ pub fn parse_import_pattern(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tokens.len() != 1) && (tokens.len() != 4) {
|
||||||
|
return (
|
||||||
|
ImportPattern {
|
||||||
|
head: vec![],
|
||||||
|
members: vec![],
|
||||||
|
},
|
||||||
|
Some(ParseError::WrongImportPattern(span)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let has_second_colon = if let Some(t) = tokens.get(2) {
|
||||||
|
let potential_colon = working_set.get_span_contents(t.span);
|
||||||
|
potential_colon == b":"
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
|
if (tokens.len() == 4) && !has_second_colon {
|
||||||
|
return (
|
||||||
|
ImportPattern {
|
||||||
|
head: vec![],
|
||||||
|
members: vec![],
|
||||||
|
},
|
||||||
|
Some(ParseError::WrongImportPattern(span)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let head = working_set.get_span_contents(tokens[0].span).to_vec();
|
let head = working_set.get_span_contents(tokens[0].span).to_vec();
|
||||||
|
|
||||||
if let Some(tail) = tokens.get(3) {
|
if let Some(tail) = tokens.get(3) {
|
||||||
|
16
src/tests.rs
16
src/tests.rs
@ -434,6 +434,22 @@ fn module_import_uses_internal_command() -> TestResult {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn module_import_does_not_parse_with_incorrect_delimiter() -> TestResult {
|
||||||
|
fail_test(
|
||||||
|
r#"module foo { export def a [] { 1 } }; use foo:.a"#,
|
||||||
|
"not found",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn module_import_does_not_parse_with_missing_tail() -> TestResult {
|
||||||
|
fail_test(
|
||||||
|
r#"module foo { export def a [] { 1 } }; use foo::"#,
|
||||||
|
"not found",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Test the use/hide tests also as separate lines in REPL (i.e., with merging the delta in between)
|
// TODO: Test the use/hide tests also as separate lines in REPL (i.e., with merging the delta in between)
|
||||||
#[test]
|
#[test]
|
||||||
fn hides_def() -> TestResult {
|
fn hides_def() -> TestResult {
|
||||||
|
Loading…
Reference in New Issue
Block a user