|
|
#include "unity/unity.h" |
|
|
#define PCRE2_CODE_UNIT_WIDTH 8 |
|
|
#include "pcre2.h" |
|
|
|
|
|
void setUp(void) { |
|
|
|
|
|
} |
|
|
|
|
|
void tearDown(void) { |
|
|
|
|
|
} |
|
|
|
|
|
void test_simple_pattern_compiles(void) { |
|
|
pcre2_code *re; |
|
|
int errornumber; |
|
|
PCRE2_SIZE erroroffset; |
|
|
PCRE2_SPTR pattern = (PCRE2_SPTR)"\\d+"; |
|
|
|
|
|
re = pcre2_compile(pattern, PCRE2_ZERO_TERMINATED, 0, |
|
|
&errornumber, &erroroffset, NULL); |
|
|
|
|
|
TEST_ASSERT_NOT_NULL_MESSAGE(re, "Pattern should compile"); |
|
|
pcre2_code_free(re); |
|
|
} |
|
|
|
|
|
void test_invalid_pattern_fails(void) { |
|
|
pcre2_code *re; |
|
|
int errornumber; |
|
|
PCRE2_SIZE erroroffset; |
|
|
PCRE2_SPTR pattern = (PCRE2_SPTR)"[invalid"; |
|
|
|
|
|
re = pcre2_compile(pattern, PCRE2_ZERO_TERMINATED, 0, |
|
|
&errornumber, &erroroffset, NULL); |
|
|
|
|
|
TEST_ASSERT_NULL_MESSAGE(re, "Invalid pattern should fail"); |
|
|
} |
|
|
|
|
|
void test_utf8_pattern(void) { |
|
|
pcre2_code *re; |
|
|
int errornumber; |
|
|
PCRE2_SIZE erroroffset; |
|
|
PCRE2_SPTR pattern = (PCRE2_SPTR)"café"; |
|
|
|
|
|
re = pcre2_compile(pattern, PCRE2_ZERO_TERMINATED, PCRE2_UTF, |
|
|
&errornumber, &erroroffset, NULL); |
|
|
|
|
|
TEST_ASSERT_NOT_NULL_MESSAGE(re, "UTF-8 pattern should compile"); |
|
|
pcre2_code_free(re); |
|
|
} |
|
|
|
|
|
int main(void) { |
|
|
UNITY_BEGIN(); |
|
|
RUN_TEST(test_simple_pattern_compiles); |
|
|
RUN_TEST(test_invalid_pattern_fails); |
|
|
RUN_TEST(test_utf8_pattern); |
|
|
return UNITY_END(); |
|
|
} |