Fixed tests.

This commit is contained in:
Jacob Signorovitch 2025-01-25 09:22:31 -05:00
parent 4dd1f2b5f1
commit c94d7863a7

View File

@ -16,6 +16,27 @@ void test_ast_num() {
ast_destroy(ast); ast_destroy(ast);
} }
void test_ast_call() {
AST** argv = malloc(2*sizeof(AST*));
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(1.0));
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init(2.0));
char* name = malloc(2);
strcpy(name, "f");
ASTCallData* call = ast_call_data_init(name, 2, argv);
AST* ast = ast_init(AST_TYPE_CALL, call);
TEST_ASSERT_EQUAL(AST_TYPE_CALL, ast->type);
TEST_ASSERT_EQUAL(name, ((ASTCallData*)ast->data)->to);
TEST_ASSERT_EQUAL(2, ((ASTCallData*)ast->data)->argc);
TEST_ASSERT_EQUAL(1.0, ((ASTCallData*)ast->data)->argv[0]);
TEST_ASSERT_EQUAL(2.0, ((ASTCallData*)ast->data)->argv[1]);
ast_destroy(ast);
}
void test_ast_vref() { void test_ast_vref() {
char* s = malloc(2); char* s = malloc(2);
strcpy(s, "x"); strcpy(s, "x");
@ -29,28 +50,10 @@ void test_ast_vref() {
//ast_destroy(ast); //ast_destroy(ast);
} }
void test_ast_call() {
AST** argv = malloc(2*sizeof(AST*));
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(1.0));
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init(2.0));
ASTCallData* call = ast_call_data_init("f", 2, argv);
AST* ast = ast_init(AST_TYPE_CALL, call);
TEST_ASSERT_EQUAL(AST_TYPE_CALL, ast->type);
TEST_ASSERT_EQUAL("f", ((ASTCallData*)ast->data)->to);
TEST_ASSERT_EQUAL(2, ((ASTCallData*)ast->data)->argc);
TEST_ASSERT_EQUAL(1.0, ((ASTCallData*)ast->data)->argv[0]);
TEST_ASSERT_EQUAL(2.0, ((ASTCallData*)ast->data)->argv[1]);
ast_destroy(ast);
}
int main() { int main() {
UNITY_BEGIN(); UNITY_BEGIN();
RUN_TEST(test_ast_num); RUN_TEST(test_ast_num);
RUN_TEST(test_ast_vref);
RUN_TEST(test_ast_call); RUN_TEST(test_ast_call);
//RUN_TEST(test_ast_vref);
return UNITY_END(); return UNITY_END();
} }