Test disjunction parser

This commit is contained in:
Patrick Lühne 2020-03-27 04:54:40 +01:00
parent 17d8dbd8ba
commit 5ea0a96ec4
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
1 changed files with 40 additions and 0 deletions

View File

@ -531,6 +531,46 @@ mod tests
assert_eq!(formula_remainder("p (and q)"), " (and q)");
}
#[test]
fn parse_or()
{
let formula_as_or = |i| match formula(i)
{
Formula::Or(arguments) => arguments,
_ => panic!("expected disjunction"),
};
let as_predicate = |x| match x
{
Formula::Predicate(arguments) => arguments,
_ => panic!("expected predicate"),
};
assert_eq!(format_formula("true or false"), "true or false");
assert_eq!(formula_as_or("true or false").len(), 2);
assert_eq!(*formula_as_or("true or false").remove(0), Formula::true_());
assert_eq!(*formula_as_or("true or false").remove(1), Formula::false_());
// The order of elements is retained
assert_ne!(formula("true or false"), formula("false or true"));
assert_eq!(format_formula("p or q or r or s"), "p or q or r or s");
assert_eq!(
as_predicate(*formula_as_or("p or q or r or s").remove(0)).declaration.name, "p");
assert_eq!(
as_predicate(*formula_as_or("p or q or r or s").remove(3)).declaration.name, "s");
let formula = |i| original::formula(i, &Declarations::new());
// Malformed formulas shouldnt be accepted
assert!(formula("or").is_err());
assert!(formula("or p").is_err());
assert_eq!(formula_remainder("p or"), " or");
assert_eq!(formula_remainder("p orq"), " orq");
assert_eq!(formula_remainder("p or q or"), " or");
assert_eq!(formula_remainder("p or q orq"), " orq");
assert!(formula("(p or) q").is_err());
assert_eq!(formula_remainder("p (or q)"), " (or q)");
}
#[test]
fn parse_predicate()
{