| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/url_matcher/regex_set_matcher.h" | 5 #include "components/url_matcher/regex_set_matcher.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 12 | 12 |
| 13 namespace url_matcher { | 13 namespace url_matcher { |
| 14 | 14 |
| 15 TEST(RegexSetMatcherTest, MatchRegexes) { | 15 TEST(RegexSetMatcherTest, MatchRegexes) { |
| 16 StringPattern pattern_1("ab.*c", 42); | 16 StringPattern pattern_1("ab.*c", 42); |
| 17 StringPattern pattern_2("f*f", 17); | 17 StringPattern pattern_2("f*f", 17); |
| 18 StringPattern pattern_3("c(ar|ra)b|brac", 239); | 18 StringPattern pattern_3("c(ar|ra)b|brac", 239); |
| 19 std::vector<const StringPattern*> regexes; | 19 std::vector<const StringPattern*> regexes; |
| 20 regexes.push_back(&pattern_1); | 20 regexes.push_back(&pattern_1); |
| 21 regexes.push_back(&pattern_2); | 21 regexes.push_back(&pattern_2); |
| 22 regexes.push_back(&pattern_3); | 22 regexes.push_back(&pattern_3); |
| 23 RegexSetMatcher matcher; | 23 RegexSetMatcher matcher; |
| 24 matcher.AddPatterns(regexes); | 24 matcher.AddPatterns(regexes); |
| 25 | 25 |
| 26 std::set<StringPattern::ID> result1; | 26 std::set<StringPattern::ID> result1; |
| 27 matcher.Match("http://abracadabra.com", &result1); | 27 matcher.Match("http://abracadabra.com", &result1); |
| 28 EXPECT_EQ(2U, result1.size()); | 28 EXPECT_EQ(2U, result1.size()); |
| 29 EXPECT_TRUE(ContainsKey(result1, 42)); | 29 EXPECT_TRUE(base::ContainsKey(result1, 42)); |
| 30 EXPECT_TRUE(ContainsKey(result1, 239)); | 30 EXPECT_TRUE(base::ContainsKey(result1, 239)); |
| 31 | 31 |
| 32 std::set<StringPattern::ID> result2; | 32 std::set<StringPattern::ID> result2; |
| 33 matcher.Match("https://abfffffffffffffffffffffffffffffff.fi/cf", &result2); | 33 matcher.Match("https://abfffffffffffffffffffffffffffffff.fi/cf", &result2); |
| 34 EXPECT_EQ(2U, result2.size()); | 34 EXPECT_EQ(2U, result2.size()); |
| 35 EXPECT_TRUE(ContainsKey(result2, 17)); | 35 EXPECT_TRUE(base::ContainsKey(result2, 17)); |
| 36 EXPECT_TRUE(ContainsKey(result2, 42)); | 36 EXPECT_TRUE(base::ContainsKey(result2, 42)); |
| 37 | 37 |
| 38 std::set<StringPattern::ID> result3; | 38 std::set<StringPattern::ID> result3; |
| 39 matcher.Match("http://nothing.com/", &result3); | 39 matcher.Match("http://nothing.com/", &result3); |
| 40 EXPECT_EQ(0U, result3.size()); | 40 EXPECT_EQ(0U, result3.size()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 TEST(RegexSetMatcherTest, CaseSensitivity) { | 43 TEST(RegexSetMatcherTest, CaseSensitivity) { |
| 44 StringPattern pattern_1("AAA", 51); | 44 StringPattern pattern_1("AAA", 51); |
| 45 StringPattern pattern_2("aaA", 57); | 45 StringPattern pattern_2("aaA", 57); |
| 46 std::vector<const StringPattern*> regexes; | 46 std::vector<const StringPattern*> regexes; |
| 47 regexes.push_back(&pattern_1); | 47 regexes.push_back(&pattern_1); |
| 48 regexes.push_back(&pattern_2); | 48 regexes.push_back(&pattern_2); |
| 49 RegexSetMatcher matcher; | 49 RegexSetMatcher matcher; |
| 50 matcher.AddPatterns(regexes); | 50 matcher.AddPatterns(regexes); |
| 51 | 51 |
| 52 std::set<StringPattern::ID> result1; | 52 std::set<StringPattern::ID> result1; |
| 53 matcher.Match("http://aaa.net/", &result1); | 53 matcher.Match("http://aaa.net/", &result1); |
| 54 EXPECT_EQ(0U, result1.size()); | 54 EXPECT_EQ(0U, result1.size()); |
| 55 | 55 |
| 56 std::set<StringPattern::ID> result2; | 56 std::set<StringPattern::ID> result2; |
| 57 matcher.Match("http://aaa.net/quaaACK", &result2); | 57 matcher.Match("http://aaa.net/quaaACK", &result2); |
| 58 EXPECT_EQ(1U, result2.size()); | 58 EXPECT_EQ(1U, result2.size()); |
| 59 EXPECT_TRUE(ContainsKey(result2, 57)); | 59 EXPECT_TRUE(base::ContainsKey(result2, 57)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // namespace url_matcher | 62 } // namespace url_matcher |
| OLD | NEW |