Chromium Code Reviews| 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 <iostream> | 5 #include <iostream> |
| 6 #include <sstream> | 6 #include <sstream> |
| 7 | 7 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "tools/gn/input_file.h" | 9 #include "tools/gn/input_file.h" |
| 10 #include "tools/gn/parser.h" | 10 #include "tools/gn/parser.h" |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 " LITERAL(2)\n" | 197 " LITERAL(2)\n" |
| 198 " LITERAL(3)\n" | 198 " LITERAL(3)\n" |
| 199 " IDENTIFIER(foo)\n"); | 199 " IDENTIFIER(foo)\n"); |
| 200 DoExpressionPrintTest("[1,\n2,\n 3,\n 4]", | 200 DoExpressionPrintTest("[1,\n2,\n 3,\n 4]", |
| 201 "LIST\n" | 201 "LIST\n" |
| 202 " LITERAL(1)\n" | 202 " LITERAL(1)\n" |
| 203 " LITERAL(2)\n" | 203 " LITERAL(2)\n" |
| 204 " LITERAL(3)\n" | 204 " LITERAL(3)\n" |
| 205 " LITERAL(4)\n"); | 205 " LITERAL(4)\n"); |
| 206 | 206 |
| 207 DoExpressionErrorTest("[a, 2+,]", 1, 6); | 207 DoExpressionErrorTest("[a, 2+,]", 1, 7); |
|
mdempsky
2015/04/06 23:41:51
This expectation change is because GN used to give
| |
| 208 DoExpressionErrorTest("[,]", 1, 2); | 208 DoExpressionErrorTest("[,]", 1, 2); |
| 209 DoExpressionErrorTest("[a,,]", 1, 4); | 209 DoExpressionErrorTest("[a,,]", 1, 4); |
| 210 } | 210 } |
| 211 | 211 |
| 212 TEST(Parser, Assignment) { | 212 TEST(Parser, Assignment) { |
| 213 DoParserPrintTest("a=2", | 213 DoParserPrintTest("a=2", |
| 214 "BLOCK\n" | 214 "BLOCK\n" |
| 215 " BINARY(=)\n" | 215 " BINARY(=)\n" |
| 216 " IDENTIFIER(a)\n" | 216 " IDENTIFIER(a)\n" |
| 217 " LITERAL(2)\n"); | 217 " LITERAL(2)\n"); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 236 "BLOCK\n" | 236 "BLOCK\n" |
| 237 " BINARY(=)\n" | 237 " BINARY(=)\n" |
| 238 " IDENTIFIER(a)\n" | 238 " IDENTIFIER(a)\n" |
| 239 " BINARY(+)\n" | 239 " BINARY(+)\n" |
| 240 " ACCESSOR\n" | 240 " ACCESSOR\n" |
| 241 " b\n" | 241 " b\n" |
| 242 " IDENTIFIER(c)\n" | 242 " IDENTIFIER(c)\n" |
| 243 " LITERAL(2)\n"); | 243 " LITERAL(2)\n"); |
| 244 DoParserErrorTest("a = b.c.d", 1, 6); // Can't nest accessors (currently). | 244 DoParserErrorTest("a = b.c.d", 1, 6); // Can't nest accessors (currently). |
| 245 DoParserErrorTest("a.b = 5", 1, 1); // Can't assign to accessors (currently). | 245 DoParserErrorTest("a.b = 5", 1, 1); // Can't assign to accessors (currently). |
| 246 | |
| 247 // Error at the bad dot in the RHS, not the + operator (crbug.com/472038). | |
| 248 DoParserErrorTest("foo(a + b.c.d)", 1, 10); | |
| 246 } | 249 } |
| 247 | 250 |
| 248 TEST(Parser, Condition) { | 251 TEST(Parser, Condition) { |
| 249 DoParserPrintTest("if(1) { a = 2 }", | 252 DoParserPrintTest("if(1) { a = 2 }", |
| 250 "BLOCK\n" | 253 "BLOCK\n" |
| 251 " CONDITION\n" | 254 " CONDITION\n" |
| 252 " LITERAL(1)\n" | 255 " LITERAL(1)\n" |
| 253 " BLOCK\n" | 256 " BLOCK\n" |
| 254 " BINARY(=)\n" | 257 " BINARY(=)\n" |
| 255 " IDENTIFIER(a)\n" | 258 " IDENTIFIER(a)\n" |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 694 // freestanding block. | 697 // freestanding block. |
| 695 TEST(Parser, StandaloneBlock) { | 698 TEST(Parser, StandaloneBlock) { |
| 696 DoParserErrorTest( | 699 DoParserErrorTest( |
| 697 "if (true) {\n" | 700 "if (true) {\n" |
| 698 "}\n" | 701 "}\n" |
| 699 "{\n" | 702 "{\n" |
| 700 " assert(false)\n" | 703 " assert(false)\n" |
| 701 "}\n", | 704 "}\n", |
| 702 3, 1); | 705 3, 1); |
| 703 } | 706 } |
| OLD | NEW |