test(rust): prefer asserts to panics
This commit is contained in:
parent
b0cdab85fe
commit
ce56465197
6 changed files with 42 additions and 43 deletions
|
|
@ -591,14 +591,13 @@ mod test {
|
|||
]);
|
||||
grammar.external_tokens = vec![Variable::named("rule_1", Rule::non_terminal(1))];
|
||||
|
||||
match extract_tokens(grammar) {
|
||||
Err(e) => {
|
||||
assert_eq!(e.to_string(), "Rule 'rule_1' cannot be used as both an external token and a non-terminal rule");
|
||||
}
|
||||
_ => {
|
||||
panic!("Expected an error but got no error");
|
||||
}
|
||||
}
|
||||
let result = extract_tokens(grammar);
|
||||
assert!(result.is_err(), "Expected an error but got no error");
|
||||
let err = result.err().unwrap();
|
||||
assert_eq!(
|
||||
err.to_string(),
|
||||
"Rule 'rule_1' cannot be used as both an external token and a non-terminal rule"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -279,10 +279,9 @@ mod tests {
|
|||
fn test_grammar_with_undefined_symbols() {
|
||||
let result = intern_symbols(&build_grammar(vec![Variable::named("x", Rule::named("y"))]));
|
||||
|
||||
match result {
|
||||
Err(e) => assert_eq!(e.to_string(), "Undefined symbol `y`"),
|
||||
_ => panic!("Expected an error but got none"),
|
||||
}
|
||||
assert!(result.is_err(), "Expected an error but got none");
|
||||
let e = result.err().unwrap();
|
||||
assert_eq!(e.to_string(), "Undefined symbol `y`");
|
||||
}
|
||||
|
||||
fn build_grammar(variables: Vec<Variable>) -> InputGrammar {
|
||||
|
|
|
|||
|
|
@ -549,10 +549,9 @@ mod tests {
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
if let Err(error) = process_inlines(&grammar, &lexical_grammar) {
|
||||
assert_eq!(error.to_string(), "Token `something` cannot be inlined");
|
||||
} else {
|
||||
panic!("expected an error, but got none");
|
||||
}
|
||||
let result = process_inlines(&grammar, &lexical_grammar);
|
||||
assert!(result.is_err(), "expected an error, but got none");
|
||||
let err = result.err().unwrap();
|
||||
assert_eq!(err.to_string(), "Token `something` cannot be inlined",);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue