Add parser tests for function calls
This commit is contained in:
parent
96b1fecdcd
commit
76f3c776a0
1 changed files with 77 additions and 0 deletions
|
|
@ -1141,6 +1141,82 @@ TEST(complex_function, t) {
|
|||
destroy_parser_test(pt);
|
||||
}
|
||||
|
||||
TEST(function_calls, t) {
|
||||
struct parser_test *pt = new_parser_test(t,
|
||||
"foo\n"
|
||||
"(foo)\n"
|
||||
"foo bar\n"
|
||||
"(foo bar)\n"
|
||||
"((foo bar))\n"
|
||||
"foo bar ~baz\n"
|
||||
);
|
||||
expect_expr(pt, (struct apfl_expr) {
|
||||
.type = APFL_EXPR_VAR,
|
||||
.position = POS(1, 1),
|
||||
.var = new_string(pt, "foo"),
|
||||
});
|
||||
expect_expr(pt, (struct apfl_expr) {
|
||||
.type = APFL_EXPR_CALL,
|
||||
.position = POS(2, 1),
|
||||
.call = {
|
||||
.callee = new_var(pt, 2, 2, "foo"),
|
||||
.arguments = LIST_BEGIN(pt, list)
|
||||
LIST_END,
|
||||
},
|
||||
});
|
||||
expect_expr(pt, (struct apfl_expr) {
|
||||
.type = APFL_EXPR_CALL,
|
||||
.position = POS(3, 1),
|
||||
.call = {
|
||||
.callee = new_var(pt, 3, 1, "foo"),
|
||||
.arguments = LIST_BEGIN(pt, list)
|
||||
LIST_ADD list_item(false, new_var(pt, 3, 5, "bar")),
|
||||
LIST_END,
|
||||
},
|
||||
});
|
||||
expect_expr(pt, (struct apfl_expr) {
|
||||
.type = APFL_EXPR_CALL,
|
||||
.position = POS(4, 1),
|
||||
.call = {
|
||||
.callee = new_var(pt, 4, 2, "foo"),
|
||||
.arguments = LIST_BEGIN(pt, list)
|
||||
LIST_ADD list_item(false, new_var(pt, 4, 6, "bar")),
|
||||
LIST_END,
|
||||
},
|
||||
});
|
||||
expect_expr(pt, (struct apfl_expr) {
|
||||
.type = APFL_EXPR_CALL,
|
||||
.position = POS(5, 1),
|
||||
.call = {
|
||||
.callee = BEGIN_NEW(pt, struct apfl_expr) {
|
||||
.type = APFL_EXPR_CALL,
|
||||
.position = POS(5, 2),
|
||||
.call = {
|
||||
.callee = new_var(pt, 5, 3, "foo"),
|
||||
.arguments = LIST_BEGIN(pt, list)
|
||||
LIST_ADD list_item(false, new_var(pt, 5, 7, "bar")),
|
||||
LIST_END,
|
||||
},
|
||||
} END_NEW,
|
||||
.arguments = LIST_BEGIN(pt, list)
|
||||
LIST_END
|
||||
},
|
||||
});
|
||||
expect_expr(pt, (struct apfl_expr) {
|
||||
.type = APFL_EXPR_CALL,
|
||||
.position = POS(6, 1),
|
||||
.call = {
|
||||
.callee = new_var(pt, 6, 1, "foo"),
|
||||
.arguments = LIST_BEGIN(pt, list)
|
||||
LIST_ADD list_item(false, new_var(pt, 6, 5, "bar")),
|
||||
LIST_ADD list_item(true, new_var(pt, 6, 10, "baz")),
|
||||
LIST_END,
|
||||
},
|
||||
});
|
||||
expect_eof(pt);
|
||||
destroy_parser_test(pt);
|
||||
}
|
||||
|
||||
TEST(err_empty_assignment, t) {
|
||||
struct parser_test *pt = new_parser_test(t, "= foo bar");
|
||||
expect_error_of_type(pt, APFL_ERR_EMPTY_ASSIGNMENT);
|
||||
|
|
@ -1243,6 +1319,7 @@ TESTS_BEGIN
|
|||
ADDTEST(assignment),
|
||||
ADDTEST(simple_function),
|
||||
ADDTEST(complex_function),
|
||||
ADDTEST(function_calls),
|
||||
ADDTEST(err_empty_assignment),
|
||||
ADDTEST(err_mismatching_parens),
|
||||
ADDTEST(err_unclosed_func),
|
||||
|
|
|
|||
Loading…
Reference in a new issue