OLD | NEW |
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 Loading... |
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 } |
OLD | NEW |