Merge pull request #17 from jntrnr/fix_15

Fix #15
This commit is contained in:
JT 2021-09-06 06:48:59 +12:00 committed by GitHub
commit fda7e096cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 32 deletions

View file

@ -27,6 +27,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
args: --all
- uses: actions-rs/cargo@v1
with:

View file

@ -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(

View file

@ -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());
}
}