/* * Copyright (c) Camden Dixie O'Brien * SPDX-License-Identifier: AGPL-3.0-only */ #include "construct.h" #include "testing.h" static void test_empty_expression(void) { regex_term_t *terms = malloc(1 * sizeof(regex_term_t)); terms[0].quantifier = REGEX_QUANTIFIER_NONE; terms[0].type = REGEX_TERM_EMPTY; regex_sequence_t *alternatives = malloc(1 * sizeof(regex_sequence_t)); alternatives[0].count = alternatives[0].capacity = 1; alternatives[0].contents = terms; const regex_t regex = { .count = 1, .capacity = 1, .contents = alternatives }; fsa_t fsa; construct(®ex, &fsa); ASSERT_EQ(1, fsa.count); ASSERT_TRUE(fsa.states[fsa.initial].final); ASSERT_EQ(0, fsa.states[fsa.initial].count); regex_free(®ex); fsa_free(&fsa); } static void test_literal_expression(void) { 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 = 'a'; regex_sequence_t *alternatives = malloc(1 * sizeof(regex_sequence_t)); alternatives[0].count = alternatives[0].capacity = 1; alternatives[0].contents = terms; const regex_t regex = { .count = 1, .capacity = 1, .contents = alternatives }; fsa_t fsa; construct(®ex, &fsa); const fsa_state_t *initial = &fsa.states[fsa.initial]; ASSERT_EQ(2, fsa.count); ASSERT_EQ(1, initial->count); ASSERT_EQ('a', initial->rules[0].input); ASSERT_TRUE(fsa.states[initial->rules[0].next].final); ASSERT_EQ(0, fsa.states[initial->rules[0].next].count); regex_free(®ex); fsa_free(&fsa); } int main(void) { TESTING_BEGIN(); test_empty_expression(); test_literal_expression(); return TESTING_END(); }