OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "tools/gn/operators.h" | 5 #include "tools/gn/operators.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 // The "var" variable should have been updated. Both instances of "foo" are | 230 // The "var" variable should have been updated. Both instances of "foo" are |
231 // deleted. | 231 // deleted. |
232 const Value* new_value = setup.scope()->GetValue(var); | 232 const Value* new_value = setup.scope()->GetValue(var); |
233 ASSERT_TRUE(new_value); | 233 ASSERT_TRUE(new_value); |
234 ASSERT_EQ(Value::LIST, new_value->type()); | 234 ASSERT_EQ(Value::LIST, new_value->type()); |
235 ASSERT_EQ(1u, new_value->list_value().size()); | 235 ASSERT_EQ(1u, new_value->list_value().size()); |
236 ASSERT_EQ(Value::STRING, new_value->list_value()[0].type()); | 236 ASSERT_EQ(Value::STRING, new_value->list_value()[0].type()); |
237 EXPECT_EQ("bar", new_value->list_value()[0].string_value()); | 237 EXPECT_EQ("bar", new_value->list_value()[0].string_value()); |
238 } | 238 } |
239 | 239 |
| 240 TEST(Operators, IntegerAdd) { |
| 241 Err err; |
| 242 TestWithScope setup; |
| 243 |
| 244 TestBinaryOpNode node(Token::PLUS, "+"); |
| 245 node.SetLeftToValue(Value(nullptr, static_cast<int64_t>(123))); |
| 246 node.SetRightToValue(Value(nullptr, static_cast<int64_t>(456))); |
| 247 Value ret = ExecuteBinaryOperator(setup.scope(), &node, node.left(), |
| 248 node.right(), &err); |
| 249 ASSERT_FALSE(err.has_error()); |
| 250 ASSERT_EQ(Value::INTEGER, ret.type()); |
| 251 EXPECT_EQ(579, ret.int_value()); |
| 252 } |
| 253 |
| 254 TEST(Operators, IntegerSubtract) { |
| 255 Err err; |
| 256 TestWithScope setup; |
| 257 |
| 258 TestBinaryOpNode node(Token::MINUS, "-"); |
| 259 node.SetLeftToValue(Value(nullptr, static_cast<int64_t>(123))); |
| 260 node.SetRightToValue(Value(nullptr, static_cast<int64_t>(456))); |
| 261 Value ret = ExecuteBinaryOperator(setup.scope(), &node, node.left(), |
| 262 node.right(), &err); |
| 263 ASSERT_FALSE(err.has_error()); |
| 264 ASSERT_EQ(Value::INTEGER, ret.type()); |
| 265 EXPECT_EQ(-333, ret.int_value()); |
| 266 } |
| 267 |
240 TEST(Operators, ShortCircuitAnd) { | 268 TEST(Operators, ShortCircuitAnd) { |
241 Err err; | 269 Err err; |
242 TestWithScope setup; | 270 TestWithScope setup; |
243 | 271 |
244 // Set a && operator with the left to false. | 272 // Set a && operator with the left to false. |
245 TestBinaryOpNode node(Token::BOOLEAN_AND, "&&"); | 273 TestBinaryOpNode node(Token::BOOLEAN_AND, "&&"); |
246 node.SetLeftToValue(Value(nullptr, false)); | 274 node.SetLeftToValue(Value(nullptr, false)); |
247 | 275 |
248 // Set right as foo, but don't define a value for it. | 276 // Set right as foo, but don't define a value for it. |
249 const char foo[] = "foo"; | 277 const char foo[] = "foo"; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 TestBinaryOpNode node(Token::PLUS_EQUALS, "+="); | 382 TestBinaryOpNode node(Token::PLUS_EQUALS, "+="); |
355 node.SetLeftToIdentifier(foo); | 383 node.SetLeftToIdentifier(foo); |
356 node.SetRightToValue(Value(nullptr, static_cast<int64_t>(1))); | 384 node.SetRightToValue(Value(nullptr, static_cast<int64_t>(1))); |
357 node.Execute(&nested, &err); | 385 node.Execute(&nested, &err); |
358 ASSERT_FALSE(err.has_error()); | 386 ASSERT_FALSE(err.has_error()); |
359 | 387 |
360 // Outer foo should be used, inner foo should not be. | 388 // Outer foo should be used, inner foo should not be. |
361 EXPECT_FALSE(setup.scope()->IsSetButUnused(foo)); | 389 EXPECT_FALSE(setup.scope()->IsSetButUnused(foo)); |
362 EXPECT_TRUE(nested.IsSetButUnused(foo)); | 390 EXPECT_TRUE(nested.IsSetButUnused(foo)); |
363 } | 391 } |
OLD | NEW |