diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 409973f..7085734 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,6 +13,7 @@ add_test_suites( env_tests.c eval_tests.c expr_tests.c + integration_tests.c parse_tests.c prim_tests.c print_tests.c diff --git a/tests/integration_tests.c b/tests/integration_tests.c new file mode 100644 index 0000000..d53d03e --- /dev/null +++ b/tests/integration_tests.c @@ -0,0 +1,48 @@ +#include "eval.h" +#include "memory_stream.h" +#include "print.h" +#include "read.h" +#include "unity.h" + +#include + +#define BUFFER_SIZE 256U + +static am_t am; +static char buffer[BUFFER_SIZE]; + +static const char *read_eval_print(const char *input) +{ + memory_stream_t stream; + memory_stream_init(&stream, (const uint8_t *)input, strlen(input)); + read(&am, (stream_t *)&stream); + + eval(&am); + + memset(buffer, 0, sizeof(buffer)); + print(&am, buffer, BUFFER_SIZE - 1); + return buffer; +} + +void setUp(void) +{ + am_init(&am); +} + +void tearDown(void) +{ +} + +static void test_unnested_arithmetic(void) +{ + TEST_ASSERT_EQUAL_STRING("10", read_eval_print("(+ 1 2 3 4)")); + TEST_ASSERT_EQUAL_STRING("42", read_eval_print("(* 2 21)")); + TEST_ASSERT_EQUAL_STRING("64", read_eval_print("(- 100 36)")); +} + +int main(void) +{ + UNITY_BEGIN(); + RUN_TEST(test_unnested_arithmetic); + return UNITY_END(); +}