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.
4
5 #include <stddef.h>
6
7 #include "gn/commands.h"
8 #include "gn/label_pattern.h"
9 #include "gn/target.h"
10 #include "gn/test_with_scope.h"
11 #include "util/test/test.h"
12
TEST(Commands,FilterOutMatch)13 TEST(Commands, FilterOutMatch) {
14 TestWithScope setup;
15 SourceDir current_dir("//");
16
17 Target target_afoo(setup.settings(), Label(SourceDir("//a/"), "foo"));
18 Target target_cbar(setup.settings(), Label(SourceDir("//c/"), "bar"));
19 std::vector<const Target*> targets{&target_afoo, &target_cbar};
20
21 Err err;
22 LabelPattern pattern_a = LabelPattern::GetPattern(
23 current_dir, std::string_view(), Value(nullptr, "//a:*"), &err);
24 EXPECT_FALSE(err.has_error());
25 LabelPattern pattern_ef = LabelPattern::GetPattern(
26 current_dir, std::string_view(), Value(nullptr, "//e:f"), &err);
27 EXPECT_FALSE(err.has_error());
28 std::vector<LabelPattern> label_patterns{pattern_a, pattern_ef};
29
30 std::vector<const Target*> output;
31 commands::FilterOutTargetsByPatterns(targets, label_patterns, &output);
32
33 EXPECT_EQ(1, output.size());
34 EXPECT_EQ(&target_cbar, output[0]);
35 }
36