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/autofill/core/common/autofill_regexes.h" | 5 #include "components/autofill/core/common/autofill_regexes.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 {"string", "tri"}, | 30 {"string", "tri"}, |
31 // Substring at beginning | 31 // Substring at beginning |
32 {"string", "str"}, | 32 {"string", "str"}, |
33 {"string", "^str"}, | 33 {"string", "^str"}, |
34 // Substring at end | 34 // Substring at end |
35 {"string", "ring"}, | 35 {"string", "ring"}, |
36 {"string", "ring$"}, | 36 {"string", "ring$"}, |
37 // Case-insensitive | 37 // Case-insensitive |
38 {"StRiNg", "string"}, | 38 {"StRiNg", "string"}, |
39 }; | 39 }; |
40 for (const auto& test_case : kPositiveCases) { | 40 for (size_t i = 0; i < arraysize(kPositiveCases); ++i) { |
| 41 const TestCase& test_case = kPositiveCases[i]; |
41 SCOPED_TRACE(test_case.input); | 42 SCOPED_TRACE(test_case.input); |
42 SCOPED_TRACE(test_case.pattern); | 43 SCOPED_TRACE(test_case.pattern); |
43 EXPECT_TRUE(MatchesPattern(ASCIIToUTF16(test_case.input), | 44 EXPECT_TRUE(MatchesPattern(ASCIIToUTF16(test_case.input), |
44 ASCIIToUTF16(test_case.pattern))); | 45 ASCIIToUTF16(test_case.pattern))); |
45 } | 46 } |
46 | 47 |
47 const TestCase kNegativeCases[] = { | 48 const TestCase kNegativeCases[] = { |
48 // Empty string | 49 // Empty string |
49 {"", "Look, ma' -- a non-empty pattern!"}, | 50 {"", "Look, ma' -- a non-empty pattern!"}, |
50 // Substring | 51 // Substring |
51 {"string", "trn"}, | 52 {"string", "trn"}, |
52 // Substring at beginning | 53 // Substring at beginning |
53 {"string", " str"}, | 54 {"string", " str"}, |
54 {"string", "^tri"}, | 55 {"string", "^tri"}, |
55 // Substring at end | 56 // Substring at end |
56 {"string", "ring "}, | 57 {"string", "ring "}, |
57 {"string", "rin$"}, | 58 {"string", "rin$"}, |
58 }; | 59 }; |
59 for (const auto& test_case : kNegativeCases) { | 60 for (size_t i = 0; i < arraysize(kNegativeCases); ++i) { |
| 61 const TestCase& test_case = kNegativeCases[i]; |
60 SCOPED_TRACE(test_case.input); | 62 SCOPED_TRACE(test_case.input); |
61 SCOPED_TRACE(test_case.pattern); | 63 SCOPED_TRACE(test_case.pattern); |
62 EXPECT_FALSE(MatchesPattern(ASCIIToUTF16(test_case.input), | 64 EXPECT_FALSE(MatchesPattern(ASCIIToUTF16(test_case.input), |
63 ASCIIToUTF16(test_case.pattern))); | 65 ASCIIToUTF16(test_case.pattern))); |
64 } | 66 } |
65 } | 67 } |
66 | 68 |
67 TEST(AutofillRegexesTest, ExpirationDate2DigitYearRegexes) { | 69 TEST(AutofillRegexesTest, ExpirationDate2DigitYearRegexes) { |
68 struct TestCase { | 70 struct TestCase { |
69 const char* const input; | 71 const char* const input; |
(...skipping 18 matching lines...) Expand all Loading... |
88 {"Expiration Date (MM - YY)"}, | 90 {"Expiration Date (MM - YY)"}, |
89 {"Expiration Date (MM-YY)"}, | 91 {"Expiration Date (MM-YY)"}, |
90 {"Expiration Date MM / YY"}, | 92 {"Expiration Date MM / YY"}, |
91 {"Expiration Date MM/YY"}, | 93 {"Expiration Date MM/YY"}, |
92 {"Expiration Date MM - YY"}, | 94 {"Expiration Date MM - YY"}, |
93 {"Expiration Date MM-YY"}, | 95 {"Expiration Date MM-YY"}, |
94 {"expiration date yy"}, | 96 {"expiration date yy"}, |
95 {"Exp Date (MM / YY)"}, | 97 {"Exp Date (MM / YY)"}, |
96 }; | 98 }; |
97 | 99 |
98 for (const auto& test_case : kPositiveCases) { | 100 for (size_t i = 0; i < arraysize(kPositiveCases); ++i) { |
| 101 const TestCase& test_case = kPositiveCases[i]; |
99 SCOPED_TRACE(test_case.input); | 102 SCOPED_TRACE(test_case.input); |
100 EXPECT_TRUE(MatchesPattern(ASCIIToUTF16(test_case.input),pattern)); | 103 EXPECT_TRUE(MatchesPattern(ASCIIToUTF16(test_case.input),pattern)); |
101 } | 104 } |
102 | 105 |
103 const TestCase kNegativeCases[] = { | 106 const TestCase kNegativeCases[] = { |
104 {""}, | 107 {""}, |
105 {"Look, ma' -- an invalid string!"}, | 108 {"Look, ma' -- an invalid string!"}, |
106 {"mmfavouritewordyy"}, | 109 {"mmfavouritewordyy"}, |
107 {"mm a yy"}, | 110 {"mm a yy"}, |
108 {"mm a yyyy"}, | 111 {"mm a yyyy"}, |
(...skipping 13 matching lines...) Expand all Loading... |
122 {"Expiration Date (MM - YYYY)"}, | 125 {"Expiration Date (MM - YYYY)"}, |
123 {"Expiration Date (MM-YYYY)"}, | 126 {"Expiration Date (MM-YYYY)"}, |
124 {"Expiration Date MM / YYYY"}, | 127 {"Expiration Date MM / YYYY"}, |
125 {"Expiration Date MM/YYYY"}, | 128 {"Expiration Date MM/YYYY"}, |
126 {"Expiration Date MM - YYYY"}, | 129 {"Expiration Date MM - YYYY"}, |
127 {"Expiration Date MM-YYYY"}, | 130 {"Expiration Date MM-YYYY"}, |
128 {"expiration date yyyy"}, | 131 {"expiration date yyyy"}, |
129 {"Exp Date (MM / YYYY)"}, | 132 {"Exp Date (MM / YYYY)"}, |
130 }; | 133 }; |
131 | 134 |
132 for (const auto& test_case : kNegativeCases) { | 135 for (size_t i = 0; i < arraysize(kNegativeCases); ++i) { |
| 136 const TestCase& test_case = kNegativeCases[i]; |
133 SCOPED_TRACE(test_case.input); | 137 SCOPED_TRACE(test_case.input); |
134 EXPECT_FALSE(MatchesPattern(ASCIIToUTF16(test_case.input), pattern)); | 138 EXPECT_FALSE(MatchesPattern(ASCIIToUTF16(test_case.input), pattern)); |
135 } | 139 } |
136 } | 140 } |
137 | 141 |
138 TEST(AutofillRegexesTest, ExpirationDate4DigitYearRegexes) { | 142 TEST(AutofillRegexesTest, ExpirationDate4DigitYearRegexes) { |
139 struct TestCase { | 143 struct TestCase { |
140 const char* const input; | 144 const char* const input; |
141 }; | 145 }; |
142 | 146 |
(...skipping 16 matching lines...) Expand all Loading... |
159 {"Expiration Date (MM - YYYY)"}, | 163 {"Expiration Date (MM - YYYY)"}, |
160 {"Expiration Date (MM-YYYY)"}, | 164 {"Expiration Date (MM-YYYY)"}, |
161 {"Expiration Date MM / YYYY"}, | 165 {"Expiration Date MM / YYYY"}, |
162 {"Expiration Date MM/YYYY"}, | 166 {"Expiration Date MM/YYYY"}, |
163 {"Expiration Date MM - YYYY"}, | 167 {"Expiration Date MM - YYYY"}, |
164 {"Expiration Date MM-YYYY"}, | 168 {"Expiration Date MM-YYYY"}, |
165 {"expiration date yyyy"}, | 169 {"expiration date yyyy"}, |
166 {"Exp Date (MM / YYYY)"}, | 170 {"Exp Date (MM / YYYY)"}, |
167 }; | 171 }; |
168 | 172 |
169 for (const auto& test_case : kPositiveCases) { | 173 for (size_t i = 0; i < arraysize(kPositiveCases); ++i) { |
| 174 const TestCase& test_case = kPositiveCases[i]; |
170 SCOPED_TRACE(test_case.input); | 175 SCOPED_TRACE(test_case.input); |
171 EXPECT_TRUE(MatchesPattern(ASCIIToUTF16(test_case.input),pattern)); | 176 EXPECT_TRUE(MatchesPattern(ASCIIToUTF16(test_case.input),pattern)); |
172 } | 177 } |
173 | 178 |
174 const TestCase kNegativeCases[] = { | 179 const TestCase kNegativeCases[] = { |
175 {""}, | 180 {""}, |
176 {"Look, ma' -- an invalid string!"}, | 181 {"Look, ma' -- an invalid string!"}, |
177 {"mmfavouritewordyy"}, | 182 {"mmfavouritewordyy"}, |
178 {"mm a yy"}, | 183 {"mm a yy"}, |
179 {"mm a yyyy"}, | 184 {"mm a yyyy"}, |
(...skipping 13 matching lines...) Expand all Loading... |
193 {"Expiration Date (MM - YY)"}, | 198 {"Expiration Date (MM - YY)"}, |
194 {"Expiration Date (MM-YY)"}, | 199 {"Expiration Date (MM-YY)"}, |
195 {"Expiration Date MM / YY"}, | 200 {"Expiration Date MM / YY"}, |
196 {"Expiration Date MM/YY"}, | 201 {"Expiration Date MM/YY"}, |
197 {"Expiration Date MM - YY"}, | 202 {"Expiration Date MM - YY"}, |
198 {"Expiration Date MM-YY"}, | 203 {"Expiration Date MM-YY"}, |
199 {"expiration date yy"}, | 204 {"expiration date yy"}, |
200 {"Exp Date (MM / YY)"}, | 205 {"Exp Date (MM / YY)"}, |
201 }; | 206 }; |
202 | 207 |
203 for (const auto& test_case : kNegativeCases) { | 208 for (size_t i = 0; i < arraysize(kNegativeCases); ++i) { |
| 209 const TestCase& test_case = kNegativeCases[i]; |
204 SCOPED_TRACE(test_case.input); | 210 SCOPED_TRACE(test_case.input); |
205 EXPECT_FALSE(MatchesPattern(ASCIIToUTF16(test_case.input), pattern)); | 211 EXPECT_FALSE(MatchesPattern(ASCIIToUTF16(test_case.input), pattern)); |
206 } | 212 } |
207 } | 213 } |
208 | 214 |
209 } // namespace autofill | 215 } // namespace autofill |
OLD | NEW |