Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 20 | * |
| 21 | * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/> |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 22 | */ |
| 23 | |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 24 | #include "util/regex/regex-backref-manager.hpp" |
| 25 | #include "util/regex/regex-component-matcher.hpp" |
| 26 | #include "util/regex/regex-component-set-matcher.hpp" |
| 27 | #include "util/regex/regex-pattern-list-matcher.hpp" |
| 28 | #include "util/regex/regex-repeat-matcher.hpp" |
| 29 | #include "util/regex/regex-backref-matcher.hpp" |
| 30 | #include "util/regex/regex-top-matcher.hpp" |
| 31 | #include "util/regex.hpp" |
| 32 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 33 | #include "boost-test.hpp" |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 34 | |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 35 | using namespace std; |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 36 | namespace ndn { |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 37 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 38 | BOOST_AUTO_TEST_SUITE(UtilTestRegex) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 39 | |
| 40 | BOOST_AUTO_TEST_CASE(ComponentMatcher) |
| 41 | { |
| 42 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 43 | shared_ptr<RegexBackrefManager> backRef = make_shared<RegexBackrefManager>(); |
| 44 | shared_ptr<RegexComponentMatcher> cm = make_shared<RegexComponentMatcher>("a", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 45 | bool res = cm->match(Name("/a/b/"), 0, 1); |
| 46 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 47 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 48 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 49 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 50 | backRef = make_shared<RegexBackrefManager>(); |
| 51 | cm = make_shared<RegexComponentMatcher>("a", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 52 | res = cm->match(Name("/a/b/"), 1, 1); |
| 53 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 54 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 55 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 56 | backRef = make_shared<RegexBackrefManager>(); |
| 57 | cm = make_shared<RegexComponentMatcher>("(c+)\\.(cd)", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 58 | res = cm->match(Name("/ccc.cd/b/"), 0, 1); |
| 59 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 60 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 61 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("ccc.cd")); |
| 62 | BOOST_CHECK_EQUAL(backRef->getBackref(0)->getMatchResult()[0].toUri(), string("ccc")); |
| 63 | BOOST_CHECK_EQUAL(backRef->getBackref(1)->getMatchResult()[0].toUri(), string("cd")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 66 | BOOST_AUTO_TEST_CASE(ComponentSetMatcher) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 67 | { |
| 68 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 69 | shared_ptr<RegexBackrefManager> backRef = make_shared<RegexBackrefManager>(); |
| 70 | shared_ptr<RegexComponentSetMatcher> cm = make_shared<RegexComponentSetMatcher>("<a>", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 71 | bool res = cm->match(Name("/a/b/"), 0, 1); |
| 72 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 73 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 74 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 75 | |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 76 | res = cm->match(Name("/a/b/"), 1, 1); |
| 77 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 78 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 79 | |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 80 | res = cm->match(Name("/a/b/"), 0, 2); |
| 81 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 82 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 83 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 84 | backRef = make_shared<RegexBackrefManager>(); |
| 85 | cm = make_shared<RegexComponentSetMatcher>("[<a><b><c>]", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 86 | res = cm->match(Name("/a/b/d"), 1, 1); |
| 87 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 88 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 89 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 90 | |
| 91 | res = cm->match(Name("/a/b/d"), 2, 1); |
| 92 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 93 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 94 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 95 | backRef = make_shared<RegexBackrefManager>(); |
| 96 | cm = make_shared<RegexComponentSetMatcher>("[^<a><b><c>]", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 97 | res = cm->match(Name("/b/d"), 1, 1); |
| 98 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 99 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 100 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("d")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 101 | |
| 102 | } |
| 103 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 104 | BOOST_AUTO_TEST_CASE(RepeatMatcher) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 105 | { |
| 106 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 107 | shared_ptr<RegexBackrefManager> backRef = make_shared<RegexBackrefManager>(); |
| 108 | shared_ptr<RegexRepeatMatcher> cm = make_shared<RegexRepeatMatcher>("[<a><b>]*", backRef, 8); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 109 | bool res = cm->match(Name("/a/b/c"), 0, 0); |
| 110 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 111 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 112 | |
| 113 | cm->match(Name("/a/b/c"), 0, 2); |
| 114 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 115 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 116 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 117 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 118 | |
| 119 | |
| 120 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 121 | backRef = make_shared<RegexBackrefManager>(); |
| 122 | cm = make_shared<RegexRepeatMatcher>("[<a><b>]+", backRef, 8); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 123 | res = cm->match(Name("/a/b/c"), 0, 0); |
| 124 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 125 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 126 | |
| 127 | res = cm->match(Name("/a/b/c"), 0, 2); |
| 128 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 129 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 130 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 131 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 132 | |
| 133 | |
| 134 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 135 | backRef = make_shared<RegexBackrefManager>(); |
| 136 | cm = make_shared<RegexRepeatMatcher>("<.*>*", backRef, 4); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 137 | res = cm->match(Name("/a/b/c/d/e/f/"), 0, 6); |
| 138 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 139 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 6); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 140 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 141 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 142 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
| 143 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("d")); |
| 144 | BOOST_CHECK_EQUAL(cm->getMatchResult()[4].toUri(), string("e")); |
| 145 | BOOST_CHECK_EQUAL(cm->getMatchResult()[5].toUri(), string("f")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 146 | |
| 147 | |
| 148 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 149 | backRef = make_shared<RegexBackrefManager>(); |
| 150 | cm = make_shared<RegexRepeatMatcher>("<>*", backRef, 2); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 151 | res = cm->match(Name("/a/b/c/d/e/f/"), 0, 6); |
| 152 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 153 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 6); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 154 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 155 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 156 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
| 157 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("d")); |
| 158 | BOOST_CHECK_EQUAL(cm->getMatchResult()[4].toUri(), string("e")); |
| 159 | BOOST_CHECK_EQUAL(cm->getMatchResult()[5].toUri(), string("f")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 160 | |
| 161 | |
| 162 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 163 | backRef = make_shared<RegexBackrefManager>(); |
| 164 | cm = make_shared<RegexRepeatMatcher>("<a>?", backRef, 3); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 165 | res = cm->match(Name("/a/b/c"), 0, 0); |
| 166 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 167 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 168 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 169 | cm = make_shared<RegexRepeatMatcher>("<a>?", backRef, 3); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 170 | res = cm->match(Name("/a/b/c"), 0, 1); |
| 171 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 172 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 173 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 174 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 175 | cm = make_shared<RegexRepeatMatcher>("<a>?", backRef, 3); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 176 | res = cm->match(Name("/a/b/c"), 0, 2); |
| 177 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 178 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 179 | |
| 180 | |
| 181 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 182 | backRef = make_shared<RegexBackrefManager>(); |
| 183 | cm = make_shared<RegexRepeatMatcher>("[<a><b>]{3}", backRef, 8); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 184 | res = cm->match(Name("/a/b/a/d/"), 0, 2); |
| 185 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 186 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 187 | |
| 188 | res = cm->match(Name("/a/b/a/d/"), 0, 3); |
| 189 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 190 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 3); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 191 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 192 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 193 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("a")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 194 | |
| 195 | res = cm->match(Name("/a/b/a/d/"), 0, 4); |
| 196 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 197 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 198 | |
| 199 | |
| 200 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 201 | backRef = make_shared<RegexBackrefManager>(); |
| 202 | cm = make_shared<RegexRepeatMatcher>("[<a><b>]{2,3}", backRef, 8); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 203 | res = cm->match(Name("/a/b/a/d/e/"), 0, 2); |
| 204 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 205 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 206 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 207 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 208 | |
| 209 | res = cm->match(Name("/a/b/a/d/e/"), 0, 3); |
| 210 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 211 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 3); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 212 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 213 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 214 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("a")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 215 | |
| 216 | res = cm->match(Name("/a/b/a/b/e/"), 0, 4); |
| 217 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 218 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 219 | |
| 220 | res = cm->match(Name("/a/b/a/d/e/"), 0, 1); |
| 221 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 222 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 223 | |
| 224 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 225 | backRef = make_shared<RegexBackrefManager>(); |
| 226 | cm = make_shared<RegexRepeatMatcher>("[<a><b>]{2,}", backRef, 8); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 227 | res = cm->match(Name("/a/b/a/d/e/"), 0, 2); |
| 228 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 229 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 230 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 231 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 232 | |
| 233 | res = cm->match(Name("/a/b/a/b/e/"), 0, 4); |
| 234 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 235 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 236 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 237 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 238 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("a")); |
| 239 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 240 | |
| 241 | res = cm->match(Name("/a/b/a/d/e/"), 0, 1); |
| 242 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 243 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 244 | |
| 245 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 246 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 247 | backRef = make_shared<RegexBackrefManager>(); |
| 248 | cm = make_shared<RegexRepeatMatcher>("[<a><b>]{,2}", backRef, 8); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 249 | res = cm->match(Name("/a/b/a/b/e/"), 0, 3); |
| 250 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 251 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 252 | |
| 253 | res = cm->match(Name("/a/b/a/b/e/"), 0, 2); |
| 254 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 255 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 256 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 257 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 258 | |
| 259 | res = cm->match(Name("/a/b/a/d/e/"), 0, 1); |
| 260 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 261 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 262 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 263 | |
| 264 | res = cm->match(Name("/a/b/a/d/e/"), 0, 0); |
| 265 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 266 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 269 | BOOST_AUTO_TEST_CASE(BackRefMatcher) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 270 | { |
| 271 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 272 | shared_ptr<RegexBackrefManager> backRef = make_shared<RegexBackrefManager>(); |
| 273 | shared_ptr<RegexBackrefMatcher> cm = make_shared<RegexBackrefMatcher>("(<a><b>)", backRef); |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 274 | backRef->pushRef(static_pointer_cast<RegexMatcher>(cm)); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 275 | cm->lateCompile(); |
| 276 | bool res = cm->match(Name("/a/b/c"), 0, 2); |
| 277 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 278 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 279 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 280 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 281 | BOOST_CHECK_EQUAL(backRef->size(), 1); |
| 282 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 283 | backRef = make_shared<RegexBackrefManager>(); |
| 284 | cm = make_shared<RegexBackrefMatcher>("(<a>(<b>))", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 285 | backRef->pushRef(cm); |
| 286 | cm->lateCompile(); |
| 287 | res = cm->match(Name("/a/b/c"), 0, 2); |
| 288 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 289 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 290 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 291 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 292 | BOOST_CHECK_EQUAL(backRef->size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 293 | BOOST_CHECK_EQUAL(backRef->getBackref(0)->getMatchResult()[0].toUri(), string("a")); |
| 294 | BOOST_CHECK_EQUAL(backRef->getBackref(0)->getMatchResult()[1].toUri(), string("b")); |
| 295 | BOOST_CHECK_EQUAL(backRef->getBackref(1)->getMatchResult()[0].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 296 | } |
| 297 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 298 | BOOST_AUTO_TEST_CASE(BackRefMatcherAdvanced) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 299 | { |
| 300 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 301 | shared_ptr<RegexBackrefManager> backRef = make_shared<RegexBackrefManager>(); |
| 302 | shared_ptr<RegexRepeatMatcher> cm = make_shared<RegexRepeatMatcher>("([<a><b>])+", backRef, 10); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 303 | bool res = cm->match(Name("/a/b/c"), 0, 2); |
| 304 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 305 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 306 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 307 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 308 | BOOST_CHECK_EQUAL(backRef->size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 309 | BOOST_CHECK_EQUAL(backRef->getBackref(0)->getMatchResult()[0].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 312 | BOOST_AUTO_TEST_CASE(BackRefMatcherAdvanced2) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 313 | { |
| 314 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 315 | shared_ptr<RegexBackrefManager> backRef = make_shared<RegexBackrefManager>(); |
| 316 | shared_ptr<RegexPatternListMatcher> cm = make_shared<RegexPatternListMatcher>("(<a>(<b>))<c>", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 317 | bool res = cm->match(Name("/a/b/c"), 0, 3); |
| 318 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 319 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 3); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 320 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 321 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 322 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 323 | BOOST_CHECK_EQUAL(backRef->size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 324 | BOOST_CHECK_EQUAL(backRef->getBackref(0)->getMatchResult()[0].toUri(), string("a")); |
| 325 | BOOST_CHECK_EQUAL(backRef->getBackref(0)->getMatchResult()[1].toUri(), string("b")); |
| 326 | BOOST_CHECK_EQUAL(backRef->getBackref(1)->getMatchResult()[0].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 327 | } |
| 328 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 329 | BOOST_AUTO_TEST_CASE(PatternListMatcher) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 330 | { |
| 331 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 332 | shared_ptr<RegexBackrefManager> backRef = make_shared<RegexBackrefManager>(); |
| 333 | shared_ptr<RegexPatternListMatcher> cm = make_shared<RegexPatternListMatcher>("<a>[<a><b>]", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 334 | bool res = cm->match(Name("/a/b/c"), 0, 2); |
| 335 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 336 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 337 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 338 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 339 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 340 | backRef = make_shared<RegexBackrefManager>(); |
| 341 | cm = make_shared<RegexPatternListMatcher>("<>*<a>", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 342 | res = cm->match(Name("/a/b/c"), 0, 1); |
| 343 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 344 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 345 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 346 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 347 | backRef = make_shared<RegexBackrefManager>(); |
| 348 | cm = make_shared<RegexPatternListMatcher>("<>*<a>", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 349 | res = cm->match(Name("/a/b/c"), 0, 2); |
| 350 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 351 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 352 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 353 | backRef = make_shared<RegexBackrefManager>(); |
| 354 | cm = make_shared<RegexPatternListMatcher>("<>*<a><>*", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 355 | res = cm->match(Name("/a/b/c"), 0, 3); |
| 356 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 357 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 3); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 358 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 359 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 360 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 361 | |
| 362 | } |
| 363 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 364 | BOOST_AUTO_TEST_CASE(TopMatcher) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 365 | { |
| 366 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 367 | shared_ptr<RegexTopMatcher> cm = make_shared<RegexTopMatcher>("^<a><b><c>"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 368 | bool res = cm->match(Name("/a/b/c/d")); |
| 369 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 370 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 371 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 372 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 373 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
| 374 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("d")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 375 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 376 | cm = make_shared<RegexTopMatcher>("<b><c><d>$"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 377 | res = cm->match(Name("/a/b/c/d")); |
| 378 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 379 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 380 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 381 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 382 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
| 383 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("d")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 384 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 385 | cm = make_shared<RegexTopMatcher>("^<a><b><c><d>$"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 386 | res = cm->match(Name("/a/b/c/d")); |
| 387 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 388 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 389 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 390 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 391 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
| 392 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("d")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 393 | |
| 394 | res = cm->match(Name("/a/b/c/d/e")); |
| 395 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 396 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 397 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 398 | cm = make_shared<RegexTopMatcher>("<a><b><c><d>"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 399 | res = cm->match(Name("/a/b/c/d")); |
| 400 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 401 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 402 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 403 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 404 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
| 405 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("d")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 406 | |
| 407 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 408 | cm = make_shared<RegexTopMatcher>("<b><c>"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 409 | res = cm->match(Name("/a/b/c/d")); |
| 410 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 411 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 412 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 413 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 414 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
| 415 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("d")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 416 | } |
| 417 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 418 | BOOST_AUTO_TEST_CASE(TopMatcherAdvanced) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 419 | { |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 420 | shared_ptr<Regex> cm = make_shared<Regex>("^(<.*>*)<.*>"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 421 | bool res = cm->match(Name("/n/a/b/c")); |
| 422 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 423 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 424 | BOOST_CHECK_EQUAL(cm->expand("\\1"), Name("/n/a/b/")); |
| 425 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 426 | cm = make_shared<Regex>("^(<.*>*)<.*><c>(<.*>)<.*>"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 427 | res = cm->match(Name("/n/a/b/c/d/e/")); |
| 428 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 429 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 6); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 430 | BOOST_CHECK_EQUAL(cm->expand("\\1\\2"), Name("/n/a/d/")); |
| 431 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 432 | cm = make_shared<Regex>("(<.*>*)<.*>$"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 433 | res = cm->match(Name("/n/a/b/c/")); |
| 434 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 435 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 436 | BOOST_CHECK_EQUAL(cm->expand("\\1"), Name("/n/a/b/")); |
| 437 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 438 | cm = make_shared<Regex>("<.*>(<.*>*)<.*>$"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 439 | res = cm->match(Name("/n/a/b/c/")); |
| 440 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 441 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 442 | BOOST_CHECK_EQUAL(cm->expand("\\1"), Name("/a/b/")); |
| 443 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 444 | cm = make_shared<Regex>("<a>(<>*)<>$"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 445 | res = cm->match(Name("/n/a/b/c/")); |
| 446 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 447 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 448 | BOOST_CHECK_EQUAL(cm->expand("\\1"), Name("/b/")); |
| 449 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 450 | cm = make_shared<Regex>("^<ndn><(.*)\\.(.*)><DNS>(<>*)<>"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 451 | res = cm->match(Name("/ndn/ucla.edu/DNS/yingdi/mac/ksk-1/")); |
| 452 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 453 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 6); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 454 | BOOST_CHECK_EQUAL(cm->expand("<ndn>\\2\\1\\3"), Name("/ndn/edu/ucla/yingdi/mac/")); |
| 455 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 456 | cm = make_shared<Regex>("^<ndn><(.*)\\.(.*)><DNS>(<>*)<>", "<ndn>\\2\\1\\3"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 457 | res = cm->match(Name("/ndn/ucla.edu/DNS/yingdi/mac/ksk-1/")); |
| 458 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 459 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 6); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 460 | BOOST_CHECK_EQUAL(cm->expand(), Name("/ndn/edu/ucla/yingdi/mac/")); |
| 461 | } |
| 462 | |
| 463 | BOOST_AUTO_TEST_SUITE_END() |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 464 | |
| 465 | } // namespace ndn |