OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "tools/gn/err.h" | 6 #include "tools/gn/err.h" |
7 #include "tools/gn/label_pattern.h" | 7 #include "tools/gn/label_pattern.h" |
8 #include "tools/gn/value.h" | 8 #include "tools/gn/value.h" |
9 | 9 |
10 namespace { | 10 namespace { |
11 | 11 |
12 struct PatternCase { | 12 struct PatternCase { |
13 const char* input; | 13 const char* input; |
14 bool success; | 14 bool success; |
15 | 15 |
16 LabelPattern::Type type; | 16 LabelPattern::Type type; |
17 const char* dir; | 17 const char* dir; |
18 const char* name; | 18 const char* name; |
19 const char* toolchain; | 19 const char* toolchain; |
20 }; | 20 }; |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 TEST(LabelPattern, PatternParse) { | 24 TEST(LabelPattern, PatternParse) { |
| 25 base::FilePath source_root("/source/root"); |
25 SourceDir current_dir("//foo/"); | 26 SourceDir current_dir("//foo/"); |
26 PatternCase cases[] = { | 27 PatternCase cases[] = { |
27 // Missing stuff. | 28 // Missing stuff. |
28 { "", false, LabelPattern::MATCH, "", "", "" }, | 29 { "", false, LabelPattern::MATCH, "", "", "" }, |
29 { ":", false, LabelPattern::MATCH, "", "", "" }, | 30 { ":", false, LabelPattern::MATCH, "", "", "" }, |
30 // Normal things. | 31 // Normal things. |
31 { ":bar", true, LabelPattern::MATCH, "//foo/", "bar", "" }, | 32 { ":bar", true, LabelPattern::MATCH, "//foo/", "bar", "" }, |
32 { "//la:bar", true, LabelPattern::MATCH, "//la/", "bar", "" }, | 33 { "//la:bar", true, LabelPattern::MATCH, "//la/", "bar", "" }, |
33 { "*", true, LabelPattern::RECURSIVE_DIRECTORY, "", "", "" }, | 34 { "*", true, LabelPattern::RECURSIVE_DIRECTORY, "", "", "" }, |
34 { ":*", true, LabelPattern::DIRECTORY, "//foo/", "", "" }, | 35 { ":*", true, LabelPattern::DIRECTORY, "//foo/", "", "" }, |
(...skipping 18 matching lines...) Expand all Loading... |
53 { "*:*", true, LabelPattern::RECURSIVE_DIRECTORY, "", "", "" }, | 54 { "*:*", true, LabelPattern::RECURSIVE_DIRECTORY, "", "", "" }, |
54 // Invalid toolchain stuff. | 55 // Invalid toolchain stuff. |
55 { "//foo(//foo/bar:*)", false, LabelPattern::MATCH, "", "", "" }, | 56 { "//foo(//foo/bar:*)", false, LabelPattern::MATCH, "", "", "" }, |
56 { "//foo/*(*)", false, LabelPattern::MATCH, "", "", "" }, | 57 { "//foo/*(*)", false, LabelPattern::MATCH, "", "", "" }, |
57 { "//foo(//bar", false, LabelPattern::MATCH, "", "", "" }, | 58 { "//foo(//bar", false, LabelPattern::MATCH, "", "", "" }, |
58 }; | 59 }; |
59 | 60 |
60 for (size_t i = 0; i < arraysize(cases); i++) { | 61 for (size_t i = 0; i < arraysize(cases); i++) { |
61 const PatternCase& cur = cases[i]; | 62 const PatternCase& cur = cases[i]; |
62 Err err; | 63 Err err; |
63 LabelPattern result = | 64 LabelPattern result = LabelPattern::GetPattern(source_root, current_dir, |
64 LabelPattern::GetPattern(current_dir, Value(NULL, cur.input), &err); | 65 Value(NULL, cur.input), |
| 66 &err); |
65 | 67 |
66 EXPECT_EQ(cur.success, !err.has_error()) << i << " " << cur.input; | 68 EXPECT_EQ(cur.success, !err.has_error()) << i << " " << cur.input; |
67 EXPECT_EQ(cur.type, result.type()) << i << " " << cur.input; | 69 EXPECT_EQ(cur.type, result.type()) << i << " " << cur.input; |
68 EXPECT_EQ(cur.dir, result.dir().value()) << i << " " << cur.input; | 70 EXPECT_EQ(cur.dir, result.dir().value()) << i << " " << cur.input; |
69 EXPECT_EQ(cur.name, result.name()) << i << " " << cur.input; | 71 EXPECT_EQ(cur.name, result.name()) << i << " " << cur.input; |
70 EXPECT_EQ(cur.toolchain, result.toolchain().GetUserVisibleName(false)) | 72 EXPECT_EQ(cur.toolchain, result.toolchain().GetUserVisibleName(false)) |
71 << i << " " << cur.input; | 73 << i << " " << cur.input; |
72 } | 74 } |
73 } | 75 } |
OLD | NEW |