diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ffb9013f8c..1be606cf9d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,7 @@ jobs: - uses: actions-rs/cargo@v1 with: command: test + args: --all - uses: actions-rs/cargo@v1 with: diff --git a/crates/nu-cli/src/errors.rs b/crates/nu-cli/src/errors.rs index 7c620c9b9c..4b2944f355 100644 --- a/crates/nu-cli/src/errors.rs +++ b/crates/nu-cli/src/errors.rs @@ -18,7 +18,17 @@ fn convert_span_to_diag( } } - panic!("internal error: can't find span in parser state") + if span.start == working_set.next_span_start() { + // We're trying to highlight the space after the end + if let Some((file_id, (_, _, end))) = working_set.files().enumerate().last() { + return Ok((file_id, *end..(*end + 1))); + } + } + + panic!( + "internal error: can't find span in parser state: {:?}", + span + ) } pub fn report_parsing_error( diff --git a/crates/nu-parser/tests/test_parser.rs b/crates/nu-parser/tests/test_parser.rs index c47808fe88..781cfd9577 100644 --- a/crates/nu-parser/tests/test_parser.rs +++ b/crates/nu-parser/tests/test_parser.rs @@ -302,37 +302,6 @@ mod range { } } - #[test] - fn parse_left_unbounded_range() { - let engine_state = EngineState::new(); - let mut working_set = StateWorkingSet::new(&engine_state); - - let (block, err) = parse_source(&mut working_set, b"..10", true); - - assert!(err.is_none()); - assert!(block.len() == 1); - match &block[0] { - Statement::Pipeline(Pipeline { expressions }) => { - assert!(expressions.len() == 1); - assert!(matches!( - expressions[0], - Expression { - expr: Expr::Range( - None, - Some(_), - RangeOperator { - inclusion: RangeInclusion::Inclusive, - .. - } - ), - .. - } - )) - } - _ => panic!("No match"), - } - } - #[test] fn parse_right_unbounded_range() { let engine_state = EngineState::new(); @@ -394,4 +363,14 @@ mod range { _ => panic!("No match"), } } + + #[test] + fn bad_parse_does_crash() { + let engine_state = EngineState::new(); + let mut working_set = StateWorkingSet::new(&engine_state); + + let (_, err) = parse_source(&mut working_set, b"(0)..\"a\"", true); + + assert!(err.is_some()); + } }