|
|
#include "unity/unity.h" |
|
|
#define PCRE2_CODE_UNIT_WIDTH 8 |
|
|
#include "pcre2.h" |
|
|
|
|
|
|
|
|
#include "pcre2_compile.h" |
|
|
|
|
|
#include <string.h> |
|
|
#include <stdint.h> |
|
|
|
|
|
|
|
|
extern BOOL test_compile_class_binary_tight(); |
|
|
|
|
|
void setUp(void) { |
|
|
|
|
|
} |
|
|
|
|
|
void tearDown(void) { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static void assert_bits_all_ones(const eclass_op_info *op) |
|
|
{ |
|
|
for (int i = 0; i < 8; i++) { |
|
|
TEST_ASSERT_EQUAL_HEX32(0xFFFFFFFFu, op->bits.classwords[i]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static void assert_bits_all_zeros(const eclass_op_info *op) |
|
|
{ |
|
|
for (int i = 0; i < 8; i++) { |
|
|
TEST_ASSERT_EQUAL_HEX32(0u, op->bits.classwords[i]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void test_compile_class_binary_tight_single_any(void) |
|
|
{ |
|
|
|
|
|
uint32_t tokens[] = { META_CLASS_EMPTY_NOT, META_CLASS_END }; |
|
|
uint32_t *ptr = tokens; |
|
|
uint32_t *pptr = ptr; |
|
|
PCRE2_UCHAR codebuf[16]; |
|
|
PCRE2_UCHAR *code = codebuf; |
|
|
eclass_op_info op_info; |
|
|
memset(&op_info, 0, sizeof(op_info)); |
|
|
|
|
|
BOOL ok = test_compile_class_binary_tight(NULL, FALSE, |
|
|
&pptr, &code, &op_info, |
|
|
NULL); |
|
|
TEST_ASSERT_TRUE(ok); |
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL_PTR(codebuf + 1, code); |
|
|
TEST_ASSERT_EQUAL_UINT8(ECL_ANY, codebuf[0]); |
|
|
TEST_ASSERT_EQUAL_UINT8(ECL_ANY, op_info.op_single_type); |
|
|
TEST_ASSERT_EQUAL_UINT(1, op_info.length); |
|
|
assert_bits_all_ones(&op_info); |
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL_PTR(&tokens[1], pptr); |
|
|
TEST_ASSERT_EQUAL_UINT(META_CLASS_END, *pptr); |
|
|
} |
|
|
|
|
|
|
|
|
void test_compile_class_binary_tight_and_any_any(void) |
|
|
{ |
|
|
uint32_t tokens[] = { META_CLASS_EMPTY_NOT, META_ECLASS_AND, META_CLASS_EMPTY_NOT, META_CLASS_END }; |
|
|
uint32_t *pptr = tokens; |
|
|
PCRE2_UCHAR codebuf[16]; |
|
|
PCRE2_UCHAR *code = codebuf; |
|
|
eclass_op_info op_info; |
|
|
memset(&op_info, 0, sizeof(op_info)); |
|
|
|
|
|
BOOL ok = test_compile_class_binary_tight(NULL, FALSE, &pptr, &code, &op_info, NULL); |
|
|
TEST_ASSERT_TRUE(ok); |
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL_PTR(codebuf + 1, code); |
|
|
TEST_ASSERT_EQUAL_UINT8(ECL_ANY, codebuf[0]); |
|
|
TEST_ASSERT_EQUAL_UINT8(ECL_ANY, op_info.op_single_type); |
|
|
TEST_ASSERT_EQUAL_UINT(1, op_info.length); |
|
|
assert_bits_all_ones(&op_info); |
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL_PTR(&tokens[3], pptr); |
|
|
TEST_ASSERT_EQUAL_UINT(META_CLASS_END, *pptr); |
|
|
} |
|
|
|
|
|
|
|
|
void test_compile_class_binary_tight_and_none_any(void) |
|
|
{ |
|
|
uint32_t tokens[] = { META_CLASS_EMPTY, META_ECLASS_AND, META_CLASS_EMPTY_NOT, META_CLASS_END }; |
|
|
uint32_t *pptr = tokens; |
|
|
PCRE2_UCHAR codebuf[16]; |
|
|
PCRE2_UCHAR *code = codebuf; |
|
|
eclass_op_info op_info; |
|
|
memset(&op_info, 0, sizeof(op_info)); |
|
|
|
|
|
BOOL ok = test_compile_class_binary_tight(NULL, FALSE, &pptr, &code, &op_info, NULL); |
|
|
TEST_ASSERT_TRUE(ok); |
|
|
|
|
|
TEST_ASSERT_EQUAL_PTR(codebuf + 1, code); |
|
|
TEST_ASSERT_EQUAL_UINT8(ECL_NONE, codebuf[0]); |
|
|
TEST_ASSERT_EQUAL_UINT8(ECL_NONE, op_info.op_single_type); |
|
|
TEST_ASSERT_EQUAL_UINT(1, op_info.length); |
|
|
assert_bits_all_zeros(&op_info); |
|
|
|
|
|
TEST_ASSERT_EQUAL_PTR(&tokens[3], pptr); |
|
|
TEST_ASSERT_EQUAL_UINT(META_CLASS_END, *pptr); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void test_compile_class_binary_tight_negated_transforms_and_to_or(void) |
|
|
{ |
|
|
uint32_t tokens[] = { META_CLASS_EMPTY, META_ECLASS_AND, META_CLASS_EMPTY, META_CLASS_END }; |
|
|
uint32_t *pptr = tokens; |
|
|
PCRE2_UCHAR codebuf[16]; |
|
|
PCRE2_UCHAR *code = codebuf; |
|
|
eclass_op_info op_info; |
|
|
memset(&op_info, 0, sizeof(op_info)); |
|
|
|
|
|
BOOL ok = test_compile_class_binary_tight(NULL, TRUE, &pptr, &code, &op_info, NULL); |
|
|
TEST_ASSERT_TRUE(ok); |
|
|
|
|
|
TEST_ASSERT_EQUAL_PTR(codebuf + 1, code); |
|
|
TEST_ASSERT_EQUAL_UINT8(ECL_ANY, codebuf[0]); |
|
|
TEST_ASSERT_EQUAL_UINT8(ECL_ANY, op_info.op_single_type); |
|
|
TEST_ASSERT_EQUAL_UINT(1, op_info.length); |
|
|
assert_bits_all_ones(&op_info); |
|
|
|
|
|
TEST_ASSERT_EQUAL_PTR(&tokens[3], pptr); |
|
|
TEST_ASSERT_EQUAL_UINT(META_CLASS_END, *pptr); |
|
|
} |
|
|
|
|
|
|
|
|
void test_compile_class_binary_tight_length_only_mode(void) |
|
|
{ |
|
|
uint32_t tokens[] = { META_CLASS_EMPTY_NOT, META_ECLASS_AND, META_CLASS_EMPTY_NOT, META_CLASS_END }; |
|
|
uint32_t *pptr = tokens; |
|
|
PCRE2_UCHAR codebuf[16]; |
|
|
memset(codebuf, 0xA5, sizeof(codebuf)); |
|
|
PCRE2_UCHAR *code = codebuf; |
|
|
eclass_op_info op_info; |
|
|
memset(&op_info, 0, sizeof(op_info)); |
|
|
PCRE2_SIZE length = 0; |
|
|
|
|
|
BOOL ok = test_compile_class_binary_tight(NULL, FALSE, &pptr, &code, &op_info, &length); |
|
|
TEST_ASSERT_TRUE(ok); |
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL_UINT(2, length); |
|
|
|
|
|
TEST_ASSERT_EQUAL_PTR(codebuf, code); |
|
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(ECL_ANY, op_info.op_single_type); |
|
|
assert_bits_all_ones(&op_info); |
|
|
|
|
|
TEST_ASSERT_EQUAL_PTR(&tokens[3], pptr); |
|
|
TEST_ASSERT_EQUAL_UINT(META_CLASS_END, *pptr); |
|
|
} |
|
|
|
|
|
int main(void) |
|
|
{ |
|
|
UNITY_BEGIN(); |
|
|
RUN_TEST(test_compile_class_binary_tight_single_any); |
|
|
RUN_TEST(test_compile_class_binary_tight_and_any_any); |
|
|
RUN_TEST(test_compile_class_binary_tight_and_none_any); |
|
|
RUN_TEST(test_compile_class_binary_tight_negated_transforms_and_to_or); |
|
|
RUN_TEST(test_compile_class_binary_tight_length_only_mode); |
|
|
return UNITY_END(); |
|
|
} |