mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Move precedence tests into test_canonicalize
This commit is contained in:
parent
a1234d68ba
commit
39c4380a31
2 changed files with 69 additions and 60 deletions
69
tests/test_canonicalize.rs
Normal file
69
tests/test_canonicalize.rs
Normal 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))
|
||||||
|
// ),
|
||||||
|
// ""))
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
}
|
|
@ -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))
|
|
||||||
),
|
|
||||||
""))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue