| 1 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | // test2.hpp |
|---|
| 3 | // |
|---|
| 4 | // Copyright 2004 Eric Niebler. Distributed under the Boost |
|---|
| 5 | // Software License, Version 1.0. (See accompanying file |
|---|
| 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 7 | |
|---|
| 8 | #include "./test.hpp" |
|---|
| 9 | |
|---|
| 10 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 11 | // get_test_cases |
|---|
| 12 | // |
|---|
| 13 | template<typename BidiIterT> |
|---|
| 14 | boost::iterator_range<test_case<BidiIterT> const *> get_test_cases() |
|---|
| 15 | { |
|---|
| 16 | typedef typename boost::iterator_value<BidiIterT>::type char_type; |
|---|
| 17 | typedef test_case<BidiIterT> test_case; |
|---|
| 18 | typedef basic_regex<BidiIterT> regex_type; |
|---|
| 19 | |
|---|
| 20 | // "(\\+|-)?([0-9]+\\.?[0-9]*|\\.[0-9]+)([eE](\\+|-)?[0-9]+)?" |
|---|
| 21 | static regex_type const test21 = !(s1= as_xpr(L('+'))|L('-')) >> (s2= +range(L('0'),L('9')) >> !as_xpr(L('.')) >> *range(L('0'),L('9')) | |
|---|
| 22 | L('.') >> +range(L('0'),L('9'))) >> !(s3= (set=L('e'),L('E')) >> !(s4= as_xpr(L('+'))|L('-')) >> +range(L('0'),L('9'))); |
|---|
| 23 | |
|---|
| 24 | // "^(\\+|-)?([0-9]+\\.?[0-9]*|\\.[0-9]+)([eE](\\+|-)?[0-9]+)?$" |
|---|
| 25 | static regex_type const test23 = bos >> test21 >> eos; |
|---|
| 26 | |
|---|
| 27 | static char_type const *nilbr = 0; |
|---|
| 28 | static test_case const test_cases[] = |
|---|
| 29 | { |
|---|
| 30 | test_case |
|---|
| 31 | ( |
|---|
| 32 | "test21" |
|---|
| 33 | , L("-1234.56789") |
|---|
| 34 | , test21 |
|---|
| 35 | , backrefs(L("-1234.56789"), L("-"), L("1234.56789"), L(""), L(""), nilbr) |
|---|
| 36 | ) |
|---|
| 37 | , test_case |
|---|
| 38 | ( |
|---|
| 39 | "test22" |
|---|
| 40 | , L("-1234.56789e-123123123") |
|---|
| 41 | , test21 |
|---|
| 42 | , backrefs(L("-1234.56789e-123123123"), L("-"), L("1234.56789"), L("e-123123123"), L("-"), nilbr) |
|---|
| 43 | ) |
|---|
| 44 | , test_case |
|---|
| 45 | ( |
|---|
| 46 | "test23" |
|---|
| 47 | , L("-.1234.56789") |
|---|
| 48 | , test23 |
|---|
| 49 | , no_match |
|---|
| 50 | ) |
|---|
| 51 | , test_case |
|---|
| 52 | ( |
|---|
| 53 | "test24" |
|---|
| 54 | , L("-1234.56789e-12312e123") |
|---|
| 55 | , test23 |
|---|
| 56 | , no_match |
|---|
| 57 | ) |
|---|
| 58 | , test_case |
|---|
| 59 | ( |
|---|
| 60 | "test25" |
|---|
| 61 | , L("aaaaaaaaac") |
|---|
| 62 | , regex_type(*as_xpr(L('a')) >> *as_xpr(L('a')) >> *as_xpr(L('a')) >> *as_xpr(L('a')) >> *as_xpr(L('a')) >> L('b')) |
|---|
| 63 | , no_match |
|---|
| 64 | ) |
|---|
| 65 | , test_case |
|---|
| 66 | ( |
|---|
| 67 | "test26" |
|---|
| 68 | , L("ThIs iS a TeSt") |
|---|
| 69 | , regex_type(*set[range(L('a'),L('z')) | range(L('A'),L('Z'))]) |
|---|
| 70 | , backrefs(L("ThIs"), nilbr) |
|---|
| 71 | ) |
|---|
| 72 | , test_case |
|---|
| 73 | ( |
|---|
| 74 | "test27" |
|---|
| 75 | , L("a^b") |
|---|
| 76 | , regex_type(L('a') >> bos >> L('b')) |
|---|
| 77 | , no_match |
|---|
| 78 | ) |
|---|
| 79 | , test_case |
|---|
| 80 | ( |
|---|
| 81 | "test28" |
|---|
| 82 | , L("a^b") |
|---|
| 83 | , regex_type(as_xpr(L("a^b"))) |
|---|
| 84 | , backrefs(L("a^b"), nilbr) |
|---|
| 85 | ) |
|---|
| 86 | , test_case |
|---|
| 87 | ( |
|---|
| 88 | "test29" |
|---|
| 89 | , L("a^b") |
|---|
| 90 | , regex_type(L('a') >> ~set[L(' ')] >> L('b')) |
|---|
| 91 | , backrefs(L("a^b"), nilbr) |
|---|
| 92 | ) |
|---|
| 93 | , test_case |
|---|
| 94 | ( |
|---|
| 95 | "test30" |
|---|
| 96 | , L("a^b") |
|---|
| 97 | , regex_type(L('a') >> ~set[L('^')] >> L('b')) |
|---|
| 98 | , no_match |
|---|
| 99 | ) |
|---|
| 100 | , test_case |
|---|
| 101 | ( |
|---|
| 102 | "test31" |
|---|
| 103 | , L("a^b") |
|---|
| 104 | , regex_type(L('a') >> ~set[L('^')] >> L('b')) |
|---|
| 105 | , no_match |
|---|
| 106 | ) |
|---|
| 107 | , test_case |
|---|
| 108 | ( |
|---|
| 109 | "test31.1" |
|---|
| 110 | , L("a^b") |
|---|
| 111 | , regex_type(L('a') >> set[L('^')] >> L('b')) |
|---|
| 112 | , backrefs(L("a^b"), nilbr) |
|---|
| 113 | ) |
|---|
| 114 | , test_case |
|---|
| 115 | ( |
|---|
| 116 | "test32" |
|---|
| 117 | , L("foobazFOObar") |
|---|
| 118 | , regex_type(icase(L("foo") >> before(L("bar")))) |
|---|
| 119 | , backrefs(L("FOO"), nilbr) |
|---|
| 120 | ) |
|---|
| 121 | , test_case |
|---|
| 122 | ( |
|---|
| 123 | "test33" |
|---|
| 124 | , L("foobarFOObaz") |
|---|
| 125 | , regex_type(icase(L("foo") >> ~before(L("bar")))) |
|---|
| 126 | , backrefs(L("FOO"), nilbr) |
|---|
| 127 | ) |
|---|
| 128 | , test_case |
|---|
| 129 | ( |
|---|
| 130 | "test34" |
|---|
| 131 | , L("foobarFOO") |
|---|
| 132 | , regex_type(icase(L("foo") >> ~before(L("bar")))) |
|---|
| 133 | , backrefs(L("FOO"), nilbr) |
|---|
| 134 | ) |
|---|
| 135 | , test_case |
|---|
| 136 | ( |
|---|
| 137 | "test35" |
|---|
| 138 | , L("foobarFOObarfoo") |
|---|
| 139 | , regex_type(icase(+(s1= keep(s2= L("foo")) >> L("bar")))) |
|---|
| 140 | , backrefs(L("foobarFOObar"), L("FOObar"), L("FOO"), nilbr) |
|---|
| 141 | ) |
|---|
| 142 | , test_case |
|---|
| 143 | ( |
|---|
| 144 | "test37" |
|---|
| 145 | , L("foobar") |
|---|
| 146 | , regex_type(+(s1= L("bar") | (s2= L("foo")))) |
|---|
| 147 | , backrefs(L("foobar"), L("bar"), L("foo"), nilbr) |
|---|
| 148 | ) |
|---|
| 149 | , test_case |
|---|
| 150 | ( |
|---|
| 151 | "test38" |
|---|
| 152 | , L("foobar") |
|---|
| 153 | , regex_type(+(s1= (s2= L("bar")) | L("foo"))) |
|---|
| 154 | , backrefs(L("foobar"), L("bar"), L("bar"), nilbr) |
|---|
| 155 | ) |
|---|
| 156 | , test_case |
|---|
| 157 | ( |
|---|
| 158 | "test39" |
|---|
| 159 | , L("foobar") |
|---|
| 160 | , regex_type(+(s1= L("foo") | (s2= L("bar")))) |
|---|
| 161 | , backrefs(L("foobar"), L("bar"), L("bar"), nilbr) |
|---|
| 162 | ) |
|---|
| 163 | , test_case |
|---|
| 164 | ( |
|---|
| 165 | "test40" |
|---|
| 166 | , L("foobar") |
|---|
| 167 | , regex_type(+(s1= (s2= L("foo")) | L("bar"))) |
|---|
| 168 | , backrefs(L("foobar"), L("bar"), L("foo"), nilbr) |
|---|
| 169 | ) |
|---|
| 170 | }; |
|---|
| 171 | |
|---|
| 172 | return boost::make_iterator_range(test_cases); |
|---|
| 173 | } |
|---|