Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Unified Diff: tools/gn/pattern_unittest.cc

Issue 21114002: Add initial prototype for the GN meta-buildsystem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add owners and readme Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/pattern.cc ('k') | tools/gn/scheduler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/pattern_unittest.cc
diff --git a/tools/gn/pattern_unittest.cc b/tools/gn/pattern_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e9ffea6c35f5cdedf674cecb2617e5ecd5bfc268
--- /dev/null
+++ b/tools/gn/pattern_unittest.cc
@@ -0,0 +1,61 @@
+// Copyright (c) 2013 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 "testing/gtest/include/gtest/gtest.h"
+#include "tools/gn/pattern.h"
+
+namespace {
+
+struct Case {
+ const char* pattern;
+ const char* candidate;
+ bool expected_match;
+};
+
+} // namespace
+
+TEST(Pattern, Matches) {
+ Case pattern_cases[] = {
+ // Empty pattern matches only empty string.
+ { "", "", true },
+ { "", "foo", false },
+ // Exact matches.
+ { "foo", "foo", true },
+ { "foo", "bar", false },
+ // Path boundaries.
+ { "\\b", "", true },
+ { "\\b", "/", true },
+ { "\\b\\b", "/", true },
+ { "\\b\\b\\b", "", false },
+ { "\\b\\b\\b", "/", true },
+ { "\\b", "//", false },
+ { "\\bfoo\\b", "foo", true },
+ { "\\bfoo\\b", "/foo/", true },
+ { "\\b\\bfoo", "/foo", true },
+ // *
+ { "*", "", true },
+ { "*", "foo", true },
+ { "*foo", "foo", true },
+ { "*foo", "gagafoo", true },
+ { "*foo", "gagafoob", false },
+ { "foo*bar", "foobar", true },
+ { "foo*bar", "foo-bar", true },
+ { "foo*bar", "foolalalalabar", true },
+ { "foo*bar", "foolalalalabaz", false },
+ { "*a*b*c*d*", "abcd", true },
+ { "*a*b*c*d*", "1a2b3c4d5", true },
+ { "*a*b*c*d*", "1a2b3c45", false },
+ { "*\\bfoo\\b*", "foo", true },
+ { "*\\bfoo\\b*", "/foo/", true },
+ { "*\\bfoo\\b*", "foob", false },
+ { "*\\bfoo\\b*", "lala/foo/bar/baz", true },
+ };
+ for (size_t i = 0; i < arraysize(pattern_cases); i++) {
+ const Case& c = pattern_cases[i];
+ Pattern pattern(c.pattern);
+ bool result = pattern.MatchesString(c.candidate);
+ EXPECT_EQ(c.expected_match, result) << i << ": \"" << c.pattern
+ << "\", \"" << c.candidate << "\"";
+ }
+}
« no previous file with comments | « tools/gn/pattern.cc ('k') | tools/gn/scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698