Yield NULL from read_expression() on invalid input
This commit is contained in:
@@ -166,6 +166,20 @@ static void paren_1_plus_2_times_3_close_paren_parses_as_left_nested(void)
|
||||
ASSERT_EQUAL(3, operand1->number);
|
||||
}
|
||||
|
||||
static void garbage_input_yeilds_null(void)
|
||||
{
|
||||
init_memory_pool(&pool);
|
||||
const expression_t *result = read_expression(&pool, "arwizxhu", 8);
|
||||
ASSERT_NULL(result);
|
||||
}
|
||||
|
||||
static void valid_expression_followed_by_garbage_yeilds_null(void)
|
||||
{
|
||||
init_memory_pool(&pool);
|
||||
const expression_t *result = read_expression(&pool, "5+2jvkre", 8);
|
||||
ASSERT_NULL(result);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TESTING_BEGIN();
|
||||
@@ -180,5 +194,7 @@ int main(void)
|
||||
RUN_TEST(input_1_times_2_times_3_is_parsed_as_a_left_nested_application);
|
||||
RUN_TEST(input_1_plus_2_times_3_is_parsed_as_a_right_nested_application);
|
||||
RUN_TEST(paren_1_plus_2_times_3_close_paren_parses_as_left_nested);
|
||||
RUN_TEST(garbage_input_yeilds_null);
|
||||
RUN_TEST(valid_expression_followed_by_garbage_yeilds_null);
|
||||
TESTING_END();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user