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

Side by Side Diff: tools/gn/parser_unittest.cc

Issue 1275853006: Fix some crashes in GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « tools/gn/parser.cc ('k') | tools/gn/tokenizer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 " FUNCTION(print)\n" 174 " FUNCTION(print)\n"
175 " LIST\n" 175 " LIST\n"
176 " LITERAL(\"hai\")\n"; 176 " LITERAL(\"hai\")\n";
177 DoParserPrintTest(input, expected); 177 DoParserPrintTest(input, expected);
178 } 178 }
179 179
180 TEST(Parser, UnaryOp) { 180 TEST(Parser, UnaryOp) {
181 DoExpressionPrintTest("!foo", 181 DoExpressionPrintTest("!foo",
182 "UNARY(!)\n" 182 "UNARY(!)\n"
183 " IDENTIFIER(foo)\n"); 183 " IDENTIFIER(foo)\n");
184
185 // No contents for binary operator.
186 DoExpressionErrorTest("a = !", 1, 5);
184 } 187 }
185 188
186 TEST(Parser, List) { 189 TEST(Parser, List) {
187 DoExpressionPrintTest("[]", "LIST\n"); 190 DoExpressionPrintTest("[]", "LIST\n");
188 DoExpressionPrintTest("[1,asd,]", 191 DoExpressionPrintTest("[1,asd,]",
189 "LIST\n" 192 "LIST\n"
190 " LITERAL(1)\n" 193 " LITERAL(1)\n"
191 " IDENTIFIER(asd)\n"); 194 " IDENTIFIER(asd)\n");
192 DoExpressionPrintTest("[1, 2+3 - foo]", 195 DoExpressionPrintTest("[1, 2+3 - foo]",
193 "LIST\n" 196 "LIST\n"
(...skipping 14 matching lines...) Expand all
208 DoExpressionErrorTest("[,]", 1, 2); 211 DoExpressionErrorTest("[,]", 1, 2);
209 DoExpressionErrorTest("[a,,]", 1, 4); 212 DoExpressionErrorTest("[a,,]", 1, 4);
210 } 213 }
211 214
212 TEST(Parser, Assignment) { 215 TEST(Parser, Assignment) {
213 DoParserPrintTest("a=2", 216 DoParserPrintTest("a=2",
214 "BLOCK\n" 217 "BLOCK\n"
215 " BINARY(=)\n" 218 " BINARY(=)\n"
216 " IDENTIFIER(a)\n" 219 " IDENTIFIER(a)\n"
217 " LITERAL(2)\n"); 220 " LITERAL(2)\n");
221
222 DoExpressionErrorTest("a = ", 1, 3);
218 } 223 }
219 224
220 TEST(Parser, Accessor) { 225 TEST(Parser, Accessor) {
221 // Accessor indexing. 226 // Accessor indexing.
222 DoParserPrintTest("a=b[c+2]", 227 DoParserPrintTest("a=b[c+2]",
223 "BLOCK\n" 228 "BLOCK\n"
224 " BINARY(=)\n" 229 " BINARY(=)\n"
225 " IDENTIFIER(a)\n" 230 " IDENTIFIER(a)\n"
226 " ACCESSOR\n" 231 " ACCESSOR\n"
227 " b\n" // AccessorNode is a bit weird in that it holds 232 " b\n" // AccessorNode is a bit weird in that it holds
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 // freestanding block. 702 // freestanding block.
698 TEST(Parser, StandaloneBlock) { 703 TEST(Parser, StandaloneBlock) {
699 DoParserErrorTest( 704 DoParserErrorTest(
700 "if (true) {\n" 705 "if (true) {\n"
701 "}\n" 706 "}\n"
702 "{\n" 707 "{\n"
703 " assert(false)\n" 708 " assert(false)\n"
704 "}\n", 709 "}\n",
705 3, 1); 710 3, 1);
706 } 711 }
OLDNEW
« no previous file with comments | « tools/gn/parser.cc ('k') | tools/gn/tokenizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698