Add paren support to reader
This commit is contained in:
@@ -141,6 +141,31 @@ input_1_plus_2_times_3_is_parsed_as_a_right_nested_application(void)
|
||||
ASSERT_EQUAL(3, operand1->application.operands[1]->number);
|
||||
}
|
||||
|
||||
static void paren_1_plus_2_times_3_close_paren_parses_as_left_nested(void)
|
||||
{
|
||||
init_memory_pool(&pool);
|
||||
const expression_t *result = read_expression(&pool, "(1+2)*3", 7);
|
||||
ASSERT_NOT_NULL(result);
|
||||
ASSERT_FALSE(result->is_number);
|
||||
ASSERT_EQUAL(OPERATOR_MULTIPLY, result->application.operator);
|
||||
|
||||
const expression_t *operand0 = result->application.operands[0];
|
||||
ASSERT_NOT_NULL(operand0);
|
||||
ASSERT_FALSE(operand0->is_number);
|
||||
ASSERT_EQUAL(OPERATOR_ADD, operand0->application.operator);
|
||||
ASSERT_NOT_NULL(operand0->application.operands[0]);
|
||||
ASSERT_TRUE(operand0->application.operands[0]->is_number);
|
||||
ASSERT_EQUAL(1, operand0->application.operands[0]->number);
|
||||
ASSERT_NOT_NULL(operand0->application.operands[1]);
|
||||
ASSERT_TRUE(operand0->application.operands[1]->is_number);
|
||||
ASSERT_EQUAL(2, operand0->application.operands[1]->number);
|
||||
|
||||
const expression_t *operand1 = result->application.operands[1];
|
||||
ASSERT_NOT_NULL(operand1);
|
||||
ASSERT_TRUE(operand1->is_number);
|
||||
ASSERT_EQUAL(3, operand1->number);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TESTING_BEGIN();
|
||||
@@ -154,5 +179,6 @@ int main(void)
|
||||
RUN_TEST(input_1_plus_2_plus_3_is_parsed_as_a_left_nested_application);
|
||||
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);
|
||||
TESTING_END();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user