Commit 77bab142 authored by Chris Müller's avatar Chris Müller
Browse files

add testcases for character literals

parent 595ae31c
......@@ -23,7 +23,7 @@
static void test_lex_fixnum(const_pointer data)
{
byte_t* fixnum = "0 0xFF 0xFF_FF 1_000 0777 0b0001 0b0001_1111";
byte_t* fixnum = "0 0xFF 0xFFFF 1000 0777 0b0001 0b00011111";
struct CyContext* c = cy_context_repl_new(fixnum);
assert(cy_lex(c) == TOK_DEC);
......@@ -72,10 +72,86 @@ static void test_lex_float(const_pointer data)
}
static void test_lex_string(const_pointer data)
{
byte_t* str = " \"asdf\" \"test\\uFFFF\\UFFFFFFFF\\n\" ";
struct CyContext* c = cy_context_repl_new(str);
assert(cy_lex(c) == TOK_STRING);
assert(strcmp(cy_token_string(c), "asdf") == 0);
assert(cy_lex(c) == TOK_STRING);
assert(strcmp(cy_token_string(c), "test\\uFFFF\\UFFFFFFFF\\n") == 0);
cy_context_free(c);
}
static void test_lex_comment(const_pointer data)
{
byte_t* comment = "; comment\n";
struct CyContext* c = cy_context_repl_new(comment);
assert(cy_lex(c) == TOK_COMMENT);
assert(strcmp(cy_token_string(c), "; comment") == 0);
cy_context_free(c);
}
static void test_lex_symbols(const_pointer data)
{
byte_t* str = " true false null? + - ";
struct CyContext* c = cy_context_repl_new(str);
assert(cy_lex(c) == TOK_TRUE);
assert(cy_lex(c) == TOK_FALSE);
assert(cy_lex(c) == TOK_SYMBOL);
assert(strcmp(cy_token_string(c), "null?") == 0);
assert(cy_lex(c) == TOK_SYMBOL);
assert(strcmp(cy_token_string(c), "+") == 0);
assert(cy_lex(c) == TOK_SYMBOL);
assert(strcmp(cy_token_string(c), "-") == 0);
cy_context_free(c);
}
static void test_lex_characters(const_pointer data)
{
byte_t* str = " \\a \\A \\uFFFF \\newline \\space ";
struct CyContext* c = cy_context_repl_new(str);
assert(cy_lex(c) == TOK_CHAR);
assert(strcmp(cy_token_string(c), "\\a") == 0);
assert(cy_lex(c) == TOK_CHAR);
assert(strcmp(cy_token_string(c), "\\A") == 0);
assert(cy_lex(c) == TOK_CHAR);
assert(strcmp(cy_token_string(c), "\\uFFFF") == 0);
assert(cy_lex(c) == TOK_CHAR);
assert(strcmp(cy_token_string(c), "\\newline") == 0);
assert(cy_lex(c) == TOK_CHAR);
assert(strcmp(cy_token_string(c), "\\space") == 0);
cy_context_free(c);
}
void test_suite_lex()
{
cry_unittest_run("org.cherry.parser/lex_fixnum", test_lex_fixnum, 0, 100);
cry_unittest_run("org.cherry.parser/lex_float", test_lex_float, 0, 100);
cry_unittest_run("org.cherry.parser/lex_string", test_lex_string, 0, 100);
cry_unittest_run("org.cherry.parser/lex_comment", test_lex_comment, 0, 100);
cry_unittest_run("org.cherry.parser/lex_symbols", test_lex_symbols, 0, 100);
cry_unittest_run("org.cherry.parser/lex_characters", test_lex_characters, 0, 100);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment