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

Side by Side Diff: pkg/analyzer/test/generated/parser_test.dart

Issue 515543002: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/pubspec.yaml ('k') | tests/language/language_analyzer2.status » ('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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.parser_test; 8 library engine.parser_test;
9 9
10 import 'package:analyzer/src/generated/java_core.dart'; 10 import 'package:analyzer/src/generated/java_core.dart';
(...skipping 3189 matching lines...) Expand 10 before | Expand all | Expand 10 after
3200 * An empty array of objects used as arguments to zero-argument methods. 3200 * An empty array of objects used as arguments to zero-argument methods.
3201 */ 3201 */
3202 static List<Object> _EMPTY_ARGUMENTS = new List<Object>(0); 3202 static List<Object> _EMPTY_ARGUMENTS = new List<Object>(0);
3203 3203
3204 /** 3204 /**
3205 * A flag indicating whether parser is to parse function bodies. 3205 * A flag indicating whether parser is to parse function bodies.
3206 */ 3206 */
3207 static bool parseFunctionBodies = true; 3207 static bool parseFunctionBodies = true;
3208 3208
3209 /** 3209 /**
3210 * Create a parser.
3211 *
3212 * @param listener the listener to be passed to the parser
3213 * @return the parser that was created
3214 */
3215 static Parser createParser(GatheringErrorListener listener) {
3216 Parser parser = new Parser(null, listener);
3217 parser.parseAsync = true;
3218 parser.parseDeferredLibraries = true;
3219 parser.parseEnum = true;
3220 return parser;
3221 }
3222
3223 /**
3210 * Invoke a parse method in [Parser]. The method is assumed to have the given number and 3224 * Invoke a parse method in [Parser]. The method is assumed to have the given number and
3211 * type of parameters and will be invoked with the given arguments. 3225 * type of parameters and will be invoked with the given arguments.
3212 * 3226 *
3213 * The given source is scanned and the parser is initialized to start with the first token in the 3227 * The given source is scanned and the parser is initialized to start with the first token in the
3214 * source before the parse method is invoked. 3228 * source before the parse method is invoked.
3215 * 3229 *
3216 * @param methodName the name of the parse method that should be invoked to pa rse the source 3230 * @param methodName the name of the parse method that should be invoked to pa rse the source
3217 * @param objects the values of the arguments to the method 3231 * @param objects the values of the arguments to the method
3218 * @param source the source to be parsed by the parse method 3232 * @param source the source to be parsed by the parse method
3219 * @return the result of invoking the method 3233 * @return the result of invoking the method
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
3291 * @param errorCodes the error codes of the errors that are expected to be fou nd 3305 * @param errorCodes the error codes of the errors that are expected to be fou nd
3292 * @return the compilation unit that was parsed 3306 * @return the compilation unit that was parsed
3293 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do 3307 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do
3294 * not match those that are expected, or if the result would have be en `null` 3308 * not match those that are expected, or if the result would have be en `null`
3295 */ 3309 */
3296 static CompilationUnit parseCompilationUnit(String source, List<ErrorCode> err orCodes) { 3310 static CompilationUnit parseCompilationUnit(String source, List<ErrorCode> err orCodes) {
3297 GatheringErrorListener listener = new GatheringErrorListener(); 3311 GatheringErrorListener listener = new GatheringErrorListener();
3298 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener ); 3312 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener );
3299 listener.setLineInfo(new TestSource(), scanner.lineStarts); 3313 listener.setLineInfo(new TestSource(), scanner.lineStarts);
3300 Token token = scanner.tokenize(); 3314 Token token = scanner.tokenize();
3301 Parser parser = new Parser(null, listener); 3315 Parser parser = createParser(listener);
3302 parser.parseAsync = true;
3303 parser.parseDeferredLibraries = true;
3304 parser.parseEnum = true;
3305 CompilationUnit unit = parser.parseCompilationUnit(token); 3316 CompilationUnit unit = parser.parseCompilationUnit(token);
3306 JUnitTestCase.assertNotNull(unit); 3317 JUnitTestCase.assertNotNull(unit);
3307 listener.assertErrorsWithCodes(errorCodes); 3318 listener.assertErrorsWithCodes(errorCodes);
3308 return unit; 3319 return unit;
3309 } 3320 }
3310 3321
3311 /** 3322 /**
3312 * Parse the given source as an expression. 3323 * Parse the given source as an expression.
3313 * 3324 *
3314 * @param source the source to be parsed 3325 * @param source the source to be parsed
3315 * @param errorCodes the error codes of the errors that are expected to be fou nd 3326 * @param errorCodes the error codes of the errors that are expected to be fou nd
3316 * @return the expression that was parsed 3327 * @return the expression that was parsed
3317 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do 3328 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do
3318 * not match those that are expected, or if the result would have be en `null` 3329 * not match those that are expected, or if the result would have be en `null`
3319 */ 3330 */
3320 static Expression parseExpression(String source, List<ErrorCode> errorCodes) { 3331 static Expression parseExpression(String source, List<ErrorCode> errorCodes) {
3321 GatheringErrorListener listener = new GatheringErrorListener(); 3332 GatheringErrorListener listener = new GatheringErrorListener();
3322 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener ); 3333 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener );
3323 listener.setLineInfo(new TestSource(), scanner.lineStarts); 3334 listener.setLineInfo(new TestSource(), scanner.lineStarts);
3324 Token token = scanner.tokenize(); 3335 Token token = scanner.tokenize();
3325 Parser parser = new Parser(null, listener); 3336 Parser parser = createParser(listener);
3326 Expression expression = parser.parseExpression(token); 3337 Expression expression = parser.parseExpression(token);
3327 JUnitTestCase.assertNotNull(expression); 3338 JUnitTestCase.assertNotNull(expression);
3328 listener.assertErrorsWithCodes(errorCodes); 3339 listener.assertErrorsWithCodes(errorCodes);
3329 return expression; 3340 return expression;
3330 } 3341 }
3331 3342
3332 /** 3343 /**
3333 * Parse the given source as a statement. 3344 * Parse the given source as a statement.
3334 * 3345 *
3335 * @param source the source to be parsed 3346 * @param source the source to be parsed
3336 * @param errorCodes the error codes of the errors that are expected to be fou nd 3347 * @param errorCodes the error codes of the errors that are expected to be fou nd
3337 * @return the statement that was parsed 3348 * @return the statement that was parsed
3338 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do 3349 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do
3339 * not match those that are expected, or if the result would have be en `null` 3350 * not match those that are expected, or if the result would have be en `null`
3340 */ 3351 */
3341 static Statement parseStatement(String source, List<ErrorCode> errorCodes) { 3352 static Statement parseStatement(String source, List<ErrorCode> errorCodes) {
3342 GatheringErrorListener listener = new GatheringErrorListener(); 3353 GatheringErrorListener listener = new GatheringErrorListener();
3343 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener ); 3354 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener );
3344 listener.setLineInfo(new TestSource(), scanner.lineStarts); 3355 listener.setLineInfo(new TestSource(), scanner.lineStarts);
3345 Token token = scanner.tokenize(); 3356 Token token = scanner.tokenize();
3346 Parser parser = new Parser(null, listener); 3357 Parser parser = createParser(listener);
3347 Statement statement = parser.parseStatement(token); 3358 Statement statement = parser.parseStatement(token);
3348 JUnitTestCase.assertNotNull(statement); 3359 JUnitTestCase.assertNotNull(statement);
3349 listener.assertErrorsWithCodes(errorCodes); 3360 listener.assertErrorsWithCodes(errorCodes);
3350 return statement; 3361 return statement;
3351 } 3362 }
3352 3363
3353 /** 3364 /**
3354 * Parse the given source as a sequence of statements. 3365 * Parse the given source as a sequence of statements.
3355 * 3366 *
3356 * @param source the source to be parsed 3367 * @param source the source to be parsed
3357 * @param expectedCount the number of statements that are expected 3368 * @param expectedCount the number of statements that are expected
3358 * @param errorCodes the error codes of the errors that are expected to be fou nd 3369 * @param errorCodes the error codes of the errors that are expected to be fou nd
3359 * @return the statements that were parsed 3370 * @return the statements that were parsed
3360 * @throws Exception if the source could not be parsed, if the number of state ments does not match 3371 * @throws Exception if the source could not be parsed, if the number of state ments does not match
3361 * the expected count, if the compilation errors in the source do no t match those that 3372 * the expected count, if the compilation errors in the source do no t match those that
3362 * are expected, or if the result would have been `null` 3373 * are expected, or if the result would have been `null`
3363 */ 3374 */
3364 static List<Statement> parseStatements(String source, int expectedCount, List< ErrorCode> errorCodes) { 3375 static List<Statement> parseStatements(String source, int expectedCount, List< ErrorCode> errorCodes) {
3365 GatheringErrorListener listener = new GatheringErrorListener(); 3376 GatheringErrorListener listener = new GatheringErrorListener();
3366 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener ); 3377 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener );
3367 listener.setLineInfo(new TestSource(), scanner.lineStarts); 3378 listener.setLineInfo(new TestSource(), scanner.lineStarts);
3368 Token token = scanner.tokenize(); 3379 Token token = scanner.tokenize();
3369 Parser parser = new Parser(null, listener); 3380 Parser parser = createParser(listener);
3370 List<Statement> statements = parser.parseStatements(token); 3381 List<Statement> statements = parser.parseStatements(token);
3371 EngineTestCase.assertSizeOfList(expectedCount, statements); 3382 EngineTestCase.assertSizeOfList(expectedCount, statements);
3372 listener.assertErrorsWithCodes(errorCodes); 3383 listener.assertErrorsWithCodes(errorCodes);
3373 return statements; 3384 return statements;
3374 } 3385 }
3375 3386
3376 /** 3387 /**
3377 * Invoke a method in [Parser]. The method is assumed to have the given number and type of 3388 * Invoke a method in [Parser]. The method is assumed to have the given number and type of
3378 * parameters and will be invoked with the given arguments. 3389 * parameters and will be invoked with the given arguments.
3379 * 3390 *
(...skipping 12 matching lines...) Expand all
3392 static Object invokeParserMethod(String methodName, List<Object> objects, Stri ng source, GatheringErrorListener listener) { 3403 static Object invokeParserMethod(String methodName, List<Object> objects, Stri ng source, GatheringErrorListener listener) {
3393 // 3404 //
3394 // Scan the source. 3405 // Scan the source.
3395 // 3406 //
3396 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener ); 3407 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener );
3397 Token tokenStream = scanner.tokenize(); 3408 Token tokenStream = scanner.tokenize();
3398 listener.setLineInfo(new TestSource(), scanner.lineStarts); 3409 listener.setLineInfo(new TestSource(), scanner.lineStarts);
3399 // 3410 //
3400 // Parse the source. 3411 // Parse the source.
3401 // 3412 //
3402 Parser parser = new Parser(null, listener); 3413 Parser parser = createParser(listener);
3403 parser.parseFunctionBodies = parseFunctionBodies; 3414 parser.parseFunctionBodies = parseFunctionBodies;
3404 parser.parseDeferredLibraries = true; 3415 parser.parseDeferredLibraries = true;
3405 parser.parseAsync = true; 3416 parser.parseAsync = true;
3406 Object result = invokeParserMethodImpl(parser, methodName, objects, tokenStr eam); 3417 Object result = invokeParserMethodImpl(parser, methodName, objects, tokenStr eam);
3407 // 3418 //
3408 // Partially test the results. 3419 // Partially test the results.
3409 // 3420 //
3410 if (!listener.hasErrors) { 3421 if (!listener.hasErrors) {
3411 JUnitTestCase.assertNotNull(result); 3422 JUnitTestCase.assertNotNull(result);
3412 } 3423 }
(...skipping 2374 matching lines...) Expand 10 before | Expand all | Expand 10 after
5787 SimpleIdentifier selector = ParserTestCase.parse("parseAssignableSelector", <Object> [new SimpleIdentifier(null), true], ";"); 5798 SimpleIdentifier selector = ParserTestCase.parse("parseAssignableSelector", <Object> [new SimpleIdentifier(null), true], ";");
5788 JUnitTestCase.assertNotNull(selector); 5799 JUnitTestCase.assertNotNull(selector);
5789 } 5800 }
5790 5801
5791 void test_parseAwaitExpression() { 5802 void test_parseAwaitExpression() {
5792 AwaitExpression expression = ParserTestCase.parse4("parseAwaitExpression", " await x;", []); 5803 AwaitExpression expression = ParserTestCase.parse4("parseAwaitExpression", " await x;", []);
5793 JUnitTestCase.assertNotNull(expression.awaitKeyword); 5804 JUnitTestCase.assertNotNull(expression.awaitKeyword);
5794 JUnitTestCase.assertNotNull(expression.expression); 5805 JUnitTestCase.assertNotNull(expression.expression);
5795 } 5806 }
5796 5807
5808 void test_parseAwaitExpression_asStatement_inAsync() {
5809 MethodDeclaration method = ParserTestCase.parse("parseClassMember", <Object> ["C"], EngineTestCase.createSource(["m() async { await x; }"]));
5810 FunctionBody body = method.body;
5811 EngineTestCase.assertInstanceOf((obj) => obj is BlockFunctionBody, BlockFunc tionBody, body);
5812 Statement statement = (body as BlockFunctionBody).block.statements[0];
5813 EngineTestCase.assertInstanceOf((obj) => obj is ExpressionStatement, Express ionStatement, statement);
5814 Expression expression = (statement as ExpressionStatement).expression;
5815 EngineTestCase.assertInstanceOf((obj) => obj is AwaitExpression, AwaitExpres sion, expression);
5816 JUnitTestCase.assertNotNull((expression as AwaitExpression).awaitKeyword);
5817 JUnitTestCase.assertNotNull((expression as AwaitExpression).expression);
5818 }
5819
5820 void test_parseAwaitExpression_asStatement_inSync() {
5821 MethodDeclaration method = ParserTestCase.parse("parseClassMember", <Object> ["C"], EngineTestCase.createSource(["m() { await x; }"]));
5822 FunctionBody body = method.body;
5823 EngineTestCase.assertInstanceOf((obj) => obj is BlockFunctionBody, BlockFunc tionBody, body);
5824 Statement statement = (body as BlockFunctionBody).block.statements[0];
5825 EngineTestCase.assertInstanceOf((obj) => obj is VariableDeclarationStatement , VariableDeclarationStatement, statement);
5826 }
5827
5797 void test_parseBitwiseAndExpression_normal() { 5828 void test_parseBitwiseAndExpression_normal() {
5798 BinaryExpression expression = ParserTestCase.parse4("parseBitwiseAndExpressi on", "x & y", []); 5829 BinaryExpression expression = ParserTestCase.parse4("parseBitwiseAndExpressi on", "x & y", []);
5799 JUnitTestCase.assertNotNull(expression.leftOperand); 5830 JUnitTestCase.assertNotNull(expression.leftOperand);
5800 JUnitTestCase.assertNotNull(expression.operator); 5831 JUnitTestCase.assertNotNull(expression.operator);
5801 JUnitTestCase.assertEquals(TokenType.AMPERSAND, expression.operator.type); 5832 JUnitTestCase.assertEquals(TokenType.AMPERSAND, expression.operator.type);
5802 JUnitTestCase.assertNotNull(expression.rightOperand); 5833 JUnitTestCase.assertNotNull(expression.rightOperand);
5803 } 5834 }
5804 5835
5805 void test_parseBitwiseAndExpression_super() { 5836 void test_parseBitwiseAndExpression_super() {
5806 BinaryExpression expression = ParserTestCase.parse4("parseBitwiseAndExpressi on", "super & y", []); 5837 BinaryExpression expression = ParserTestCase.parse4("parseBitwiseAndExpressi on", "super & y", []);
(...skipping 4663 matching lines...) Expand 10 before | Expand all | Expand 10 after
10470 runJUnitTest(__test, __test.test_parseAssignableSelector_index); 10501 runJUnitTest(__test, __test.test_parseAssignableSelector_index);
10471 }); 10502 });
10472 _ut.test('test_parseAssignableSelector_none', () { 10503 _ut.test('test_parseAssignableSelector_none', () {
10473 final __test = new SimpleParserTest(); 10504 final __test = new SimpleParserTest();
10474 runJUnitTest(__test, __test.test_parseAssignableSelector_none); 10505 runJUnitTest(__test, __test.test_parseAssignableSelector_none);
10475 }); 10506 });
10476 _ut.test('test_parseAwaitExpression', () { 10507 _ut.test('test_parseAwaitExpression', () {
10477 final __test = new SimpleParserTest(); 10508 final __test = new SimpleParserTest();
10478 runJUnitTest(__test, __test.test_parseAwaitExpression); 10509 runJUnitTest(__test, __test.test_parseAwaitExpression);
10479 }); 10510 });
10511 _ut.test('test_parseAwaitExpression_asStatement_inAsync', () {
10512 final __test = new SimpleParserTest();
10513 runJUnitTest(__test, __test.test_parseAwaitExpression_asStatement_inAsyn c);
10514 });
10515 _ut.test('test_parseAwaitExpression_asStatement_inSync', () {
10516 final __test = new SimpleParserTest();
10517 runJUnitTest(__test, __test.test_parseAwaitExpression_asStatement_inSync );
10518 });
10480 _ut.test('test_parseBitwiseAndExpression_normal', () { 10519 _ut.test('test_parseBitwiseAndExpression_normal', () {
10481 final __test = new SimpleParserTest(); 10520 final __test = new SimpleParserTest();
10482 runJUnitTest(__test, __test.test_parseBitwiseAndExpression_normal); 10521 runJUnitTest(__test, __test.test_parseBitwiseAndExpression_normal);
10483 }); 10522 });
10484 _ut.test('test_parseBitwiseAndExpression_super', () { 10523 _ut.test('test_parseBitwiseAndExpression_super', () {
10485 final __test = new SimpleParserTest(); 10524 final __test = new SimpleParserTest();
10486 runJUnitTest(__test, __test.test_parseBitwiseAndExpression_super); 10525 runJUnitTest(__test, __test.test_parseBitwiseAndExpression_super);
10487 }); 10526 });
10488 _ut.test('test_parseBitwiseOrExpression_normal', () { 10527 _ut.test('test_parseBitwiseOrExpression_normal', () {
10489 final __test = new SimpleParserTest(); 10528 final __test = new SimpleParserTest();
(...skipping 1893 matching lines...) Expand 10 before | Expand all | Expand 10 after
12383 12422
12384 main() { 12423 main() {
12385 ComplexParserTest.dartSuite(); 12424 ComplexParserTest.dartSuite();
12386 ErrorParserTest.dartSuite(); 12425 ErrorParserTest.dartSuite();
12387 IncrementalParserTest.dartSuite(); 12426 IncrementalParserTest.dartSuite();
12388 NonErrorParserTest.dartSuite(); 12427 NonErrorParserTest.dartSuite();
12389 RecoveryParserTest.dartSuite(); 12428 RecoveryParserTest.dartSuite();
12390 ResolutionCopierTest.dartSuite(); 12429 ResolutionCopierTest.dartSuite();
12391 SimpleParserTest.dartSuite(); 12430 SimpleParserTest.dartSuite();
12392 } 12431 }
OLDNEW
« no previous file with comments | « pkg/analyzer/pubspec.yaml ('k') | tests/language/language_analyzer2.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698