cc: Ensure to return pending now before active eventually tiles.
[chromium-blink-merge.git] / tools / gn / visibility_unittest.cc
blob8be2db67facbcc6683806c5f730904e7bf4430a8
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(NULL, Value::LIST);
13 list.list_value().push_back(Value(NULL, "//rec/*")); // Recursive.
14 list.list_value().push_back(Value(NULL, "//dir:*")); // One dir.
15 list.list_value().push_back(Value(NULL, "//my:name")); // Exact match.
17 Err err;
18 Visibility vis;
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) {
34 Err err;
35 Visibility vis;
37 Value list(NULL, Value::LIST);
38 list.list_value().push_back(Value(NULL, "*"));
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) {
46 Err err;
47 Visibility vis;
48 ASSERT_TRUE(vis.Set(SourceDir("//"), Value(NULL, Value::LIST), &err));
50 EXPECT_FALSE(vis.CanSeeMe(Label(SourceDir("//random/"), "thing")));
51 EXPECT_FALSE(vis.CanSeeMe(Label(SourceDir("//"), "")));