fix all gen and cli tests

This commit is contained in:
Folkert 2021-02-02 22:06:11 +01:00
parent e643d1ea3c
commit f6aa77e6a8
4 changed files with 37 additions and 7 deletions

View file

@ -3382,7 +3382,6 @@ fn canonicalize_and_constrain<'a>(
}
fn parse<'a>(arena: &'a Bump, header: ModuleHeader<'a>) -> Result<Msg<'a>, LoadingProblem> {
println!("-------- parsing {:?}", header.module_id);
let mut module_timing = header.module_timing;
let parse_start = SystemTime::now();
let parse_state = parser::State::new(&header.src, Attempting::Module);

View file

@ -387,7 +387,9 @@ fn spaces<'a>(
);
if any_newlines {
state = state.check_indent(min_indent).map_err(
|(fail, _)| (progress, fail, original_state),
|(fail, _)| {
(progress, fail, original_state.clone())
},
)?;
}

View file

@ -596,10 +596,13 @@ fn body<'a>(min_indent: u16) -> impl Parser<'a, Body<'a>> {
equals_for_def(),
// Spaces after the '=' (at a normal indentation level) and then the expr.
// The expr itself must be indented more than the pattern and '='
space0_before(
loc!(move |arena, state| parse_expr(indented_more, arena, state)),
min_indent,
)
move |a, s| {
space0_before(
loc!(move |arena, state| { parse_expr(indented_more, arena, state) }),
min_indent,
)
.parse(a, s)
}
)
);
result
@ -1540,7 +1543,8 @@ pub fn if_expr<'a>(min_indent: u16) -> impl Parser<'a, Expr<'a>> {
),
skip_first!(
parser::keyword(keyword::ELSE, min_indent),
space1_around(
// NOTE changed this from space1_around to space1_before
space1_before(
loc!(move |arena, state| parse_expr(min_indent, arena, state)),
min_indent,
)

View file

@ -2819,6 +2819,31 @@ mod test_parse {
assert!(actual.is_ok());
}
#[test]
fn outdenting_newline_after_else() {
use roc_parse::ast::Def::*;
let arena = Bump::new();
// highlights a problem with the else branch demanding a newline after its expression
let src = indoc!(
r#"
main =
v = \y -> if x then y else z
1
"#
);
let actual = module_defs()
.parse(&arena, State::new(src.as_bytes(), Attempting::Module))
.map(|tuple| tuple.1);
dbg!(&actual);
assert!(actual.is_ok());
}
#[test]
fn newline_after_equals() {
// Regression test for https://github.com/rtfeldman/roc/issues/51