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