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"
12 const char* candidate
;
18 TEST(Pattern
, Matches
) {
19 Case pattern_cases
[] = {
20 // Empty pattern matches only empty string.
24 { "foo", "foo", true },
25 { "foo", "bar", false },
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 },
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
<< "\"";