Skip to content

Commit 5667a30

Browse files
committed
add tests
1 parent 6189a9d commit 5667a30

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

numbat/src/parser.rs

+23-9
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,8 @@ pub enum ParseErrorKind {
108108
#[error("Expected identifier")]
109109
ExpectedIdentifier,
110110

111-
#[error(
112-
"Expected identifier or function call after postfix apply (`//`) but instead got: `{0}`"
113-
)]
114-
ExpectedIdentifierOrCallAfterPostfixApply(String),
111+
#[error("Expected identifier or function call after postfix apply (`//`)")]
112+
ExpectedIdentifierOrCallAfterPostfixApply,
115113

116114
#[error("Expected dimension identifier, '1', or opening parenthesis")]
117115
ExpectedDimensionPrimary,
@@ -902,11 +900,9 @@ impl<'a> Parser<'a> {
902900
params.push(expr);
903901
expr = Expression::FunctionCall(call_span, full_span, call, params);
904902
}
905-
other => {
903+
_other => {
906904
return Err(ParseError::new(
907-
ParseErrorKind::ExpectedIdentifierOrCallAfterPostfixApply(format!(
908-
"{other:?}"
909-
)),
905+
ParseErrorKind::ExpectedIdentifierOrCallAfterPostfixApply,
910906
full_span,
911907
))
912908
}
@@ -1878,7 +1874,7 @@ mod tests {
18781874
for input in inputs {
18791875
match parse(input, 0) {
18801876
Err((_, errors)) => {
1881-
assert_eq!(errors[0].kind, error_kind);
1877+
assert_eq!(errors[0].kind, error_kind, "Failed on {}", input);
18821878
}
18831879
_ => {
18841880
panic!();
@@ -2755,6 +2751,24 @@ mod tests {
27552751
vec![binop!(scalar!(1.0), Add, scalar!(1.0))],
27562752
),
27572753
);
2754+
parse_as_expression(
2755+
&["1 + 1 // kefir(2)"],
2756+
Expression::FunctionCall(
2757+
Span::dummy(),
2758+
Span::dummy(),
2759+
Box::new(identifier!("kefir")),
2760+
vec![scalar!(2.0), binop!(scalar!(1.0), Add, scalar!(1.0))],
2761+
),
2762+
);
2763+
2764+
should_fail_with(&["1 // print()"], ParseErrorKind::InlineProcedureUsage);
2765+
2766+
should_fail_with(&["1 // +"], ParseErrorKind::ExpectedPrimary);
2767+
2768+
should_fail_with(
2769+
&["1 // 2", "1 // 1 +"],
2770+
ParseErrorKind::ExpectedIdentifierOrCallAfterPostfixApply,
2771+
);
27582772
}
27592773

27602774
#[test]

0 commit comments

Comments
 (0)