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 "base/strings/string16.h" | 7 #include "base/macros.h" |
8 #include "base/strings/utf_string_conversions.h" | |
9 #include "components/autofill/core/browser/autofill_regex_constants.h" | 8 #include "components/autofill/core/browser/autofill_regex_constants.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
11 | 10 |
12 using base::ASCIIToUTF16; | |
13 | |
14 namespace autofill { | 11 namespace autofill { |
15 | 12 |
16 TEST(AutofillRegexesTest, AutofillRegexes) { | 13 TEST(AutofillRegexesTest, AutofillRegexes) { |
17 struct TestCase { | 14 struct TestCase { |
18 const char* const input; | 15 const char* const input; |
19 const char* const pattern; | 16 const char* const pattern; |
20 }; | 17 }; |
21 | 18 |
22 const TestCase kPositiveCases[] = { | 19 const TestCase kPositiveCases[] = { |
23 // Empty pattern | 20 // Empty pattern |
24 {"", ""}, | 21 {"", ""}, |
25 {"Look, ma' -- a non-empty string!", ""}, | 22 {"Look, ma' -- a non-empty string!", ""}, |
26 // Substring | 23 // Substring |
27 {"string", "tri"}, | 24 {"string", "tri"}, |
28 // Substring at beginning | 25 // Substring at beginning |
29 {"string", "str"}, | 26 {"string", "str"}, |
30 {"string", "^str"}, | 27 {"string", "^str"}, |
31 // Substring at end | 28 // Substring at end |
32 {"string", "ring"}, | 29 {"string", "ring"}, |
33 {"string", "ring$"}, | 30 {"string", "ring$"}, |
34 // Case-insensitive | 31 // Case-insensitive |
35 {"StRiNg", "string"}, | 32 {"StRiNg", "string"}, |
36 }; | 33 }; |
37 for (size_t i = 0; i < arraysize(kPositiveCases); ++i) { | 34 for (size_t i = 0; i < arraysize(kPositiveCases); ++i) { |
38 const TestCase& test_case = kPositiveCases[i]; | 35 const TestCase& test_case = kPositiveCases[i]; |
39 SCOPED_TRACE(test_case.input); | 36 SCOPED_TRACE(test_case.input); |
40 SCOPED_TRACE(test_case.pattern); | 37 SCOPED_TRACE(test_case.pattern); |
41 EXPECT_TRUE(MatchesPattern(ASCIIToUTF16(test_case.input), | 38 EXPECT_TRUE(MatchesPattern(test_case.input, test_case.pattern)); |
42 ASCIIToUTF16(test_case.pattern))); | |
43 } | 39 } |
44 | 40 |
45 const TestCase kNegativeCases[] = { | 41 const TestCase kNegativeCases[] = { |
46 // Empty string | 42 // Empty string |
47 {"", "Look, ma' -- a non-empty pattern!"}, | 43 {"", "Look, ma' -- a non-empty pattern!"}, |
48 // Substring | 44 // Substring |
49 {"string", "trn"}, | 45 {"string", "trn"}, |
50 // Substring at beginning | 46 // Substring at beginning |
51 {"string", " str"}, | 47 {"string", " str"}, |
52 {"string", "^tri"}, | 48 {"string", "^tri"}, |
53 // Substring at end | 49 // Substring at end |
54 {"string", "ring "}, | 50 {"string", "ring "}, |
55 {"string", "rin$"}, | 51 {"string", "rin$"}, |
56 }; | 52 }; |
57 for (size_t i = 0; i < arraysize(kNegativeCases); ++i) { | 53 for (size_t i = 0; i < arraysize(kNegativeCases); ++i) { |
58 const TestCase& test_case = kNegativeCases[i]; | 54 const TestCase& test_case = kNegativeCases[i]; |
59 SCOPED_TRACE(test_case.input); | 55 SCOPED_TRACE(test_case.input); |
60 SCOPED_TRACE(test_case.pattern); | 56 SCOPED_TRACE(test_case.pattern); |
61 EXPECT_FALSE(MatchesPattern(ASCIIToUTF16(test_case.input), | 57 EXPECT_FALSE(MatchesPattern(test_case.input, test_case.pattern)); |
62 ASCIIToUTF16(test_case.pattern))); | |
63 } | 58 } |
64 } | 59 } |
65 | 60 |
66 } // namespace autofill | 61 } // namespace autofill |
OLD | NEW |