OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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.h" | 7 #include "tools/gn/label.h" |
8 #include "tools/gn/value.h" | 8 #include "tools/gn/value.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 TEST(Label, Resolve) { | 24 TEST(Label, Resolve) { |
25 ParseDepStringCase cases[] = { | 25 ParseDepStringCase cases[] = { |
26 // cur input succ expected dir n
ame tc dir tc name | 26 // cur input succ expected dir n
ame tc dir tc name |
27 { "//chrome/", "", false, "", "
", "", "" }, | 27 { "//chrome/", "", false, "", "
", "", "" }, |
28 { "//chrome/", "/", false, "", "
", "", "" }, | 28 { "//chrome/", "/", false, "", "
", "", "" }, |
29 { "//chrome/", ":", false, "", "
", "", "" }, | 29 { "//chrome/", ":", false, "", "
", "", "" }, |
30 { "//chrome/", "/:", false, "", "
", "", "" }, | 30 { "//chrome/", "/:", false, "", "
", "", "" }, |
31 { "//chrome/", "blah", true, "//chrome/blah/", "
blah", "//t/", "d" }, | 31 { "//chrome/", "blah", true, "//chrome/blah/", "
blah", "//t/", "d" }, |
32 { "//chrome/", "blah:bar", true, "//chrome/blah/", "
bar", "//t/", "d" }, | 32 { "//chrome/", "blah:bar", true, "//chrome/blah/", "
bar", "//t/", "d" }, |
33 // No single-leading slash. | 33 // Absolute paths. |
34 { "//chrome/", "/chrome:bar", false, "", "
", "", "" }, | 34 { "//chrome/", "/chrome:bar", true , "/chrome/", "
bar", "//t/", "d" }, |
35 // No trailing slash. | 35 { "//chrome/", "/chrome/:bar", true, "/chrome/", "
bar", "//t/", "d" }, |
36 { "//chrome/", "/chrome/:bar", false, "", "
", "", "" }, | |
37 // Refers to root dir. | 36 // Refers to root dir. |
38 { "//chrome/", "//:bar", true, "//", "
bar", "//t/", "d" }, | 37 { "//chrome/", "//:bar", true, "//", "
bar", "//t/", "d" }, |
39 // Implicit directory | 38 // Implicit directory |
40 { "//chrome/", ":bar", true, "//chrome/", "
bar", "//t/", "d" }, | 39 { "//chrome/", ":bar", true, "//chrome/", "
bar", "//t/", "d" }, |
41 { "//chrome/renderer/", ":bar", true, "//chrome/renderer/", "
bar", "//t/", "d" }, | 40 { "//chrome/renderer/", ":bar", true, "//chrome/renderer/", "
bar", "//t/", "d" }, |
42 // Implicit names. | 41 // Implicit names. |
43 { "//chrome/", "//base", true, "//base/", "
base", "//t/", "d" }, | 42 { "//chrome/", "//base", true, "//base/", "
base", "//t/", "d" }, |
44 { "//chrome/", "//base/i18n", true, "//base/i18n/", "
i18n", "//t/", "d" }, | 43 { "//chrome/", "//base/i18n", true, "//base/i18n/", "
i18n", "//t/", "d" }, |
45 { "//chrome/", "//base/i18n:foo", true, "//base/i18n/", "
foo", "//t/", "d" }, | 44 { "//chrome/", "//base/i18n:foo", true, "//base/i18n/", "
foo", "//t/", "d" }, |
46 { "//chrome/", "//", false, "", "
", "", "" }, | 45 { "//chrome/", "//", false, "", "
", "", "" }, |
47 // Toolchain parsing. | 46 // Toolchain parsing. |
48 { "//chrome/", "//chrome:bar(//t:n)", true, "//chrome/", "
bar", "//t/", "n" }, | 47 { "//chrome/", "//chrome:bar(//t:n)", true, "//chrome/", "
bar", "//t/", "n" }, |
49 { "//chrome/", "//chrome:bar(//t)", true, "//chrome/", "
bar", "//t/", "t" }, | 48 { "//chrome/", "//chrome:bar(//t)", true, "//chrome/", "
bar", "//t/", "t" }, |
50 { "//chrome/", "//chrome:bar(//t:)", true, "//chrome/", "
bar", "//t/", "t" }, | 49 { "//chrome/", "//chrome:bar(//t:)", true, "//chrome/", "
bar", "//t/", "t" }, |
51 { "//chrome/", "//chrome:bar()", true, "//chrome/", "
bar", "//t/", "d" }, | 50 { "//chrome/", "//chrome:bar()", true, "//chrome/", "
bar", "//t/", "d" }, |
52 { "//chrome/", "//chrome:bar(foo)", true, "//chrome/", "
bar", "//chrome/foo/", "foo" }, | 51 { "//chrome/", "//chrome:bar(foo)", true, "//chrome/", "
bar", "//chrome/foo/", "foo" }, |
53 { "//chrome/", "//chrome:bar(:foo)", true, "//chrome/", "
bar", "//chrome/", "foo" }, | 52 { "//chrome/", "//chrome:bar(:foo)", true, "//chrome/", "
bar", "//chrome/", "foo" }, |
54 // TODO(brettw) it might be nice to make this an error: | 53 // TODO(brettw) it might be nice to make this an error: |
55 //{ "//chrome/", "//chrome:bar())", false, "",
"", "", "" }, | 54 //{ "//chrome/", "//chrome:bar())", false, "",
"", "", "" }, |
56 { "//chrome/", "//chrome:bar(//t:bar(tc))", false, "", "
", "", "" }, | 55 { "//chrome/", "//chrome:bar(//t:bar(tc))", false, "", "
", "", "" }, |
57 { "//chrome/", "//chrome:bar(()", false, "", "
", "", "" }, | 56 { "//chrome/", "//chrome:bar(()", false, "", "
", "", "" }, |
58 { "//chrome/", "(t:b)", false, "", "
", "", "" }, | 57 { "//chrome/", "(t:b)", false, "", "
", "", "" }, |
59 { "//chrome/", ":bar(//t/b)", true, "//chrome/", "
bar", "//t/b/", "b" }, | 58 { "//chrome/", ":bar(//t/b)", true, "//chrome/", "
bar", "//t/b/", "b" }, |
60 { "//chrome/", ":bar(/t/b)", false, "", "
", "", "" }, | 59 { "//chrome/", ":bar(/t/b)", true, "//chrome/", "
bar", "/t/b/", "b" }, |
61 { "//chrome/", ":bar(t/b)", true, "//chrome/", "
bar", "//chrome/t/b/", "b" }, | 60 { "//chrome/", ":bar(t/b)", true, "//chrome/", "
bar", "//chrome/t/b/", "b" }, |
62 }; | 61 }; |
63 | 62 |
64 Label default_toolchain(SourceDir("//t/"), "d"); | 63 Label default_toolchain(SourceDir("//t/"), "d"); |
65 | 64 |
66 for (size_t i = 0; i < arraysize(cases); i++) { | 65 for (size_t i = 0; i < arraysize(cases); i++) { |
67 const ParseDepStringCase& cur = cases[i]; | 66 const ParseDepStringCase& cur = cases[i]; |
68 | 67 |
69 std::string location, name; | 68 std::string location, name; |
70 Err err; | 69 Err err; |
71 Value v(nullptr, Value::STRING); | 70 Value v(nullptr, Value::STRING); |
72 v.string_value() = cur.str; | 71 v.string_value() = cur.str; |
73 Label result = | 72 Label result = |
74 Label::Resolve(SourceDir(cur.cur_dir), default_toolchain, v, &err); | 73 Label::Resolve(SourceDir(cur.cur_dir), default_toolchain, v, &err); |
75 EXPECT_EQ(cur.success, !err.has_error()) << i << " " << cur.str; | 74 EXPECT_EQ(cur.success, !err.has_error()) << i << " " << cur.str; |
76 if (!err.has_error() && cur.success) { | 75 if (!err.has_error() && cur.success) { |
77 EXPECT_EQ(cur.expected_dir, result.dir().value()) | 76 EXPECT_EQ(cur.expected_dir, result.dir().value()) |
78 << i << " " << cur.str; | 77 << i << " " << cur.str; |
79 EXPECT_EQ(cur.expected_name, result.name()) | 78 EXPECT_EQ(cur.expected_name, result.name()) |
80 << i << " " << cur.str; | 79 << i << " " << cur.str; |
81 EXPECT_EQ(cur.expected_toolchain_dir, | 80 EXPECT_EQ(cur.expected_toolchain_dir, |
82 result.toolchain_dir().value()) | 81 result.toolchain_dir().value()) |
83 << i << " " << cur.str; | 82 << i << " " << cur.str; |
84 EXPECT_EQ(cur.expected_toolchain_name, result.toolchain_name()) | 83 EXPECT_EQ(cur.expected_toolchain_name, result.toolchain_name()) |
85 << i << " " << cur.str; | 84 << i << " " << cur.str; |
86 } | 85 } |
87 } | 86 } |
88 } | 87 } |
OLD | NEW |