Implement union construction
This commit is contained in:
@@ -102,11 +102,42 @@ static void test_sequence(void)
|
||||
fsa_free(&fsa);
|
||||
}
|
||||
|
||||
static void test_union(void)
|
||||
{
|
||||
const char *literals = "abc";
|
||||
regex_sequence_t *alternatives = malloc(3 * sizeof(regex_sequence_t));
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
regex_term_t *terms = malloc(1 * sizeof(regex_term_t));
|
||||
terms[0].quantifier = REGEX_QUANTIFIER_NONE;
|
||||
terms[0].type = REGEX_TERM_LITERAL;
|
||||
terms[0].literal = literals[i];
|
||||
|
||||
alternatives[i].count = alternatives[i].capacity = 1;
|
||||
alternatives[i].contents = terms;
|
||||
}
|
||||
regex_t regex = { .count = 3, .capacity = 3, .contents = alternatives };
|
||||
|
||||
fsa_t fsa;
|
||||
construct(®ex, &fsa);
|
||||
|
||||
const fsa_state_t *initial = &fsa.states[fsa.initial];
|
||||
ASSERT_EQ(3, initial->count);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
ASSERT_EQ(literals[i], initial->rules[i].input);
|
||||
const int next = initial->rules[i].next;
|
||||
ASSERT_TRUE(fsa.states[next].final);
|
||||
}
|
||||
|
||||
regex_free(®ex);
|
||||
fsa_free(&fsa);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TESTING_BEGIN();
|
||||
test_empty_expression();
|
||||
test_literal_expression();
|
||||
test_sequence();
|
||||
test_union();
|
||||
return TESTING_END();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user