Implement star construction

This commit is contained in:
2024-10-27 13:24:29 +00:00
parent d54080032c
commit bbecd12c91
2 changed files with 85 additions and 1 deletions

View File

@@ -132,6 +132,30 @@ static void test_union(void)
fsa_free(&fsa);
}
static void test_star(void)
{
regex_term_t *terms = malloc(1 * sizeof(regex_term_t));
terms[0].quantifier = REGEX_QUANTIFIER_STAR;
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(&regex, &fsa);
const fsa_state_t *initial = &fsa.states[fsa.initial];
ASSERT_TRUE(initial->final);
ASSERT_EQ(1, initial->count);
ASSERT_EQ('a', initial->rules[0].input);
ASSERT_EQ(fsa.initial, initial->rules[0].next);
regex_free(&regex);
fsa_free(&fsa);
}
int main(void)
{
TESTING_BEGIN();
@@ -139,5 +163,6 @@ int main(void)
test_literal_expression();
test_sequence();
test_union();
test_star();
return TESTING_END();
}