49 lines
883 B
C
49 lines
883 B
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)"));
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_unnested_arithmetic);
|
|
return UNITY_END();
|
|
}
|