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")); |
Alexander Afanasyev | 680e77a | 2014-08-14 22:39:17 -0700 | [diff] [blame] | 62 | |
| 63 | BOOST_REQUIRE_EQUAL(backRef->size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 64 | BOOST_CHECK_EQUAL(backRef->getBackref(0)->getMatchResult()[0].toUri(), string("ccc")); |
| 65 | BOOST_CHECK_EQUAL(backRef->getBackref(1)->getMatchResult()[0].toUri(), string("cd")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 68 | BOOST_AUTO_TEST_CASE(ComponentSetMatcher) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 69 | { |
| 70 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 71 | shared_ptr<RegexBackrefManager> backRef = make_shared<RegexBackrefManager>(); |
| 72 | shared_ptr<RegexComponentSetMatcher> cm = make_shared<RegexComponentSetMatcher>("<a>", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 73 | bool res = cm->match(Name("/a/b/"), 0, 1); |
| 74 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 75 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 76 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 77 | |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 78 | res = cm->match(Name("/a/b/"), 1, 1); |
| 79 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 80 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 81 | |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 82 | res = cm->match(Name("/a/b/"), 0, 2); |
| 83 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 84 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 85 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 86 | backRef = make_shared<RegexBackrefManager>(); |
| 87 | cm = make_shared<RegexComponentSetMatcher>("[<a><b><c>]", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 88 | res = cm->match(Name("/a/b/d"), 1, 1); |
| 89 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 90 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 91 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 92 | |
| 93 | res = cm->match(Name("/a/b/d"), 2, 1); |
| 94 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 95 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 96 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 97 | backRef = make_shared<RegexBackrefManager>(); |
| 98 | cm = make_shared<RegexComponentSetMatcher>("[^<a><b><c>]", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 99 | res = cm->match(Name("/b/d"), 1, 1); |
| 100 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 101 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 102 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("d")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 103 | |
| 104 | } |
| 105 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 106 | BOOST_AUTO_TEST_CASE(RepeatMatcher) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 107 | { |
| 108 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 109 | shared_ptr<RegexBackrefManager> backRef = make_shared<RegexBackrefManager>(); |
| 110 | shared_ptr<RegexRepeatMatcher> cm = make_shared<RegexRepeatMatcher>("[<a><b>]*", backRef, 8); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 111 | bool res = cm->match(Name("/a/b/c"), 0, 0); |
| 112 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 113 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 114 | |
| 115 | cm->match(Name("/a/b/c"), 0, 2); |
| 116 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 117 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 118 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 119 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 120 | |
| 121 | |
| 122 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 123 | backRef = make_shared<RegexBackrefManager>(); |
| 124 | cm = make_shared<RegexRepeatMatcher>("[<a><b>]+", backRef, 8); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 125 | res = cm->match(Name("/a/b/c"), 0, 0); |
| 126 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 127 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 128 | |
| 129 | res = cm->match(Name("/a/b/c"), 0, 2); |
| 130 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 131 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 132 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 133 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 134 | |
| 135 | |
| 136 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 137 | backRef = make_shared<RegexBackrefManager>(); |
| 138 | cm = make_shared<RegexRepeatMatcher>("<.*>*", backRef, 4); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 139 | res = cm->match(Name("/a/b/c/d/e/f/"), 0, 6); |
| 140 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 141 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 6); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 142 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 143 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 144 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
| 145 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("d")); |
| 146 | BOOST_CHECK_EQUAL(cm->getMatchResult()[4].toUri(), string("e")); |
| 147 | BOOST_CHECK_EQUAL(cm->getMatchResult()[5].toUri(), string("f")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 148 | |
| 149 | |
| 150 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 151 | backRef = make_shared<RegexBackrefManager>(); |
| 152 | cm = make_shared<RegexRepeatMatcher>("<>*", backRef, 2); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 153 | res = cm->match(Name("/a/b/c/d/e/f/"), 0, 6); |
| 154 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 155 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 6); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 156 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 157 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 158 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
| 159 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("d")); |
| 160 | BOOST_CHECK_EQUAL(cm->getMatchResult()[4].toUri(), string("e")); |
| 161 | BOOST_CHECK_EQUAL(cm->getMatchResult()[5].toUri(), string("f")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 162 | |
| 163 | |
| 164 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 165 | backRef = make_shared<RegexBackrefManager>(); |
| 166 | cm = make_shared<RegexRepeatMatcher>("<a>?", backRef, 3); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 167 | res = cm->match(Name("/a/b/c"), 0, 0); |
| 168 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 169 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 170 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 171 | cm = make_shared<RegexRepeatMatcher>("<a>?", backRef, 3); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 172 | res = cm->match(Name("/a/b/c"), 0, 1); |
| 173 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 174 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 175 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 176 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 177 | cm = make_shared<RegexRepeatMatcher>("<a>?", backRef, 3); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 178 | res = cm->match(Name("/a/b/c"), 0, 2); |
| 179 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 180 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 181 | |
| 182 | |
| 183 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 184 | backRef = make_shared<RegexBackrefManager>(); |
| 185 | cm = make_shared<RegexRepeatMatcher>("[<a><b>]{3}", backRef, 8); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 186 | res = cm->match(Name("/a/b/a/d/"), 0, 2); |
| 187 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 188 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 189 | |
| 190 | res = cm->match(Name("/a/b/a/d/"), 0, 3); |
| 191 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 192 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 3); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 193 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 194 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 195 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("a")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 196 | |
| 197 | res = cm->match(Name("/a/b/a/d/"), 0, 4); |
| 198 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 199 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 200 | |
| 201 | |
| 202 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 203 | backRef = make_shared<RegexBackrefManager>(); |
| 204 | cm = make_shared<RegexRepeatMatcher>("[<a><b>]{2,3}", backRef, 8); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 205 | res = cm->match(Name("/a/b/a/d/e/"), 0, 2); |
| 206 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 207 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 208 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 209 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 210 | |
| 211 | res = cm->match(Name("/a/b/a/d/e/"), 0, 3); |
| 212 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 213 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 3); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 214 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 215 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 216 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("a")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 217 | |
| 218 | res = cm->match(Name("/a/b/a/b/e/"), 0, 4); |
| 219 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 220 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 221 | |
| 222 | res = cm->match(Name("/a/b/a/d/e/"), 0, 1); |
| 223 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 224 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 225 | |
| 226 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 227 | backRef = make_shared<RegexBackrefManager>(); |
| 228 | cm = make_shared<RegexRepeatMatcher>("[<a><b>]{2,}", backRef, 8); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 229 | res = cm->match(Name("/a/b/a/d/e/"), 0, 2); |
| 230 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 231 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 232 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 233 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 234 | |
| 235 | res = cm->match(Name("/a/b/a/b/e/"), 0, 4); |
| 236 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 237 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 238 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 239 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 240 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("a")); |
| 241 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 242 | |
| 243 | res = cm->match(Name("/a/b/a/d/e/"), 0, 1); |
| 244 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 245 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 246 | |
| 247 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 248 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 249 | backRef = make_shared<RegexBackrefManager>(); |
| 250 | cm = make_shared<RegexRepeatMatcher>("[<a><b>]{,2}", backRef, 8); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 251 | res = cm->match(Name("/a/b/a/b/e/"), 0, 3); |
| 252 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 253 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 254 | |
| 255 | res = cm->match(Name("/a/b/a/b/e/"), 0, 2); |
| 256 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 257 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 258 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 259 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 260 | |
| 261 | res = cm->match(Name("/a/b/a/d/e/"), 0, 1); |
| 262 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 263 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 264 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 265 | |
| 266 | res = cm->match(Name("/a/b/a/d/e/"), 0, 0); |
| 267 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 268 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 271 | BOOST_AUTO_TEST_CASE(BackRefMatcher) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 272 | { |
| 273 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 274 | shared_ptr<RegexBackrefManager> backRef = make_shared<RegexBackrefManager>(); |
| 275 | shared_ptr<RegexBackrefMatcher> cm = make_shared<RegexBackrefMatcher>("(<a><b>)", backRef); |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 276 | backRef->pushRef(static_pointer_cast<RegexMatcher>(cm)); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 277 | cm->lateCompile(); |
| 278 | bool res = cm->match(Name("/a/b/c"), 0, 2); |
| 279 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 280 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 281 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 282 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 283 | BOOST_CHECK_EQUAL(backRef->size(), 1); |
| 284 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 285 | backRef = make_shared<RegexBackrefManager>(); |
| 286 | cm = make_shared<RegexBackrefMatcher>("(<a>(<b>))", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 287 | backRef->pushRef(cm); |
| 288 | cm->lateCompile(); |
| 289 | res = cm->match(Name("/a/b/c"), 0, 2); |
| 290 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 291 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 292 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 293 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 294 | BOOST_CHECK_EQUAL(backRef->size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 295 | BOOST_CHECK_EQUAL(backRef->getBackref(0)->getMatchResult()[0].toUri(), string("a")); |
| 296 | BOOST_CHECK_EQUAL(backRef->getBackref(0)->getMatchResult()[1].toUri(), string("b")); |
| 297 | BOOST_CHECK_EQUAL(backRef->getBackref(1)->getMatchResult()[0].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 300 | BOOST_AUTO_TEST_CASE(BackRefMatcherAdvanced) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 301 | { |
| 302 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 303 | shared_ptr<RegexBackrefManager> backRef = make_shared<RegexBackrefManager>(); |
| 304 | shared_ptr<RegexRepeatMatcher> cm = make_shared<RegexRepeatMatcher>("([<a><b>])+", backRef, 10); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 305 | bool res = cm->match(Name("/a/b/c"), 0, 2); |
| 306 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 307 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 308 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 309 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 310 | BOOST_CHECK_EQUAL(backRef->size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 311 | BOOST_CHECK_EQUAL(backRef->getBackref(0)->getMatchResult()[0].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 312 | } |
| 313 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 314 | BOOST_AUTO_TEST_CASE(BackRefMatcherAdvanced2) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 315 | { |
| 316 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 317 | shared_ptr<RegexBackrefManager> backRef = make_shared<RegexBackrefManager>(); |
| 318 | shared_ptr<RegexPatternListMatcher> cm = make_shared<RegexPatternListMatcher>("(<a>(<b>))<c>", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 319 | bool res = cm->match(Name("/a/b/c"), 0, 3); |
| 320 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 321 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 3); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 322 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 323 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 324 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 325 | BOOST_CHECK_EQUAL(backRef->size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 326 | BOOST_CHECK_EQUAL(backRef->getBackref(0)->getMatchResult()[0].toUri(), string("a")); |
| 327 | BOOST_CHECK_EQUAL(backRef->getBackref(0)->getMatchResult()[1].toUri(), string("b")); |
| 328 | BOOST_CHECK_EQUAL(backRef->getBackref(1)->getMatchResult()[0].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 329 | } |
| 330 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 331 | BOOST_AUTO_TEST_CASE(PatternListMatcher) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 332 | { |
| 333 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 334 | shared_ptr<RegexBackrefManager> backRef = make_shared<RegexBackrefManager>(); |
| 335 | shared_ptr<RegexPatternListMatcher> cm = make_shared<RegexPatternListMatcher>("<a>[<a><b>]", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 336 | bool res = cm->match(Name("/a/b/c"), 0, 2); |
| 337 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 338 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 2); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 339 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 340 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 341 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 342 | backRef = make_shared<RegexBackrefManager>(); |
| 343 | cm = make_shared<RegexPatternListMatcher>("<>*<a>", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 344 | res = cm->match(Name("/a/b/c"), 0, 1); |
| 345 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 346 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 1); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 347 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 348 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 349 | backRef = make_shared<RegexBackrefManager>(); |
| 350 | cm = make_shared<RegexPatternListMatcher>("<>*<a>", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 351 | res = cm->match(Name("/a/b/c"), 0, 2); |
| 352 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 353 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 354 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 355 | backRef = make_shared<RegexBackrefManager>(); |
| 356 | cm = make_shared<RegexPatternListMatcher>("<>*<a><>*", backRef); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 357 | res = cm->match(Name("/a/b/c"), 0, 3); |
| 358 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 359 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 3); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 360 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 361 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 362 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 363 | |
| 364 | } |
| 365 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 366 | BOOST_AUTO_TEST_CASE(TopMatcher) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 367 | { |
| 368 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 369 | shared_ptr<RegexTopMatcher> cm = make_shared<RegexTopMatcher>("^<a><b><c>"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 370 | bool res = cm->match(Name("/a/b/c/d")); |
| 371 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 372 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 373 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 374 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 375 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
| 376 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("d")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 377 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 378 | cm = make_shared<RegexTopMatcher>("<b><c><d>$"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 379 | res = cm->match(Name("/a/b/c/d")); |
| 380 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 381 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 382 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 383 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 384 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
| 385 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("d")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 386 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 387 | cm = make_shared<RegexTopMatcher>("^<a><b><c><d>$"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 388 | res = cm->match(Name("/a/b/c/d")); |
| 389 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 390 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 391 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 392 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 393 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
| 394 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("d")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 395 | |
| 396 | res = cm->match(Name("/a/b/c/d/e")); |
| 397 | BOOST_CHECK_EQUAL(res, false); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 398 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 0); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 399 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 400 | cm = make_shared<RegexTopMatcher>("<a><b><c><d>"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 401 | res = cm->match(Name("/a/b/c/d")); |
| 402 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 403 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 404 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 405 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 406 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
| 407 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("d")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 408 | |
| 409 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 410 | cm = make_shared<RegexTopMatcher>("<b><c>"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 411 | res = cm->match(Name("/a/b/c/d")); |
| 412 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 413 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 414 | BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("a")); |
| 415 | BOOST_CHECK_EQUAL(cm->getMatchResult()[1].toUri(), string("b")); |
| 416 | BOOST_CHECK_EQUAL(cm->getMatchResult()[2].toUri(), string("c")); |
| 417 | BOOST_CHECK_EQUAL(cm->getMatchResult()[3].toUri(), string("d")); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 418 | } |
| 419 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 420 | BOOST_AUTO_TEST_CASE(TopMatcherAdvanced) |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 421 | { |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 422 | shared_ptr<Regex> cm = make_shared<Regex>("^(<.*>*)<.*>"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 423 | bool res = cm->match(Name("/n/a/b/c")); |
| 424 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 425 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 426 | BOOST_CHECK_EQUAL(cm->expand("\\1"), Name("/n/a/b/")); |
| 427 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 428 | cm = make_shared<Regex>("^(<.*>*)<.*><c>(<.*>)<.*>"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 429 | res = cm->match(Name("/n/a/b/c/d/e/")); |
| 430 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 431 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 6); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 432 | BOOST_CHECK_EQUAL(cm->expand("\\1\\2"), Name("/n/a/d/")); |
| 433 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 434 | cm = make_shared<Regex>("(<.*>*)<.*>$"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 435 | res = cm->match(Name("/n/a/b/c/")); |
| 436 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 437 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 438 | BOOST_CHECK_EQUAL(cm->expand("\\1"), Name("/n/a/b/")); |
| 439 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 440 | cm = make_shared<Regex>("<.*>(<.*>*)<.*>$"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 441 | res = cm->match(Name("/n/a/b/c/")); |
| 442 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 443 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 444 | BOOST_CHECK_EQUAL(cm->expand("\\1"), Name("/a/b/")); |
| 445 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 446 | cm = make_shared<Regex>("<a>(<>*)<>$"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 447 | res = cm->match(Name("/n/a/b/c/")); |
| 448 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 449 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 4); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 450 | BOOST_CHECK_EQUAL(cm->expand("\\1"), Name("/b/")); |
| 451 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 452 | cm = make_shared<Regex>("^<ndn><(.*)\\.(.*)><DNS>(<>*)<>"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 453 | res = cm->match(Name("/ndn/ucla.edu/DNS/yingdi/mac/ksk-1/")); |
| 454 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 455 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 6); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 456 | BOOST_CHECK_EQUAL(cm->expand("<ndn>\\2\\1\\3"), Name("/ndn/edu/ucla/yingdi/mac/")); |
| 457 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 458 | cm = make_shared<Regex>("^<ndn><(.*)\\.(.*)><DNS>(<>*)<>", "<ndn>\\2\\1\\3"); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 459 | res = cm->match(Name("/ndn/ucla.edu/DNS/yingdi/mac/ksk-1/")); |
| 460 | BOOST_CHECK_EQUAL(res, true); |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 461 | BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 6); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 462 | BOOST_CHECK_EQUAL(cm->expand(), Name("/ndn/edu/ucla/yingdi/mac/")); |
| 463 | } |
| 464 | |
| 465 | BOOST_AUTO_TEST_SUITE_END() |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 466 | |
| 467 | } // namespace ndn |