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

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: Replace "auto" with "base::StringPiece" 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
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 const char *good[] = {
218 "0",
219 "10",
220 "-54321",
221 "9223372036854775807",
222 "-9223372036854775808",
223 };
224
225 const char *bad[] = {
brettw 2015/03/31 23:05:33 I think it would be better to move this to right a
mdempsky 2015/03/31 23:19:20 Done.
226 "-0",
227 "010",
228 "-010",
229 "9223372036854775808",
230 "-9223372036854775809",
231 };
232
233 for (auto s : good) {
234 TestParseInput input(std::string("x = ") + s);
235 EXPECT_FALSE(input.has_error());
236
237 TestWithScope setup;
238 Err err;
239 input.parsed()->Execute(setup.scope(), &err);
240 EXPECT_FALSE(err.has_error());
241 }
242
243 for (auto s : bad) {
244 TestParseInput input(std::string("x = ") + s);
245 EXPECT_FALSE(input.has_error());
246
247 TestWithScope setup;
248 Err err;
249 input.parsed()->Execute(setup.scope(), &err);
250 EXPECT_TRUE(err.has_error());
251 }
252 }
OLDNEW
« tools/gn/parse_tree.cc ('K') | « 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