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.h"
8 #include "tools/gn/value.h"
9 #include "tools/gn/visibility.h"
11 TEST(Visibility
, CanSeeMe
) {
12 Value
list(nullptr, Value::LIST
);
13 list
.list_value().push_back(Value(nullptr, "//rec/*")); // Recursive.
14 list
.list_value().push_back(Value(nullptr, "//dir:*")); // One dir.
15 list
.list_value().push_back(Value(nullptr, "//my:name")); // Exact match.
19 ASSERT_TRUE(vis
.Set(SourceDir("//"), list
, &err
));
21 EXPECT_FALSE(vis
.CanSeeMe(Label(SourceDir("//random/"), "thing")));
22 EXPECT_FALSE(vis
.CanSeeMe(Label(SourceDir("//my/"), "notname")));
24 EXPECT_TRUE(vis
.CanSeeMe(Label(SourceDir("//my/"), "name")));
25 EXPECT_TRUE(vis
.CanSeeMe(Label(SourceDir("//rec/"), "anything")));
26 EXPECT_TRUE(vis
.CanSeeMe(Label(SourceDir("//rec/a/"), "anything")));
27 EXPECT_TRUE(vis
.CanSeeMe(Label(SourceDir("//rec/b/"), "anything")));
28 EXPECT_TRUE(vis
.CanSeeMe(Label(SourceDir("//dir/"), "anything")));
29 EXPECT_FALSE(vis
.CanSeeMe(Label(SourceDir("//dir/a/"), "anything")));
30 EXPECT_FALSE(vis
.CanSeeMe(Label(SourceDir("//directory/"), "anything")));
33 TEST(Visibility
, Public
) {
37 Value
list(nullptr, Value::LIST
);
38 list
.list_value().push_back(Value(nullptr, "*"));
39 ASSERT_TRUE(vis
.Set(SourceDir("//"), list
, &err
));
41 EXPECT_TRUE(vis
.CanSeeMe(Label(SourceDir("//random/"), "thing")));
42 EXPECT_TRUE(vis
.CanSeeMe(Label(SourceDir("//"), "")));
45 TEST(Visibility
, Private
) {
48 ASSERT_TRUE(vis
.Set(SourceDir("//"), Value(nullptr, Value::LIST
), &err
));
50 EXPECT_FALSE(vis
.CanSeeMe(Label(SourceDir("//random/"), "thing")));
51 EXPECT_FALSE(vis
.CanSeeMe(Label(SourceDir("//"), "")));