| | #include "unity/unity.h" |
| | #define PCRE2_CODE_UNIT_WIDTH 8 |
| | #include "pcre2.h" |
| |
|
| | void setUp(void) {} |
| | void tearDown(void) {} |
| |
|
| | void test_simple_match(void) { |
| | pcre2_code *re; |
| | pcre2_match_data *match_data; |
| | int errornumber; |
| | PCRE2_SIZE erroroffset; |
| | PCRE2_SPTR pattern = (PCRE2_SPTR)"\\d+"; |
| | PCRE2_SPTR subject = (PCRE2_SPTR)"abc123def"; |
| | int rc; |
| | |
| | re = pcre2_compile(pattern, PCRE2_ZERO_TERMINATED, 0, |
| | &errornumber, &erroroffset, NULL); |
| | TEST_ASSERT_NOT_NULL(re); |
| | |
| | match_data = pcre2_match_data_create_from_pattern(re, NULL); |
| | rc = pcre2_match(re, subject, PCRE2_ZERO_TERMINATED, 0, 0, match_data, NULL); |
| | |
| | TEST_ASSERT_GREATER_THAN(0, rc); |
| | |
| | pcre2_match_data_free(match_data); |
| | pcre2_code_free(re); |
| | } |
| |
|
| | void test_no_match(void) { |
| | pcre2_code *re; |
| | pcre2_match_data *match_data; |
| | int errornumber; |
| | PCRE2_SIZE erroroffset; |
| | PCRE2_SPTR pattern = (PCRE2_SPTR)"\\d+"; |
| | PCRE2_SPTR subject = (PCRE2_SPTR)"abcdef"; |
| | int rc; |
| | |
| | re = pcre2_compile(pattern, PCRE2_ZERO_TERMINATED, 0, |
| | &errornumber, &erroroffset, NULL); |
| | match_data = pcre2_match_data_create_from_pattern(re, NULL); |
| | rc = pcre2_match(re, subject, PCRE2_ZERO_TERMINATED, 0, 0, match_data, NULL); |
| | |
| | TEST_ASSERT_EQUAL(PCRE2_ERROR_NOMATCH, rc); |
| | |
| | pcre2_match_data_free(match_data); |
| | pcre2_code_free(re); |
| | } |
| |
|
| | int main(void) { |
| | UNITY_BEGIN(); |
| | RUN_TEST(test_simple_match); |
| | RUN_TEST(test_no_match); |
| | return UNITY_END(); |
| | } |