From 7f5aa1766cb56e146935421ec29547a2762a093b Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sat, 2 Nov 2024 16:41:50 +0000 Subject: [PATCH] Create some integration tests --- tests/CMakeLists.txt | 1 + tests/integration_tests.c | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/integration_tests.c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 46e4274..bdaa7c3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,6 +21,7 @@ add_test_suites( convert_tests.c desugar_tests.c fsa_tests.c + integration_tests.c min_heap_tests.c parse_tests.c ) diff --git a/tests/integration_tests.c b/tests/integration_tests.c new file mode 100644 index 0000000..1798ab9 --- /dev/null +++ b/tests/integration_tests.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) Camden Dixie O'Brien + * SPDX-License-Identifier: AGPL-3.0-only + */ + +#include "compile.h" +#include "testing.h" + +static void test_foo_or_bar_regex(void) +{ + fsa_t dfa; + const char *regex = "foo|bar"; + const bool success = compile(regex, strlen(regex), &dfa); + ASSERT_TRUE(success); + ASSERT_ACCEPTS(&dfa, "foo"); + ASSERT_ACCEPTS(&dfa, "bar"); + ASSERT_REJECTS(&dfa, "baz"); +} + +static void test_even_number_of_Is_regex(void) +{ + fsa_t dfa; + const char *regex = "(II)*"; + const bool success = compile(regex, strlen(regex), &dfa); + ASSERT_TRUE(success); + ASSERT_ACCEPTS(&dfa, ""); + ASSERT_ACCEPTS(&dfa, "II"); + ASSERT_ACCEPTS(&dfa, "IIII"); + ASSERT_ACCEPTS(&dfa, "IIIIIIIIII"); + ASSERT_REJECTS(&dfa, "III"); + ASSERT_REJECTS(&dfa, "IIIII"); + ASSERT_REJECTS(&dfa, "IIIIIIIII"); +} + +static void test_arbitrary_regex_1(void) +{ + fsa_t dfa; + const char *regex = "(abc!?)*|dd+"; + const bool success = compile(regex, strlen(regex), &dfa); + ASSERT_TRUE(success); + ASSERT_ACCEPTS(&dfa, "abc!abcabc"); + ASSERT_ACCEPTS(&dfa, "dddddddd"); + ASSERT_REJECTS(&dfa, "d"); + ASSERT_REJECTS(&dfa, "abcd"); +} + +int main(void) +{ + TESTING_BEGIN(); + test_foo_or_bar_regex(); + test_even_number_of_Is_regex(); + test_arbitrary_regex_1(); + return TESTING_END(); +}