Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: components/autofill/core/common/autofill_regexes_unittest.cc

Issue 1453193002: autofill: switch autofill_regexes to RE2 library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/autofill/core/common/autofill_regexes.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/autofill/core/common/autofill_regexes.h" 5 #include "components/autofill/core/common/autofill_regexes.h"
6 6
7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "components/autofill/core/browser/autofill_regex_constants.h" 7 #include "components/autofill/core/browser/autofill_regex_constants.h"
10 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
11 9
12 using base::ASCIIToUTF16;
13
14 namespace autofill { 10 namespace autofill {
15 11
16 TEST(AutofillRegexesTest, AutofillRegexes) { 12 TEST(AutofillRegexesTest, AutofillRegexes) {
tfarina 2015/11/18 18:03:10 Are these test cases enough Ilya? I'm not sure abo
17 struct TestCase { 13 struct TestCase {
18 const char* const input; 14 const char* const input;
19 const char* const pattern; 15 const char* const pattern;
20 }; 16 };
21 17
22 const TestCase kPositiveCases[] = { 18 const TestCase kPositiveCases[] = {
23 // Empty pattern 19 // Empty pattern
24 {"", ""}, 20 {"", ""},
25 {"Look, ma' -- a non-empty string!", ""}, 21 {"Look, ma' -- a non-empty string!", ""},
26 // Substring 22 // Substring
27 {"string", "tri"}, 23 {"string", "tri"},
28 // Substring at beginning 24 // Substring at beginning
29 {"string", "str"}, 25 {"string", "str"},
30 {"string", "^str"}, 26 {"string", "^str"},
31 // Substring at end 27 // Substring at end
32 {"string", "ring"}, 28 {"string", "ring"},
33 {"string", "ring$"}, 29 {"string", "ring$"},
34 // Case-insensitive 30 // Case-insensitive
35 {"StRiNg", "string"}, 31 {"StRiNg", "string"},
36 }; 32 };
37 for (size_t i = 0; i < arraysize(kPositiveCases); ++i) { 33 for (size_t i = 0; i < arraysize(kPositiveCases); ++i) {
38 const TestCase& test_case = kPositiveCases[i]; 34 const TestCase& test_case = kPositiveCases[i];
39 SCOPED_TRACE(test_case.input); 35 SCOPED_TRACE(test_case.input);
40 SCOPED_TRACE(test_case.pattern); 36 SCOPED_TRACE(test_case.pattern);
41 EXPECT_TRUE(MatchesPattern(ASCIIToUTF16(test_case.input), 37 EXPECT_TRUE(MatchesPattern(test_case.input, test_case.pattern));
42 ASCIIToUTF16(test_case.pattern)));
43 } 38 }
44 39
45 const TestCase kNegativeCases[] = { 40 const TestCase kNegativeCases[] = {
46 // Empty string 41 // Empty string
47 {"", "Look, ma' -- a non-empty pattern!"}, 42 {"", "Look, ma' -- a non-empty pattern!"},
48 // Substring 43 // Substring
49 {"string", "trn"}, 44 {"string", "trn"},
50 // Substring at beginning 45 // Substring at beginning
51 {"string", " str"}, 46 {"string", " str"},
52 {"string", "^tri"}, 47 {"string", "^tri"},
53 // Substring at end 48 // Substring at end
54 {"string", "ring "}, 49 {"string", "ring "},
55 {"string", "rin$"}, 50 {"string", "rin$"},
56 }; 51 };
57 for (size_t i = 0; i < arraysize(kNegativeCases); ++i) { 52 for (size_t i = 0; i < arraysize(kNegativeCases); ++i) {
58 const TestCase& test_case = kNegativeCases[i]; 53 const TestCase& test_case = kNegativeCases[i];
59 SCOPED_TRACE(test_case.input); 54 SCOPED_TRACE(test_case.input);
60 SCOPED_TRACE(test_case.pattern); 55 SCOPED_TRACE(test_case.pattern);
61 EXPECT_FALSE(MatchesPattern(ASCIIToUTF16(test_case.input), 56 EXPECT_FALSE(MatchesPattern(test_case.input, test_case.pattern));
62 ASCIIToUTF16(test_case.pattern)));
63 } 57 }
64 } 58 }
65 59
66 } // namespace autofill 60 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/common/autofill_regexes.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698