Remove no longer needed toolbar layer method.
[chromium-blink-merge.git] / tools / gn / label_pattern_unittest.cc
blob9cd5de01f5d77f1e169751868ff5ce7f31d41792
1 // Copyright 2014 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/err.h"
7 #include "tools/gn/label_pattern.h"
8 #include "tools/gn/value.h"
10 namespace {
12 struct PatternCase {
13 const char* input;
14 bool success;
16 LabelPattern::Type type;
17 const char* dir;
18 const char* name;
19 const char* toolchain;
22 } // namespace
24 TEST(LabelPattern, PatternParse) {
25 SourceDir current_dir("//foo/");
26 PatternCase cases[] = {
27 // Missing stuff.
28 { "", false, LabelPattern::MATCH, "", "", "" },
29 { ":", false, LabelPattern::MATCH, "", "", "" },
30 // Normal things.
31 { ":bar", true, LabelPattern::MATCH, "//foo/", "bar", "" },
32 { "//la:bar", true, LabelPattern::MATCH, "//la/", "bar", "" },
33 { "*", true, LabelPattern::RECURSIVE_DIRECTORY, "", "", "" },
34 { ":*", true, LabelPattern::DIRECTORY, "//foo/", "", "" },
35 { "la:*", true, LabelPattern::DIRECTORY, "//foo/la/", "", "" },
36 { "la/*:*", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/la/", "", "" },
37 { "//la:*", true, LabelPattern::DIRECTORY, "//la/", "", "" },
38 { "./*", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/", "", "" },
39 { "foo/*", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/foo/", "", "" },
40 { "//l/*", true, LabelPattern::RECURSIVE_DIRECTORY, "//l/", "", "" },
41 // Toolchains.
42 { "//foo()", true, LabelPattern::MATCH, "//foo/", "foo", "" },
43 { "//foo(//bar)", true, LabelPattern::MATCH, "//foo/", "foo", "//bar:bar" },
44 { "//foo:*(//bar)", true, LabelPattern::DIRECTORY, "//foo/", "",
45 "//bar:bar" },
46 { "//foo/*(//bar)", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/", "",
47 "//bar:bar" },
48 // Wildcards in invalid places.
49 { "*foo*:bar", false, LabelPattern::MATCH, "", "", "" },
50 { "foo*:*bar", false, LabelPattern::MATCH, "", "", "" },
51 { "*foo:bar", false, LabelPattern::MATCH, "", "", "" },
52 { "foo:bar*", false, LabelPattern::MATCH, "", "", "" },
53 { "*:*", true, LabelPattern::RECURSIVE_DIRECTORY, "", "", "" },
54 // Invalid toolchain stuff.
55 { "//foo(//foo/bar:*)", false, LabelPattern::MATCH, "", "", "" },
56 { "//foo/*(*)", false, LabelPattern::MATCH, "", "", "" },
57 { "//foo(//bar", false, LabelPattern::MATCH, "", "", "" },
60 for (size_t i = 0; i < arraysize(cases); i++) {
61 const PatternCase& cur = cases[i];
62 Err err;
63 LabelPattern result =
64 LabelPattern::GetPattern(current_dir, Value(nullptr, cur.input), &err);
66 EXPECT_EQ(cur.success, !err.has_error()) << i << " " << cur.input;
67 EXPECT_EQ(cur.type, result.type()) << i << " " << cur.input;
68 EXPECT_EQ(cur.dir, result.dir().value()) << i << " " << cur.input;
69 EXPECT_EQ(cur.name, result.name()) << i << " " << cur.input;
70 EXPECT_EQ(cur.toolchain, result.toolchain().GetUserVisibleName(false))
71 << i << " " << cur.input;