test for malformed header

This commit is contained in:
Folkert 2021-07-19 20:37:39 +02:00
parent e7223fe176
commit 89fd4c3074
2 changed files with 65 additions and 0 deletions

View file

@ -3263,6 +3263,34 @@ fn to_requires_report<'a>(
}
}
ERequires::Rigid(row, col) => {
let surroundings = Region::from_rows_cols(start_row, start_col, row, col);
let region = Region::from_row_col(row, col);
let doc = alloc.stack(vec![
alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"),
alloc.region_with_subregion(surroundings, region),
alloc.concat(vec![
alloc.reflow("I am expecting a list of rigids like "),
alloc.keyword("{}"),
alloc.reflow(" or "),
alloc.keyword("{model=>Model}"),
alloc.reflow(" next. A full "),
alloc.keyword("requires"),
alloc.reflow(" definition looks like"),
]),
alloc
.parser_suggestion("requires {model=>Model, msg=>Msg} {main : Effect {}} ")
.indent(4),
]);
Report {
filename,
doc,
title: "BAD RIGIDS".to_string(),
}
}
_ => todo!("unhandled parse error {:?}", parse_problem),
}
}

View file

@ -5929,6 +5929,43 @@ mod test_reporting {
)
}
#[test]
fn platform_requires_rigids() {
report_header_problem_as(
indoc!(
r#"
platform folkertdev/foo
requires { main : Effect {} }
exposes []
packages {}
imports [Task]
provides [ mainForHost ]
effects fx.Effect
{
putChar : I64 -> Effect {},
putLine : Str -> Effect {},
getLine : Effect Str
}
"#
),
indoc!(
r#"
WEIRD PROVIDES
I am partway through parsing a provides list, but I got stuck here:
3 imports [base.Task, Base64 ]
4 provides [ main, @Foo ] to base
^
I was expecting a type name, value name or function name next, like
provides [ Animal, default, tame ]
"#
),
)
}
#[test]
fn exposes_identifier() {
report_header_problem_as(