Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: tools/gn/parse_tree_unittest.cc

Issue 1007963003: Fixes to {} handling in GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/functions_unittest.cc ('k') | tools/gn/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/input_file.h" 6 #include "tools/gn/input_file.h"
7 #include "tools/gn/parse_tree.h" 7 #include "tools/gn/parse_tree.h"
8 #include "tools/gn/scope.h" 8 #include "tools/gn/scope.h"
9 #include "tools/gn/test_with_scope.h" 9 #include "tools/gn/test_with_scope.h"
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 result = accessor.Execute(setup.scope(), &err); 49 result = accessor.Execute(setup.scope(), &err);
50 EXPECT_FALSE(err.has_error()); 50 EXPECT_FALSE(err.has_error());
51 ASSERT_EQ(Value::INTEGER, result.type()); 51 ASSERT_EQ(Value::INTEGER, result.type());
52 EXPECT_EQ(kBValue, result.int_value()); 52 EXPECT_EQ(kBValue, result.int_value());
53 } 53 }
54 54
55 TEST(ParseTree, BlockUnusedVars) { 55 TEST(ParseTree, BlockUnusedVars) {
56 TestWithScope setup; 56 TestWithScope setup;
57 57
58 // Printing both values should be OK. 58 // Printing both values should be OK.
59 //
60 // The crazy template definition here is a way to execute a block without
61 // defining a target. Templates require that both the target_name and the
62 // invoker be used, which is what the assertion statement inside the template
63 // does.
59 TestParseInput input_all_used( 64 TestParseInput input_all_used(
60 "{\n" 65 "template(\"foo\") { assert(target_name != 0 && invoker != 0) }\n"
66 "foo(\"a\") {\n"
61 " a = 12\n" 67 " a = 12\n"
62 " b = 13\n" 68 " b = 13\n"
63 " print(\"$a $b\")\n" 69 " print(\"$a $b\")\n"
64 "}"); 70 "}");
65 EXPECT_FALSE(input_all_used.has_error()); 71 EXPECT_FALSE(input_all_used.has_error());
66 72
67 Err err; 73 Err err;
68 input_all_used.parsed()->Execute(setup.scope(), &err); 74 input_all_used.parsed()->Execute(setup.scope(), &err);
69 EXPECT_FALSE(err.has_error()); 75 EXPECT_FALSE(err.has_error());
70 76
71 // Skipping one should throw an unused var error. 77 // Skipping one should throw an unused var error.
72 TestParseInput input_unused( 78 TestParseInput input_unused(
73 "{\n" 79 "foo(\"a\") {\n"
74 " a = 12\n" 80 " a = 12\n"
75 " b = 13\n" 81 " b = 13\n"
76 " print(\"$a\")\n" 82 " print(\"$a\")\n"
77 "}"); 83 "}");
78 EXPECT_FALSE(input_unused.has_error()); 84 EXPECT_FALSE(input_unused.has_error());
79 85
80 input_unused.parsed()->Execute(setup.scope(), &err); 86 input_unused.parsed()->Execute(setup.scope(), &err);
81 EXPECT_TRUE(err.has_error()); 87 EXPECT_TRUE(err.has_error());
82 88
83 // Also verify that the unused variable has the correct origin set. The 89 // Also verify that the unused variable has the correct origin set. The
84 // origin will point to the value assigned to the variable (in this case, the 90 // origin will point to the value assigned to the variable (in this case, the
85 // "13" assigned to "b". 91 // "13" assigned to "b".
86 EXPECT_EQ(3, err.location().line_number()); 92 EXPECT_EQ(3, err.location().line_number());
87 EXPECT_EQ(7, err.location().char_offset()); 93 EXPECT_EQ(7, err.location().char_offset());
88
89 } 94 }
90 95
91 TEST(ParseTree, OriginForDereference) { 96 TEST(ParseTree, OriginForDereference) {
92 TestWithScope setup; 97 TestWithScope setup;
93 TestParseInput input( 98 TestParseInput input(
94 "a = 6\n" 99 "a = 6\n"
95 "get_target_outputs(a)"); 100 "get_target_outputs(a)");
96 EXPECT_FALSE(input.has_error()); 101 EXPECT_FALSE(input.has_error());
97 102
98 Err err; 103 Err err;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 input.parsed()->AsBlock()->statements()[0]->AsBinaryOp(); 205 input.parsed()->AsBlock()->statements()[0]->AsBinaryOp();
201 ASSERT_TRUE(binop->right()->AsList()); 206 ASSERT_TRUE(binop->right()->AsList());
202 const ListNode* list = binop->right()->AsList(); 207 const ListNode* list = binop->right()->AsList();
203 EXPECT_EQ(3u, list->contents().size()); 208 EXPECT_EQ(3u, list->contents().size());
204 auto ranges = list->GetSortRanges(); 209 auto ranges = list->GetSortRanges();
205 ASSERT_EQ(1u, ranges.size()); 210 ASSERT_EQ(1u, ranges.size());
206 EXPECT_EQ(1u, ranges[0].begin); 211 EXPECT_EQ(1u, ranges[0].begin);
207 EXPECT_EQ(3u, ranges[0].end); 212 EXPECT_EQ(3u, ranges[0].end);
208 } 213 }
209 } 214 }
OLDNEW
« no previous file with comments | « tools/gn/functions_unittest.cc ('k') | tools/gn/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698