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

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

Issue 1038233002: tools/gn: disallow non-canonical integer literals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move kBad tests down by usage Created 5 years, 8 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/parse_tree.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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 input.parsed()->AsBlock()->statements()[0]->AsBinaryOp(); 205 input.parsed()->AsBlock()->statements()[0]->AsBinaryOp();
206 ASSERT_TRUE(binop->right()->AsList()); 206 ASSERT_TRUE(binop->right()->AsList());
207 const ListNode* list = binop->right()->AsList(); 207 const ListNode* list = binop->right()->AsList();
208 EXPECT_EQ(3u, list->contents().size()); 208 EXPECT_EQ(3u, list->contents().size());
209 auto ranges = list->GetSortRanges(); 209 auto ranges = list->GetSortRanges();
210 ASSERT_EQ(1u, ranges.size()); 210 ASSERT_EQ(1u, ranges.size());
211 EXPECT_EQ(1u, ranges[0].begin); 211 EXPECT_EQ(1u, ranges[0].begin);
212 EXPECT_EQ(3u, ranges[0].end); 212 EXPECT_EQ(3u, ranges[0].end);
213 } 213 }
214 } 214 }
215
216 TEST(ParseTree, Integers) {
217 static const char* const kGood[] = {
218 "0",
219 "10",
220 "-54321",
221 "9223372036854775807", // INT64_MAX
222 "-9223372036854775808", // INT64_MIN
223 };
224 for (auto s : kGood) {
225 TestParseInput input(std::string("x = ") + s);
226 EXPECT_FALSE(input.has_error());
227
228 TestWithScope setup;
229 Err err;
230 input.parsed()->Execute(setup.scope(), &err);
231 EXPECT_FALSE(err.has_error());
232 }
233
234 static const char* const kBad[] = {
235 "-0",
236 "010",
237 "-010",
238 "9223372036854775808", // INT64_MAX + 1
239 "-9223372036854775809", // INT64_MIN - 1
240 };
241 for (auto s : kBad) {
242 TestParseInput input(std::string("x = ") + s);
243 EXPECT_FALSE(input.has_error());
244
245 TestWithScope setup;
246 Err err;
247 input.parsed()->Execute(setup.scope(), &err);
248 EXPECT_TRUE(err.has_error());
249 }
250 }
OLDNEW
« no previous file with comments | « tools/gn/parse_tree.cc ('k') | tools/gn/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698