Support + and ? in construct_nfa()
This commit is contained in:
@@ -181,6 +181,52 @@ static void test_star(void)
|
||||
fsa_free(&fsa);
|
||||
}
|
||||
|
||||
static void test_plus(void)
|
||||
{
|
||||
regex_term_t *terms = malloc(1 * sizeof(regex_term_t));
|
||||
terms[0].quantifier = REGEX_QUANTIFIER_PLUS;
|
||||
terms[0].type = REGEX_TERM_LITERAL;
|
||||
terms[0].literal = 'a';
|
||||
regex_sequence_t *alternatives = malloc(1 * sizeof(regex_sequence_t));
|
||||
alternatives[0].count = alternatives[0].capacity = 1;
|
||||
alternatives[0].contents = terms;
|
||||
regex_t regex = { .count = 1, .capacity = 1, .contents = alternatives };
|
||||
|
||||
fsa_t fsa;
|
||||
construct_nfa(®ex, &fsa);
|
||||
|
||||
ASSERT_TRUE(accepts(&fsa, "a"));
|
||||
ASSERT_TRUE(accepts(&fsa, "aaaaaa"));
|
||||
ASSERT_FALSE(accepts(&fsa, ""));
|
||||
ASSERT_FALSE(accepts(&fsa, "b"));
|
||||
|
||||
regex_free(®ex);
|
||||
fsa_free(&fsa);
|
||||
}
|
||||
|
||||
static void test_qmark(void)
|
||||
{
|
||||
regex_term_t *terms = malloc(1 * sizeof(regex_term_t));
|
||||
terms[0].quantifier = REGEX_QUANTIFIER_QMARK;
|
||||
terms[0].type = REGEX_TERM_LITERAL;
|
||||
terms[0].literal = 'a';
|
||||
regex_sequence_t *alternatives = malloc(1 * sizeof(regex_sequence_t));
|
||||
alternatives[0].count = alternatives[0].capacity = 1;
|
||||
alternatives[0].contents = terms;
|
||||
regex_t regex = { .count = 1, .capacity = 1, .contents = alternatives };
|
||||
|
||||
fsa_t fsa;
|
||||
construct_nfa(®ex, &fsa);
|
||||
|
||||
ASSERT_TRUE(accepts(&fsa, ""));
|
||||
ASSERT_TRUE(accepts(&fsa, "a"));
|
||||
ASSERT_FALSE(accepts(&fsa, "aa"));
|
||||
ASSERT_FALSE(accepts(&fsa, "b"));
|
||||
|
||||
regex_free(®ex);
|
||||
fsa_free(&fsa);
|
||||
}
|
||||
|
||||
static void test_subexpression(void)
|
||||
{
|
||||
regex_term_t *inner_terms = malloc(1 * sizeof(regex_term_t));
|
||||
@@ -415,6 +461,8 @@ int main(void)
|
||||
test_sequence();
|
||||
test_union();
|
||||
test_star();
|
||||
test_plus();
|
||||
test_qmark();
|
||||
test_subexpression();
|
||||
test_class();
|
||||
test_negated_class();
|
||||
|
||||
Reference in New Issue
Block a user