Roll src/third_party/skia ff271c2:b679ca8
[chromium-blink-merge.git] / tools / gn / pattern_unittest.cc
blobe9ffea6c35f5cdedf674cecb2617e5ecd5bfc268
1 // Copyright (c) 2013 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.
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/pattern.h"
8 namespace {
10 struct Case {
11 const char* pattern;
12 const char* candidate;
13 bool expected_match;
16 } // namespace
18 TEST(Pattern, Matches) {
19 Case pattern_cases[] = {
20 // Empty pattern matches only empty string.
21 { "", "", true },
22 { "", "foo", false },
23 // Exact matches.
24 { "foo", "foo", true },
25 { "foo", "bar", false },
26 // Path boundaries.
27 { "\\b", "", true },
28 { "\\b", "/", true },
29 { "\\b\\b", "/", true },
30 { "\\b\\b\\b", "", false },
31 { "\\b\\b\\b", "/", true },
32 { "\\b", "//", false },
33 { "\\bfoo\\b", "foo", true },
34 { "\\bfoo\\b", "/foo/", true },
35 { "\\b\\bfoo", "/foo", true },
36 // *
37 { "*", "", true },
38 { "*", "foo", true },
39 { "*foo", "foo", true },
40 { "*foo", "gagafoo", true },
41 { "*foo", "gagafoob", false },
42 { "foo*bar", "foobar", true },
43 { "foo*bar", "foo-bar", true },
44 { "foo*bar", "foolalalalabar", true },
45 { "foo*bar", "foolalalalabaz", false },
46 { "*a*b*c*d*", "abcd", true },
47 { "*a*b*c*d*", "1a2b3c4d5", true },
48 { "*a*b*c*d*", "1a2b3c45", false },
49 { "*\\bfoo\\b*", "foo", true },
50 { "*\\bfoo\\b*", "/foo/", true },
51 { "*\\bfoo\\b*", "foob", false },
52 { "*\\bfoo\\b*", "lala/foo/bar/baz", true },
54 for (size_t i = 0; i < arraysize(pattern_cases); i++) {
55 const Case& c = pattern_cases[i];
56 Pattern pattern(c.pattern);
57 bool result = pattern.MatchesString(c.candidate);
58 EXPECT_EQ(c.expected_match, result) << i << ": \"" << c.pattern
59 << "\", \"" << c.candidate << "\"";