grammar: add repetition tests
This commit is contained in:
parent
476c97ddbd
commit
990bf5711a
1 changed files with 76 additions and 0 deletions
|
@ -279,6 +279,82 @@ static void test_quantifiers() {
|
|||
"catyyy",
|
||||
}
|
||||
);
|
||||
test_grammar(
|
||||
"simple exact repetition",
|
||||
// Grammar
|
||||
R"""(
|
||||
root ::= [ab]{4}
|
||||
)""",
|
||||
// Passing strings
|
||||
{
|
||||
"aaaa",
|
||||
"bbbb",
|
||||
"abab",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"a",
|
||||
"b",
|
||||
"aaaaa",
|
||||
}
|
||||
);
|
||||
test_grammar(
|
||||
"simple min repetition",
|
||||
// Grammar
|
||||
R"""(
|
||||
root ::= [ab]{4,}
|
||||
)""",
|
||||
// Passing strings
|
||||
{
|
||||
"aaaa",
|
||||
"aaaaab",
|
||||
"bbbb",
|
||||
"ababab",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"",
|
||||
"aba",
|
||||
}
|
||||
);
|
||||
test_grammar(
|
||||
"simple max repetition",
|
||||
// Grammar
|
||||
R"""(
|
||||
root ::= [ab]{0,4}
|
||||
)""",
|
||||
// Passing strings
|
||||
{
|
||||
"",
|
||||
"a",
|
||||
"aa",
|
||||
"aaa",
|
||||
"aaab",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"aaaaa",
|
||||
}
|
||||
);
|
||||
test_grammar(
|
||||
"min / max repetition",
|
||||
// Grammar
|
||||
R"""(
|
||||
root ::= ("0x" [A-F0-9]{2} " "?){3,5}
|
||||
)""",
|
||||
// Passing strings
|
||||
{
|
||||
"0xFF 0x12 0xAB",
|
||||
"0xFF 0x12 0xAB 0x00 0x00",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"",
|
||||
"0xFF",
|
||||
"0xFF 0x12",
|
||||
"0xFF 0x12 0xAB 0x00 0x00 0x00",
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
static void test_failure_missing_root() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue