blob: fe6a6b39420ba808f6c7ec22406293432f3fb2e7 [file] [log] [blame]
[email protected]0dc7e872012-10-30 22:49:111// 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
[email protected]e4b2fa32013-03-09 22:56:565#include "components/autofill/browser/autofill_regexes.h"
[email protected]0dc7e872012-10-30 22:49:116
7#include "base/string16.h"
8#include "base/utf_string_conversions.h"
[email protected]e4b2fa32013-03-09 22:56:569#include "components/autofill/browser/autofill_regex_constants.h"
[email protected]0dc7e872012-10-30 22:49:1110#include "testing/gtest/include/gtest/gtest.h"
11
[email protected]e217c5632013-04-12 19:11:4812namespace autofill {
13
[email protected]0dc7e872012-10-30 22:49:1114TEST(AutofillRegexesTest, AutofillRegexes) {
15 struct TestCase {
16 const char* const input;
17 const char* const pattern;
18 };
19
20 const TestCase kPositiveCases[] = {
21 // Empty pattern
22 {"", ""},
23 {"Look, ma' -- a non-empty string!", ""},
24 // Substring
25 {"string", "tri"},
26 // Substring at beginning
27 {"string", "str"},
28 {"string", "^str"},
29 // Substring at end
30 {"string", "ring"},
31 {"string", "ring$"},
32 // Case-insensitive
33 {"StRiNg", "string"},
34 };
35 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPositiveCases); ++i) {
36 const TestCase& test_case = kPositiveCases[i];
37 SCOPED_TRACE(test_case.input);
38 SCOPED_TRACE(test_case.pattern);
39 EXPECT_TRUE(autofill::MatchesPattern(ASCIIToUTF16(test_case.input),
40 ASCIIToUTF16(test_case.pattern)));
41 }
42
43 const TestCase kNegativeCases[] = {
44 // Empty string
45 {"", "Look, ma' -- a non-empty pattern!"},
46 // Substring
47 {"string", "trn"},
48 // Substring at beginning
49 {"string", " str"},
50 {"string", "^tri"},
51 // Substring at end
52 {"string", "ring "},
53 {"string", "rin$"},
54 };
55 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kNegativeCases); ++i) {
56 const TestCase& test_case = kNegativeCases[i];
57 SCOPED_TRACE(test_case.input);
58 SCOPED_TRACE(test_case.pattern);
59 EXPECT_FALSE(autofill::MatchesPattern(ASCIIToUTF16(test_case.input),
60 ASCIIToUTF16(test_case.pattern)));
61 }
62}
[email protected]e217c5632013-04-12 19:11:4863
64} // namespace autofill