gn: Fix integer subtraction.

Who knew that gn files even support an integer type!

Review-Url: https://codereview.chromium.org/2554083003
Cr-Original-Commit-Position: refs/heads/master@{#436677}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 4c53f32fe75ebc06a2f9184e07319acce8c9583d
diff --git a/tools/gn/operators.cc b/tools/gn/operators.cc
index 72b2dd1..350fef4 100644
--- a/tools/gn/operators.cc
+++ b/tools/gn/operators.cc
@@ -419,7 +419,7 @@
                    const Value& right,
                    Err* err) {
   // Left-hand-side int. The only thing to do is subtract another int.
-  if (left.type() == Value::INTEGER && right.type() != Value::INTEGER) {
+  if (left.type() == Value::INTEGER && right.type() == Value::INTEGER) {
     // Int - int -> subtraction.
     return Value(op_node, left.int_value() - right.int_value());
   }
diff --git a/tools/gn/operators_unittest.cc b/tools/gn/operators_unittest.cc
index fa163a1..4c9c670 100644
--- a/tools/gn/operators_unittest.cc
+++ b/tools/gn/operators_unittest.cc
@@ -237,6 +237,34 @@
   EXPECT_EQ("bar", new_value->list_value()[0].string_value());
 }
 
+TEST(Operators, IntegerAdd) {
+  Err err;
+  TestWithScope setup;
+
+  TestBinaryOpNode node(Token::PLUS, "+");
+  node.SetLeftToValue(Value(nullptr, static_cast<int64_t>(123)));
+  node.SetRightToValue(Value(nullptr, static_cast<int64_t>(456)));
+  Value ret = ExecuteBinaryOperator(setup.scope(), &node, node.left(),
+                                    node.right(), &err);
+  ASSERT_FALSE(err.has_error());
+  ASSERT_EQ(Value::INTEGER, ret.type());
+  EXPECT_EQ(579, ret.int_value());
+}
+
+TEST(Operators, IntegerSubtract) {
+  Err err;
+  TestWithScope setup;
+
+  TestBinaryOpNode node(Token::MINUS, "-");
+  node.SetLeftToValue(Value(nullptr, static_cast<int64_t>(123)));
+  node.SetRightToValue(Value(nullptr, static_cast<int64_t>(456)));
+  Value ret = ExecuteBinaryOperator(setup.scope(), &node, node.left(),
+                                    node.right(), &err);
+  ASSERT_FALSE(err.has_error());
+  ASSERT_EQ(Value::INTEGER, ret.type());
+  EXPECT_EQ(-333, ret.int_value());
+}
+
 TEST(Operators, ShortCircuitAnd) {
   Err err;
   TestWithScope setup;