// Copyright (c) 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "tools/gn/scope.h" #include "testing/gtest/include/gtest/gtest.h" #include "tools/gn/input_file.h" #include "tools/gn/parse_tree.h" #include "tools/gn/source_file.h" #include "tools/gn/template.h" #include "tools/gn/test_with_scope.h" namespace { bool HasStringValueEqualTo(const Scope* scope, const char* name, const char* expected_value) { const Value* value = scope->GetValue(name); if (!value) return false; if (value->type() != Value::STRING) return false; return value->string_value() == expected_value; } bool ContainsBuildDependencyFile(const Scope* scope, const SourceFile& source_file) { const auto& build_dependency_files = scope->build_dependency_files(); return build_dependency_files.end() != build_dependency_files.find(source_file); } } // namespace TEST(Scope, InheritBuildDependencyFilesFromParent) { TestWithScope setup; SourceFile source_file = SourceFile("//a/BUILD.gn"); setup.scope()->AddBuildDependencyFile(source_file); Scope new_scope(setup.scope()); EXPECT_EQ(1U, new_scope.build_dependency_files().size()); EXPECT_TRUE(ContainsBuildDependencyFile(&new_scope, source_file)); } TEST(Scope, NonRecursiveMergeTo) { TestWithScope setup; // Make a pretend parse node with proper tracking that we can blame for the // given value. InputFile input_file(SourceFile("//foo")); Token assignment_token(Location(&input_file, 1, 1, 1), Token::STRING, "\"hello\""); LiteralNode assignment; assignment.set_value(assignment_token); // Add some values to the scope. Value old_value(&assignment, "hello"); setup.scope()->SetValue("v", old_value, &assignment); base::StringPiece private_var_name("_private"); setup.scope()->SetValue(private_var_name, old_value, &assignment); // Add some templates to the scope. FunctionCallNode templ_definition; scoped_refptr