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