MCPcopy Index your code
hub / github.com/endbasic/endbasic / test_expr_errors

Function test_expr_errors

core/src/parser.rs:3554–3597  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3552
3553 #[test]
3554 fn test_expr_errors() {
3555 // Note that all column numbers in the errors below are offset by 6 (due to "PRINT ") as
3556 // that's what the do_expr_error_test function is prefixing to the given strings.
3557
3558 do_expr_error_test("+3", "1:7: Not enough values to apply operator");
3559 do_expr_error_test("2 + * 3", "1:9: Not enough values to apply operator");
3560 do_expr_error_test("(2(3))", "1:9: Unexpected ( in expression");
3561 do_expr_error_test("((3)2)", "1:11: Unexpected value in expression");
3562 do_expr_error_test("2 3", "1:9: Unexpected value in expression");
3563
3564 do_expr_error_test("(", "1:8: Missing expression");
3565
3566 do_expr_error_test(")", "1:7: Expected comma, semicolon, or end of statement");
3567 do_expr_error_test("(()", "1:10: Missing expression");
3568 do_expr_error_test("())", "1:7: Expected expression");
3569 do_expr_error_test("3 + (2 + 1) + (4 - 5", "1:21: Unbalanced parenthesis");
3570 do_expr_error_test(
3571 "3 + 2 + 1) + (4 - 5)",
3572 "1:16: Expected comma, semicolon, or end of statement",
3573 );
3574
3575 do_expr_error_test("foo(,)", "1:11: Missing expression");
3576 do_expr_error_test("foo(, 3)", "1:11: Missing expression");
3577 do_expr_error_test("foo(3, )", "1:14: Missing expression");
3578 do_expr_error_test("foo(3, , 4)", "1:14: Missing expression");
3579 // TODO(jmmv): These are not the best error messages...
3580 do_expr_error_test("(,)", "1:8: Missing expression");
3581 do_expr_error_test("(3, 4)", "1:7: Expected expression");
3582 do_expr_error_test("((), ())", "1:10: Missing expression");
3583
3584 // TODO(jmmv): This succeeds because `PRINT` is interned as a `Token::Symbol` so the
3585 // expression parser sees it as a variable reference... but this should probably fail.
3586 // Would need to intern builtin call names as a separate token to catch this, but that
3587 // also means that the lexer must be aware of builtin call names upfront.
3588 use Expr::*;
3589 do_expr_ok_test(
3590 "1 + PRINT",
3591 Add(Box::from(BinaryOpSpan {
3592 lhs: expr_integer(1, 1, 7),
3593 rhs: expr_symbol(VarRef::new("PRINT", None), 1, 11),
3594 pos: lc(1, 9),
3595 })),
3596 );
3597 }
3598
3599 #[test]
3600 fn test_expr_errors_due_to_keywords() {

Callers

nothing calls this directly

Calls 5

do_expr_error_testFunction · 0.85
do_expr_ok_testFunction · 0.85
expr_integerFunction · 0.85
expr_symbolFunction · 0.85
lcFunction · 0.85

Tested by

no test coverage detected