Commit 60055a32 authored by Chris Müller's avatar Chris Müller
Browse files

add lex testcase for rewinding and fix a relating assertion

parent d53e1fc8
......@@ -631,7 +631,7 @@ void
org_cherry_rewind(struct org_cherry_context* context, const byte_t* pos)
{
assert(context != 0);
assert(context->begin >= pos && pos >= context->src);
assert(context->begin <= pos && pos <= context->src);
context->src = pos;
}
......
......@@ -163,10 +163,38 @@ static void test_lex_core(const_pointer data)
org_cherry_context_free(c);
}
static void test_lex_rewind(const_pointer data)
{
byte_t* str = " [ ] ( ) . ' ";
struct org_cherry_context* c = org_cherry_context_repl(str);
assert(org_cherry_lex(c) == TOK_SQUARELEFTBRACE);
const byte_t* position = org_cherry_pos(c);
assert(org_cherry_lex(c) == TOK_SQUARERIGHTBRACE);
assert(org_cherry_lex(c) == TOK_ROUNDLEFTBRACE);
assert(org_cherry_lex(c) == TOK_ROUNDRIGHTBRACE);
org_cherry_rewind(c, position);
assert(org_cherry_lex(c) == TOK_SQUARERIGHTBRACE);
assert(org_cherry_lex(c) == TOK_ROUNDLEFTBRACE);
assert(org_cherry_lex(c) == TOK_ROUNDRIGHTBRACE);
assert(org_cherry_lex(c) == TOK_DOT);
assert(org_cherry_lex(c) == TOK_QUOTE);
assert(org_cherry_lex(c) == TOK_EOF);
org_cherry_context_free(c);
}
void test_suite_lex()
{
cry_unittest_run("org.cherry.parser/lex_core", test_lex_core, 0, 100);
cry_unittest_run("org.cherry.parser/lex_rewind", test_lex_rewind, 0, 100);
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);
......
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