Files
imp/tests/integration_tests.c

56 lines
1.1 KiB
C

#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)"));
}
static void test_nested_arithmetic(void)
{
TEST_ASSERT_EQUAL_STRING("20", read_eval_print("(+ 1 (* 2 (+ 3 4)) 5)"));
TEST_ASSERT_EQUAL_STRING("-6", read_eval_print("(+ 1 (* 2 2 (- 3)) 5)"));
}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_unnested_arithmetic);
RUN_TEST(test_nested_arithmetic);
return UNITY_END();
}