Add integration tests
This commit is contained in:
@@ -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
|
||||
|
||||
48
tests/integration_tests.c
Normal file
48
tests/integration_tests.c
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "eval.h"
|
||||
#include "memory_stream.h"
|
||||
#include "print.h"
|
||||
#include "read.h"
|
||||
#include "unity.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
Reference in New Issue
Block a user