summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/autofill_regexes_unittest.cc
blob: 5f3254e7c17c5776a446fa176f41669ea4b942fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/autofill/autofill_regexes.h"

#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autofill/autofill_regex_constants.h"
#include "testing/gtest/include/gtest/gtest.h"

TEST(AutofillRegexesTest, AutofillRegexes) {
  struct TestCase {
    const char* const input;
    const char* const pattern;
  };

  const TestCase kPositiveCases[] = {
    // Empty pattern
    {"", ""},
    {"Look, ma' -- a non-empty string!", ""},
    // Substring
    {"string", "tri"},
    // Substring at beginning
    {"string", "str"},
    {"string", "^str"},
    // Substring at end
    {"string", "ring"},
    {"string", "ring$"},
    // Case-insensitive
    {"StRiNg", "string"},
  };
  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPositiveCases); ++i) {
    const TestCase& test_case = kPositiveCases[i];
    SCOPED_TRACE(test_case.input);
    SCOPED_TRACE(test_case.pattern);
    EXPECT_TRUE(autofill::MatchesPattern(ASCIIToUTF16(test_case.input),
                                         ASCIIToUTF16(test_case.pattern)));
  }

  const TestCase kNegativeCases[] = {
    // Empty string
    {"", "Look, ma' -- a non-empty pattern!"},
    // Substring
    {"string", "trn"},
    // Substring at beginning
    {"string", " str"},
    {"string", "^tri"},
    // Substring at end
    {"string", "ring "},
    {"string", "rin$"},
  };
  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kNegativeCases); ++i) {
    const TestCase& test_case = kNegativeCases[i];
    SCOPED_TRACE(test_case.input);
    SCOPED_TRACE(test_case.pattern);
    EXPECT_FALSE(autofill::MatchesPattern(ASCIIToUTF16(test_case.input),
                                          ASCIIToUTF16(test_case.pattern)));
  }
}