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