Fix parsing error if parentheses are padded with whitespace

This commit is contained in:
Oliver Hamlet
2018-11-14 20:51:02 +00:00
parent 579ba2969a
commit 3007a9e090
+16 -1
View File
@@ -243,7 +243,7 @@ impl Condition {
preceded!(fix_error!(ParsingError, ws!(tag!("not"))), call!(Function::parse)) => { preceded!(fix_error!(ParsingError, ws!(tag!("not"))), call!(Function::parse)) => {
|f| Condition::InvertedFunction(f) |f| Condition::InvertedFunction(f)
} | } |
delimited!(fix_error!(ParsingError, tag!("(")), call!(parse_expression), fix_error!(ParsingError, tag!(")"))) => { delimited!(fix_error!(ParsingError, ws!(tag!("("))), call!(parse_expression), fix_error!(ParsingError, ws!(tag!(")")))) => {
|e| Condition::Expression(e) |e| Condition::Expression(e)
} }
) >> (condition) ) >> (condition)
@@ -585,6 +585,21 @@ mod tests {
} }
} }
#[test]
fn condition_parse_should_handle_an_expression_in_parentheses_with_whitespace() {
let result = Condition::parse("( not file(\"Cargo.toml\") )".into())
.unwrap()
.1;
match result {
Condition::Expression(_) => {}
v => panic!(
"Expected an expression with two compound conditions, got {:?}",
v
),
}
}
#[test] #[test]
fn condition_eval_should_return_function_eval_for_a_function_condition() { fn condition_eval_should_return_function_eval_for_a_function_condition() {
let state = state("."); let state = state(".");