Add abhijeet.k@samsung.com to AUTHORS list.
[chromium-blink-merge.git] / components / url_matcher / regex_set_matcher_unittest.cc
blobdd54e51d2fbb19872212b3c254157ff771db21c6
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
3 // found in the LICENSE file.
5 #include "components/url_matcher/regex_set_matcher.h"
7 #include <set>
9 #include "base/stl_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "url/gurl.h"
13 namespace url_matcher {
15 TEST(RegexSetMatcherTest, MatchRegexes) {
16 StringPattern pattern_1("ab.*c", 42);
17 StringPattern pattern_2("f*f", 17);
18 StringPattern pattern_3("c(ar|ra)b|brac", 239);
19 std::vector<const StringPattern*> regexes;
20 regexes.push_back(&pattern_1);
21 regexes.push_back(&pattern_2);
22 regexes.push_back(&pattern_3);
23 RegexSetMatcher matcher;
24 matcher.AddPatterns(regexes);
26 std::set<StringPattern::ID> result1;
27 matcher.Match("http://abracadabra.com", &result1);
28 EXPECT_EQ(2U, result1.size());
29 EXPECT_TRUE(ContainsKey(result1, 42));
30 EXPECT_TRUE(ContainsKey(result1, 239));
32 std::set<StringPattern::ID> result2;
33 matcher.Match("https://abfffffffffffffffffffffffffffffff.fi/cf", &result2);
34 EXPECT_EQ(2U, result2.size());
35 EXPECT_TRUE(ContainsKey(result2, 17));
36 EXPECT_TRUE(ContainsKey(result2, 42));
38 std::set<StringPattern::ID> result3;
39 matcher.Match("http://nothing.com/", &result3);
40 EXPECT_EQ(0U, result3.size());
43 TEST(RegexSetMatcherTest, CaseSensitivity) {
44 StringPattern pattern_1("AAA", 51);
45 StringPattern pattern_2("aaA", 57);
46 std::vector<const StringPattern*> regexes;
47 regexes.push_back(&pattern_1);
48 regexes.push_back(&pattern_2);
49 RegexSetMatcher matcher;
50 matcher.AddPatterns(regexes);
52 std::set<StringPattern::ID> result1;
53 matcher.Match("http://aaa.net/", &result1);
54 EXPECT_EQ(0U, result1.size());
56 std::set<StringPattern::ID> result2;
57 matcher.Match("http://aaa.net/quaaACK", &result2);
58 EXPECT_EQ(1U, result2.size());
59 EXPECT_TRUE(ContainsKey(result2, 57));
62 } // namespace url_matcher