pcre_ut_base.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #define CHECK_MATCHES(EXPECTED, PATTERN, STR) \
  2. UNIT_ASSERT(EXPECTED == NPcre::TPcre<CHAR_TYPE>(STRING(PATTERN), OPTIMIZE).Matches(STRING(STR))); \
  3. UNIT_ASSERT(EXPECTED == NPcre::TPcre<CHAR_TYPE>(STRING(PATTERN), OPTIMIZE).Matches(STRING(STR), 0, 10));
  4. #define CHECK(A, B) UNIT_ASSERT_STRINGS_EQUAL(ToString(STRING(A)), ToString(B))
  5. #define CHECK_GROUPS(EXPECTED, PATTERN, STR) \
  6. CHECK(EXPECTED, NPcre::TPcre<CHAR_TYPE>(STRING(PATTERN), OPTIMIZE).Find(STRING(STR))); \
  7. CHECK(EXPECTED, NPcre::TPcre<CHAR_TYPE>(STRING(PATTERN), OPTIMIZE).Find(STRING(STR), 0, 10));
  8. Y_UNIT_TEST_SUITE(TEST_NAME(TestRegExp)) {
  9. Y_UNIT_TEST(TestMatches) {
  10. CHECK_MATCHES(true, "ю", "bюd");
  11. CHECK_MATCHES(false, "c", "bюd");
  12. CHECK_MATCHES(true, "(ю)(?:(b)c|bd)", "zюbda");
  13. CHECK_MATCHES(false, "(ю)(?:(b)c|bd)", "bюd");
  14. CHECK_MATCHES(true, "(abc|def)=\\g1", "abc=abc");
  15. CHECK_MATCHES(true, "(abc|def)=\\g1", "def=def");
  16. CHECK_MATCHES(false, "(abc|def)=\\g1", "abc=def");
  17. }
  18. Y_UNIT_TEST(TestGroups) {
  19. CHECK_GROUPS("{1,2}", "a", "bad");
  20. CHECK_GROUPS("(empty maybe)", "c", "bad");
  21. CHECK_GROUPS("{1,4}", "(a)(?:(b)c|bd)", "zabda");
  22. CHECK_GROUPS("(empty maybe)", "(a)(?:(b)c|bd)", "bad");
  23. CHECK_GROUPS("{1,8}", "(abc|def)=\\g1", "aabc=abca");
  24. CHECK_GROUPS("(empty maybe)", "(abc|def)=\\g1", "abc=def");
  25. }
  26. Y_UNIT_TEST(TestCapture) {
  27. CHECK("[{1,2}]",NPcre::TPcre<CHAR_TYPE>(STRING("a"), OPTIMIZE).Capture(STRING("bad"), 0, 1));
  28. CHECK("[]",NPcre::TPcre<CHAR_TYPE>(STRING("c"), OPTIMIZE).Capture(STRING("bad"), 0, 1));
  29. CHECK("[{1,4},{1,2},{-1,-1},{3,4}]",NPcre::TPcre<CHAR_TYPE>(STRING("(a)(?:(b)c|b(d))"), OPTIMIZE).Capture(STRING("zabda"), 0, 1));
  30. CHECK("[]",NPcre::TPcre<CHAR_TYPE>(STRING("(a)(?:(b)c|bd)"), OPTIMIZE).Capture(STRING("bad"), 0, 1));
  31. }
  32. }