Right now in the compiler's frontend tests we just check that expected errors happen. However, we don't check where they happen.
One way to do this would be in a way similar to how it's done in parser tests:
|
#[test] |
|
fn errors_on_return_statement() { |
|
// This shouldn't be parsed as a call |
|
let src = " |
|
return 1 |
|
^^^^^^^^ |
|
"; |
|
let (src, span) = get_source_with_error_span(src); |
|
let mut parser = Parser::for_str(&src); |
|
let statement = parser.parse_statement_or_error(); |
|
assert!(matches!(statement.kind, StatementKind::Error)); |
|
let reason = get_single_error_reason(&parser.errors, span); |
|
assert!(matches!(reason, ParserErrorReason::EarlyReturn)); |
|
} |
That is, allow squiggles bellow a line, pre-process that input and extract the span where the error would happen.
Right now in the compiler's frontend tests we just check that expected errors happen. However, we don't check where they happen.
One way to do this would be in a way similar to how it's done in parser tests:
noir/compiler/noirc_frontend/src/parser/parser/statement.rs
Lines 711 to 724 in 8783e48
That is, allow squiggles bellow a line, pre-process that input and extract the span where the error would happen.