1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include "../test.h"
#include "../helpers.h"
static int test_optional(void)
{
test_start("optional");
cleri_grammar_t * grammar;
cleri_t * k_hi, * optional;
k_hi = cleri_keyword(0, "hi", false);
optional = cleri_optional(0, k_hi);
grammar = cleri_grammar(optional, NULL);
// assert statements
_assert_is_valid (grammar, "hi");
_assert_is_valid (grammar, "");
_assert_is_not_valid(grammar, "hello");
_assert_parse_str (
grammar,
"hello",
"error at line 1, position 0, "
"unexpected `hello`, expecting: hi or end_of_statement",
NULL);
_assert_parse_str (
grammar,
"hi hi",
"error at line 1, position 2, expecting: end_of_statement",
NULL);
_assert_parse_str2 (
grammar,
"hello",
"error at line 1, position 0, unexpected `hello`",
NULL);
_assert_parse_str2 (
grammar,
"hi hi",
"error at line 1, position 2",
NULL);
cleri_grammar_free(grammar);
return test_end();
}
int main()
{
return (
test_optional() ||
0
);
}
|