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