Move precedence tests into test_canonicalize

This commit is contained in:
Richard Feldman 2019-07-22 20:42:03 -04:00
parent a1234d68ba
commit 39c4380a31
2 changed files with 69 additions and 60 deletions

View file

@ -0,0 +1,69 @@
#[macro_use] extern crate pretty_assertions;
extern crate combine;
extern crate roc;
#[cfg(test)]
mod test_canonicalize {
// OPERATOR PRECEDENCE
// fn parse_with_precedence(input: &str) -> Result<(Expr, &str), easy::Errors<char, &str, IndentablePosition>> {
// parse_without_loc(input)
// .map(|(expr, remaining)| (expr::apply_precedence_and_associativity(loc(expr)).unwrap().value, remaining))
// }
// #[test]
// fn two_operator_precedence() {
// assert_eq!(
// parse_with_precedence("x + y * 5"),
// Ok((Operator(
// loc_box(var("x")),
// loc(Plus),
// loc_box(
// Operator(
// loc_box(var("y")),
// loc(Star),
// loc_box(Int(5))
// )
// ),
// ),
// ""))
// );
// assert_eq!(
// parse_with_precedence("x * y + 5"),
// Ok((Operator(
// loc_box(
// Operator(
// loc_box(var("x")),
// loc(Star),
// loc_box(var("y")),
// )
// ),
// loc(Plus),
// loc_box(Int(5))
// ),
// ""))
// );
// }
// #[test]
// fn compare_and() {
// assert_eq!(
// parse_with_precedence("x > 1 || True"),
// Ok((Operator(
// loc_box(
// Operator(
// loc_box(var("x")),
// loc(GreaterThan),
// loc_box(Int(1))
// )
// ),
// loc(Or),
// loc_box(ApplyVariant(vname("True"), None))
// ),
// ""))
// );
// }
}

View file

@ -1422,64 +1422,4 @@ mod test_parse {
) )
} }
// OPERATOR PRECEDENCE
fn parse_with_precedence(input: &str) -> Result<(Expr, &str), easy::Errors<char, &str, IndentablePosition>> {
parse_without_loc(input)
.map(|(expr, remaining)| (expr::apply_precedence_and_associativity(loc(expr)).unwrap().value, remaining))
}
#[test]
fn two_operator_precedence() {
assert_eq!(
parse_with_precedence("x + y * 5"),
Ok((Operator(
loc_box(var("x")),
loc(Plus),
loc_box(
Operator(
loc_box(var("y")),
loc(Star),
loc_box(Int(5))
)
),
),
""))
);
assert_eq!(
parse_with_precedence("x * y + 5"),
Ok((Operator(
loc_box(
Operator(
loc_box(var("x")),
loc(Star),
loc_box(var("y")),
)
),
loc(Plus),
loc_box(Int(5))
),
""))
);
}
#[test]
fn compare_and() {
assert_eq!(
parse_with_precedence("x > 1 || True"),
Ok((Operator(
loc_box(
Operator(
loc_box(var("x")),
loc(GreaterThan),
loc_box(Int(1))
)
),
loc(Or),
loc_box(ApplyVariant(vname("True"), None))
),
""))
);
}
} }