Decaf Compiler
testsuite.h
Go to the documentation of this file.
1 
6 #include <stdbool.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <stdint.h>
10 #include <assert.h>
11 #include <time.h>
12 
13 #include <check.h>
14 
15 #include "p1-lexer.h"
16 
20 #define TEST_INVALID(NAME,TEXT) START_TEST (NAME) \
21 { ck_assert (invalid_tokens(TEXT)); } \
22 END_TEST
23 
27 #define TEST_0TOKENS(NAME,TEXT) START_TEST (NAME) \
28 { ck_assert (valid_0tokens(TEXT)); } \
29 END_TEST
30 
34 #define TEST_1TOKEN(NAME,TEXT,ETYPE,ETEXT) START_TEST (NAME) \
35 { ck_assert (valid_1token(TEXT, ETYPE, ETEXT)); } \
36 END_TEST
37 
41 #define TEST_2TOKENS(NAME,TEXT,ETYPE1,ETEXT1,ETYPE2,ETEXT2) START_TEST (NAME) \
42 { ck_assert (valid_2tokens(TEXT, ETYPE1, ETEXT1, ETYPE2, ETEXT2)); } \
43 END_TEST
44 
48 #define TEST_TOKENS(NAME,TEXT,NTOKENS,ETOKENS) START_TEST (NAME) \
49 { ck_assert (valid_tokens(TEXT, NTOKENS, ETOKENS)); } \
50 END_TEST
51 
55 #define TEST(NAME) tcase_add_test (tc, NAME)
56 
66 TokenQueue* run_lexer (char* text);
67 
80 TokenQueue* run_lexer_check_size (char* text, size_t expected_length);
81 
88 bool invalid_tokens (char* text);
89 
97 bool valid_0tokens (char* text);
98 
109 bool valid_1token (char* text, TokenType expected_type, const char* expected_text);
110 
122 bool valid_2tokens (char* text, TokenType expected_type1, const char* expected_text1,
123  TokenType expected_type2, const char* expected_text2);
124 
135 bool valid_tokens(char* text, size_t ntokens, Token expected_tokens[]);
valid_tokens
bool valid_tokens(char *text, size_t ntokens, Token expected_tokens[])
Run lexer on given text and verify that it returns tokens of the appropriate type.
Definition: testsuite.c:81
valid_1token
bool valid_1token(char *text, TokenType expected_type, const char *expected_text)
Run lexer on given text and verify that it returns a single correct token.
Definition: testsuite.c:50
TokenQueue
Linked list of tokens.
Definition: token.h:152
Token
Single token.
Definition: token.h:78
valid_2tokens
bool valid_2tokens(char *text, TokenType expected_type1, const char *expected_text1, TokenType expected_type2, const char *expected_text2)
Run lexer on given text and verify that it returns two correct tokens.
Definition: testsuite.c:63
TokenType
TokenType
Valid token types.
Definition: token.h:69
valid_0tokens
bool valid_0tokens(char *text)
Run lexer on given text and verify that it returns no tokens (but also does not throw an exception).
Definition: testsuite.c:41
invalid_tokens
bool invalid_tokens(char *text)
Run lexer on given text and verify that it throws an exception.
Definition: testsuite.c:36
run_lexer_check_size
TokenQueue * run_lexer_check_size(char *text, size_t expected_length)
Run lexer on given text and check length of resulting token queue.
Definition: testsuite.c:21
p1-lexer.h
Interface for Project 1 (Lexer)
run_lexer
TokenQueue * run_lexer(char *text)
Run lexer on given text.
Definition: testsuite.c:10