Handle quantifiers in parse_term()

This commit is contained in:
2024-10-25 14:59:24 +01:00
parent 80a26997b8
commit 40db26a62d
2 changed files with 63 additions and 1 deletions

View File

@@ -172,6 +172,45 @@ static void a_in_parens_b_is_parsed_as_sequence_with_regex_term(void)
regex_free_children(&r);
}
static void dot_star_is_parsed_as_zero_or_more_wildcard(void)
{
regex_t r = { 0 };
const int result = PARSE_REGEX_STRING(".*", &r);
ASSERT_NE(-1, result);
ASSERT_EQ(1, r.sequence.len);
ASSERT_EQ(QUANTIFIER_ZERO_OR_MORE, r.sequence.contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_WILDCARD, r.sequence.contents[0].type);
regex_free_children(&r);
}
static void dot_plus_is_parsed_as_one_or_more_wildcard(void)
{
regex_t r = { 0 };
const int result = PARSE_REGEX_STRING(".+", &r);
ASSERT_NE(-1, result);
ASSERT_EQ(1, r.sequence.len);
ASSERT_EQ(QUANTIFIER_ONE_OR_MORE, r.sequence.contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_WILDCARD, r.sequence.contents[0].type);
regex_free_children(&r);
}
static void dot_question_mark_is_parsed_as_zero_or_one_wildcard(void)
{
regex_t r = { 0 };
const int result = PARSE_REGEX_STRING(".?", &r);
ASSERT_NE(-1, result);
ASSERT_EQ(1, r.sequence.len);
ASSERT_EQ(QUANTIFIER_ZERO_OR_ONE, r.sequence.contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_WILDCARD, r.sequence.contents[0].type);
regex_free_children(&r);
}
int main(void)
{
TESTING_BEGIN();
@@ -186,5 +225,8 @@ int main(void)
backslash_backslash_is_parsed_as_unquantified_literal();
a_pipe_b_in_parens_is_parsed_as_regex_term();
a_in_parens_b_is_parsed_as_sequence_with_regex_term();
dot_star_is_parsed_as_zero_or_more_wildcard();
dot_plus_is_parsed_as_one_or_more_wildcard();
dot_question_mark_is_parsed_as_zero_or_one_wildcard();
return TESTING_END();
}