| 1 | /* |
|---|
| 2 | * |
|---|
| 3 | * Copyright (c) 2004 |
|---|
| 4 | * John Maddock |
|---|
| 5 | * |
|---|
| 6 | * Use, modification and distribution are subject to the |
|---|
| 7 | * Boost Software License, Version 1.0. (See accompanying file |
|---|
| 8 | * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 9 | * |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | #include "test.hpp" |
|---|
| 13 | |
|---|
| 14 | #ifdef BOOST_MSVC |
|---|
| 15 | #pragma warning(disable:4127) |
|---|
| 16 | #endif |
|---|
| 17 | |
|---|
| 18 | void test_character_escapes() |
|---|
| 19 | { |
|---|
| 20 | using namespace boost::regex_constants; |
|---|
| 21 | // characters by code |
|---|
| 22 | TEST_REGEX_SEARCH("\\0101", perl, "A", match_default, make_array(0, 1, -2, -2)); |
|---|
| 23 | TEST_REGEX_SEARCH("\\00", perl, "\0", match_default, make_array(0, 1, -2, -2)); |
|---|
| 24 | TEST_REGEX_SEARCH("\\0", perl, "\0", match_default, make_array(0, 1, -2, -2)); |
|---|
| 25 | TEST_REGEX_SEARCH("\\0172", perl, "z", match_default, make_array(0, 1, -2, -2)); |
|---|
| 26 | // extra escape sequences: |
|---|
| 27 | TEST_REGEX_SEARCH("\\a", perl, "\a", match_default, make_array(0, 1, -2, -2)); |
|---|
| 28 | TEST_REGEX_SEARCH("\\f", perl, "\f", match_default, make_array(0, 1, -2, -2)); |
|---|
| 29 | TEST_REGEX_SEARCH("\\n", perl, "\n", match_default, make_array(0, 1, -2, -2)); |
|---|
| 30 | TEST_REGEX_SEARCH("\\r", perl, "\r", match_default, make_array(0, 1, -2, -2)); |
|---|
| 31 | TEST_REGEX_SEARCH("\\v", perl, "\v", match_default, make_array(0, 1, -2, -2)); |
|---|
| 32 | TEST_REGEX_SEARCH("\\t", perl, "\t", match_default, make_array(0, 1, -2, -2)); |
|---|
| 33 | |
|---|
| 34 | // updated tests for version 2: |
|---|
| 35 | TEST_REGEX_SEARCH("\\x41", perl, "A", match_default, make_array(0, 1, -2, -2)); |
|---|
| 36 | TEST_REGEX_SEARCH("\\xff", perl, "\xff", match_default, make_array(0, 1, -2, -2)); |
|---|
| 37 | TEST_REGEX_SEARCH("\\xFF", perl, "\xff", match_default, make_array(0, 1, -2, -2)); |
|---|
| 38 | TEST_REGEX_SEARCH("\\c@", perl, "\0", match_default, make_array(0, 1, -2, -2)); |
|---|
| 39 | TEST_REGEX_SEARCH("\\cA", perl, "\x1", match_default, make_array(0, 1, -2, -2)); |
|---|
| 40 | //TEST_REGEX_SEARCH("\\cz", perl, "\x3A", match_default, make_array(0, 1, -2, -2)); |
|---|
| 41 | //TEST_INVALID_REGEX("\\c=", extended); |
|---|
| 42 | //TEST_INVALID_REGEX("\\c?", extended); |
|---|
| 43 | TEST_REGEX_SEARCH("=:", perl, "=:", match_default, make_array(0, 2, -2, -2)); |
|---|
| 44 | |
|---|
| 45 | TEST_REGEX_SEARCH("\\e", perl, "\x1B", match_default, make_array(0, 1, -2, -2)); |
|---|
| 46 | TEST_REGEX_SEARCH("\\x1b", perl, "\x1B", match_default, make_array(0, 1, -2, -2)); |
|---|
| 47 | TEST_REGEX_SEARCH("\\x{1b}", perl, "\x1B", match_default, make_array(0, 1, -2, -2)); |
|---|
| 48 | TEST_INVALID_REGEX("\\x{}", perl); |
|---|
| 49 | TEST_INVALID_REGEX("\\x{", perl); |
|---|
| 50 | TEST_INVALID_REGEX("\\", perl); |
|---|
| 51 | TEST_INVALID_REGEX("\\c", perl); |
|---|
| 52 | TEST_INVALID_REGEX("\\x}", perl); |
|---|
| 53 | TEST_INVALID_REGEX("\\x", perl); |
|---|
| 54 | TEST_INVALID_REGEX("\\x{yy", perl); |
|---|
| 55 | TEST_INVALID_REGEX("\\x{1b", perl); |
|---|
| 56 | // \Q...\E sequences: |
|---|
| 57 | TEST_INVALID_REGEX("\\Qabc\\", perl); |
|---|
| 58 | TEST_REGEX_SEARCH("\\Qabc\\E", perl, "abcd", match_default, make_array(0, 3, -2, -2)); |
|---|
| 59 | TEST_REGEX_SEARCH("\\Qabc\\Ed", perl, "abcde", match_default, make_array(0, 4, -2, -2)); |
|---|
| 60 | TEST_REGEX_SEARCH("\\Q+*?\\\\E", perl, "+*?\\", match_default, make_array(0, 4, -2, -2)); |
|---|
| 61 | TEST_REGEX_SEARCH("a\\Q+*?\\\\Eb", perl, "a+*?\\b", match_default, make_array(0, 6, -2, -2)); |
|---|
| 62 | TEST_REGEX_SEARCH("\\C+", perl, "abcde", match_default, make_array(0, 5, -2, -2)); |
|---|
| 63 | TEST_REGEX_SEARCH("\\X+", perl, "abcde", match_default, make_array(0, 5, -2, -2)); |
|---|
| 64 | #if !BOOST_WORKAROUND(__BORLANDC__, < 0x560) |
|---|
| 65 | TEST_REGEX_SEARCH_W(L"\\X", perl, L"a\x0300\x0301", match_default, make_array(0, 3, -2, -2)); |
|---|
| 66 | #endif |
|---|
| 67 | // unknown escape sequences match themselves: |
|---|
| 68 | TEST_REGEX_SEARCH("\\~", perl, "~", match_default, make_array(0, 1, -2, -2)); |
|---|
| 69 | TEST_REGEX_SEARCH("\\~", basic, "~", match_default, make_array(0, 1, -2, -2)); |
|---|
| 70 | TEST_REGEX_SEARCH("\\~", extended, "~", match_default, make_array(0, 1, -2, -2)); |
|---|
| 71 | TEST_REGEX_SEARCH("\\j", extended, "j", match_default, make_array(0, 1, -2, -2)); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | void test_assertion_escapes() |
|---|
| 75 | { |
|---|
| 76 | using namespace boost::regex_constants; |
|---|
| 77 | // word start: |
|---|
| 78 | TEST_REGEX_SEARCH("\\<abcd", perl, " abcd", match_default, make_array(2, 6, -2, -2)); |
|---|
| 79 | TEST_REGEX_SEARCH("\\<ab", perl, "cab", match_default, make_array(-2, -2)); |
|---|
| 80 | TEST_REGEX_SEARCH("\\<ab", perl, "\nab", match_default, make_array(1, 3, -2, -2)); |
|---|
| 81 | TEST_REGEX_SEARCH("\\<tag", perl, "::tag", match_default, make_array(2, 5, -2, -2)); |
|---|
| 82 | TEST_REGEX_SEARCH("\\<abcd", perl, "abcd", match_default|match_not_bow, make_array(-2, -2)); |
|---|
| 83 | TEST_REGEX_SEARCH("\\<abcd", perl, " abcd", match_default|match_not_bow, make_array(2, 6, -2, -2)); |
|---|
| 84 | TEST_REGEX_SEARCH("\\<", perl, "ab ", match_default|match_not_bow, make_array(-2, -2)); |
|---|
| 85 | TEST_REGEX_SEARCH(".\\<.", perl, "ab", match_default|match_not_bow, make_array(-2, -2)); |
|---|
| 86 | TEST_REGEX_SEARCH(".\\<.", perl, " b", match_default|match_not_bow, make_array(0, 2, -2, -2)); |
|---|
| 87 | // word end: |
|---|
| 88 | TEST_REGEX_SEARCH("abc\\>", perl, "abc", match_default, make_array(0, 3, -2, -2)); |
|---|
| 89 | TEST_REGEX_SEARCH("abc\\>", perl, "abcd", match_default, make_array(-2, -2)); |
|---|
| 90 | TEST_REGEX_SEARCH("abc\\>", perl, "abc\n", match_default, make_array(0, 3, -2, -2)); |
|---|
| 91 | TEST_REGEX_SEARCH("abc\\>", perl, "abc::", match_default, make_array(0,3, -2, -2)); |
|---|
| 92 | TEST_REGEX_SEARCH("abc(?:\\>..|$)", perl, "abc::", match_default, make_array(0, 5, -2, -2)); |
|---|
| 93 | TEST_REGEX_SEARCH("\\>", perl, " ", match_default, make_array(-2, -2)); |
|---|
| 94 | TEST_REGEX_SEARCH(".\\>.", perl, " ", match_default, make_array(-2, -2)); |
|---|
| 95 | TEST_REGEX_SEARCH("abc\\>", perl, "abc", match_default|match_not_eow, make_array(-2, -2)); |
|---|
| 96 | // word boundary: |
|---|
| 97 | TEST_REGEX_SEARCH("\\babcd", perl, " abcd", match_default, make_array(2, 6, -2, -2)); |
|---|
| 98 | TEST_REGEX_SEARCH("\\bab", perl, "cab", match_default, make_array(-2, -2)); |
|---|
| 99 | TEST_REGEX_SEARCH("\\bab", perl, "\nab", match_default, make_array(1, 3, -2, -2)); |
|---|
| 100 | TEST_REGEX_SEARCH("\\btag", perl, "::tag", match_default, make_array(2, 5, -2, -2)); |
|---|
| 101 | TEST_REGEX_SEARCH("abc\\b", perl, "abc", match_default, make_array(0, 3, -2, -2)); |
|---|
| 102 | TEST_REGEX_SEARCH("abc\\b", perl, "abcd", match_default, make_array(-2, -2)); |
|---|
| 103 | TEST_REGEX_SEARCH("abc\\b", perl, "abc\n", match_default, make_array(0, 3, -2, -2)); |
|---|
| 104 | TEST_REGEX_SEARCH("abc\\b", perl, "abc::", match_default, make_array(0, 3, -2, -2)); |
|---|
| 105 | TEST_REGEX_SEARCH("\\babcd", perl, "abcd", match_default|match_not_bow, make_array(-2, -2)); |
|---|
| 106 | // within word: |
|---|
| 107 | TEST_REGEX_SEARCH("\\B", perl, "ab", match_default, make_array(1, 1, -2, -2)); |
|---|
| 108 | TEST_REGEX_SEARCH("a\\Bb", perl, "ab", match_default, make_array(0, 2, -2, -2)); |
|---|
| 109 | TEST_REGEX_SEARCH("a\\B", perl, "ab", match_default, make_array(0, 1, -2, -2)); |
|---|
| 110 | TEST_REGEX_SEARCH("a\\B", perl, "a", match_default, make_array(-2, -2)); |
|---|
| 111 | TEST_REGEX_SEARCH("a\\B", perl, "a ", match_default, make_array(-2, -2)); |
|---|
| 112 | // buffer operators: |
|---|
| 113 | TEST_REGEX_SEARCH("\\`abc", perl, "abc", match_default, make_array(0, 3, -2, -2)); |
|---|
| 114 | TEST_REGEX_SEARCH("\\`abc", perl, "\nabc", match_default, make_array(-2, -2)); |
|---|
| 115 | TEST_REGEX_SEARCH("\\`abc", perl, " abc", match_default, make_array(-2, -2)); |
|---|
| 116 | TEST_REGEX_SEARCH("abc\\'", perl, "abc", match_default, make_array(0, 3, -2, -2)); |
|---|
| 117 | TEST_REGEX_SEARCH("abc\\'", perl, "abc\n", match_default, make_array(-2, -2)); |
|---|
| 118 | TEST_REGEX_SEARCH("abc\\'", perl, "abc ", match_default, make_array(-2, -2)); |
|---|
| 119 | TEST_REGEX_SEARCH("abc(?:\\'|$)", perl, "abc", match_default, make_array(0, 3, -2, -2)); |
|---|
| 120 | |
|---|
| 121 | // word start: |
|---|
| 122 | TEST_REGEX_SEARCH("[[:<:]]abcd", perl, " abcd", match_default, make_array(2, 6, -2, -2)); |
|---|
| 123 | TEST_REGEX_SEARCH("[[:<:]]ab", perl, "cab", match_default, make_array(-2, -2)); |
|---|
| 124 | TEST_REGEX_SEARCH("[[:<:]]ab", perl, "\nab", match_default, make_array(1, 3, -2, -2)); |
|---|
| 125 | TEST_REGEX_SEARCH("[[:<:]]tag", perl, "::tag", match_default, make_array(2, 5, -2, -2)); |
|---|
| 126 | // word end |
|---|
| 127 | TEST_REGEX_SEARCH("abc[[:>:]]", perl, "abc", match_default, make_array(0, 3, -2, -2)); |
|---|
| 128 | TEST_REGEX_SEARCH("abc[[:>:]]", perl, "abcd", match_default, make_array(-2, -2)); |
|---|
| 129 | TEST_REGEX_SEARCH("abc[[:>:]]", perl, "abc\n", match_default, make_array(0, 3, -2, -2)); |
|---|
| 130 | TEST_REGEX_SEARCH("abc[[:>:]]", perl, "abc::", match_default, make_array(0, 3, -2, -2)); |
|---|
| 131 | |
|---|
| 132 | TEST_REGEX_SEARCH("\\Aabc", perl, "abc", match_default, make_array(0, 3, -2, -2)); |
|---|
| 133 | TEST_REGEX_SEARCH("\\Aabc", perl, "aabc", match_default, make_array(-2, -2)); |
|---|
| 134 | TEST_REGEX_SEARCH("abc\\z", perl, "abc", match_default, make_array(0, 3, -2, -2)); |
|---|
| 135 | TEST_REGEX_SEARCH("abc\\z", perl, "abcd", match_default, make_array(-2, -2)); |
|---|
| 136 | TEST_REGEX_SEARCH("abc\\Z", perl, "abc\n\n", match_default, make_array(0, 3, -2, -2)); |
|---|
| 137 | TEST_REGEX_SEARCH("abc\\Z", perl, "abc\n\n", match_default|match_not_eob, make_array(-2, -2)); |
|---|
| 138 | TEST_REGEX_SEARCH("abc\\Z", perl, "abc", match_default, make_array(0, 3, -2, -2)); |
|---|
| 139 | TEST_REGEX_SEARCH("\\Gabc", perl, "abc", match_default, make_array(0, 3, -2, -2)); |
|---|
| 140 | TEST_REGEX_SEARCH("\\Gabc", perl, "dabcd", match_default, make_array(-2, -2)); |
|---|
| 141 | TEST_REGEX_SEARCH("a\\Gbc", perl, "abc", match_default, make_array(-2, -2)); |
|---|
| 142 | TEST_REGEX_SEARCH("a\\Aab", perl, "abc", match_default, make_array(-2, -2)); |
|---|
| 143 | TEST_REGEX_SEARCH("abc(?:\\Z|$)", perl, "abc\n\n", match_default, make_array(0, 3, -2, -2)); |
|---|
| 144 | } |
|---|
| 145 | |
|---|