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

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

Issue 881403002: Fix for issue 22052 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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
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 library engine.parser_test; 5 library engine.parser_test;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
9 import 'package:analyzer/src/generated/error.dart'; 9 import 'package:analyzer/src/generated/error.dart';
10 import 'package:analyzer/src/generated/incremental_scanner.dart'; 10 import 'package:analyzer/src/generated/incremental_scanner.dart';
(...skipping 5147 matching lines...) Expand 10 before | Expand all | Expand 10 after
5158 5158
5159 /** 5159 /**
5160 * The class `SimpleParserTest` defines parser tests that test individual parsin g method. The 5160 * The class `SimpleParserTest` defines parser tests that test individual parsin g method. The
5161 * code fragments should be as minimal as possible in order to test the method, but should not test 5161 * code fragments should be as minimal as possible in order to test the method, but should not test
5162 * the interactions between the method under test and other methods. 5162 * the interactions between the method under test and other methods.
5163 * 5163 *
5164 * More complex tests should be defined in the class [ComplexParserTest]. 5164 * More complex tests should be defined in the class [ComplexParserTest].
5165 */ 5165 */
5166 @reflectiveTest 5166 @reflectiveTest
5167 class SimpleParserTest extends ParserTestCase { 5167 class SimpleParserTest extends ParserTestCase {
5168 void fail_parseAwaitExpression_inSync() {
5169 // This test requires better error recovery than we currently have. In
5170 // particular, we need to be able to distinguish between an await expression
5171 // in the wrong context, and the use of 'await' as an identifier.
5172 MethodDeclaration method = ParserTestCase.parse(
5173 "parseClassMember",
5174 <Object>["C"],
5175 "m() { return await x + await y; }");
5176 FunctionBody body = method.body;
5177 EngineTestCase.assertInstanceOf(
5178 (obj) => obj is BlockFunctionBody,
5179 BlockFunctionBody,
5180 body);
5181 Statement statement = (body as BlockFunctionBody).block.statements[0];
5182 EngineTestCase.assertInstanceOf(
5183 (obj) => obj is ReturnStatement,
5184 ReturnStatement,
5185 statement);
5186 Expression expression = (statement as ReturnStatement).expression;
5187 EngineTestCase.assertInstanceOf(
5188 (obj) => obj is BinaryExpression,
5189 BinaryExpression,
5190 expression);
5191 EngineTestCase.assertInstanceOf(
5192 (obj) => obj is AwaitExpression,
5193 AwaitExpression,
5194 (expression as BinaryExpression).leftOperand);
5195 EngineTestCase.assertInstanceOf(
5196 (obj) => obj is AwaitExpression,
5197 AwaitExpression,
5198 (expression as BinaryExpression).rightOperand);
5199 }
5200
5168 void fail_parseCommentReference_this() { 5201 void fail_parseCommentReference_this() {
5169 // This fails because we are returning null from the method and asserting 5202 // This fails because we are returning null from the method and asserting
5170 // that the return value is not null. 5203 // that the return value is not null.
5171 CommentReference reference = 5204 CommentReference reference =
5172 ParserTestCase.parse("parseCommentReference", <Object>["this", 5], ""); 5205 ParserTestCase.parse("parseCommentReference", <Object>["this", 5], "");
5173 SimpleIdentifier identifier = EngineTestCase.assertInstanceOf( 5206 SimpleIdentifier identifier = EngineTestCase.assertInstanceOf(
5174 (obj) => obj is SimpleIdentifier, 5207 (obj) => obj is SimpleIdentifier,
5175 SimpleIdentifier, 5208 SimpleIdentifier,
5176 reference.identifier); 5209 reference.identifier);
5177 expect(identifier.token, isNotNull); 5210 expect(identifier.token, isNotNull);
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
5755 (obj) => obj is BlockFunctionBody, 5788 (obj) => obj is BlockFunctionBody,
5756 BlockFunctionBody, 5789 BlockFunctionBody,
5757 body); 5790 body);
5758 Statement statement = (body as BlockFunctionBody).block.statements[0]; 5791 Statement statement = (body as BlockFunctionBody).block.statements[0];
5759 EngineTestCase.assertInstanceOf( 5792 EngineTestCase.assertInstanceOf(
5760 (obj) => obj is VariableDeclarationStatement, 5793 (obj) => obj is VariableDeclarationStatement,
5761 VariableDeclarationStatement, 5794 VariableDeclarationStatement,
5762 statement); 5795 statement);
5763 } 5796 }
5764 5797
5765 void test_parseAwaitExpression_inSync() {
5766 MethodDeclaration method = ParserTestCase.parse(
5767 "parseClassMember",
5768 <Object>["C"],
5769 "m() { return await x + await y; }");
5770 FunctionBody body = method.body;
5771 EngineTestCase.assertInstanceOf(
5772 (obj) => obj is BlockFunctionBody,
5773 BlockFunctionBody,
5774 body);
5775 Statement statement = (body as BlockFunctionBody).block.statements[0];
5776 EngineTestCase.assertInstanceOf(
5777 (obj) => obj is ReturnStatement,
5778 ReturnStatement,
5779 statement);
5780 Expression expression = (statement as ReturnStatement).expression;
5781 EngineTestCase.assertInstanceOf(
5782 (obj) => obj is BinaryExpression,
5783 BinaryExpression,
5784 expression);
5785 EngineTestCase.assertInstanceOf(
5786 (obj) => obj is AwaitExpression,
5787 AwaitExpression,
5788 (expression as BinaryExpression).leftOperand);
5789 EngineTestCase.assertInstanceOf(
5790 (obj) => obj is AwaitExpression,
5791 AwaitExpression,
5792 (expression as BinaryExpression).rightOperand);
5793 }
5794
5795 void test_parseBitwiseAndExpression_normal() { 5798 void test_parseBitwiseAndExpression_normal() {
5796 BinaryExpression expression = 5799 BinaryExpression expression =
5797 ParserTestCase.parse4("parseBitwiseAndExpression", "x & y"); 5800 ParserTestCase.parse4("parseBitwiseAndExpression", "x & y");
5798 expect(expression.leftOperand, isNotNull); 5801 expect(expression.leftOperand, isNotNull);
5799 expect(expression.operator, isNotNull); 5802 expect(expression.operator, isNotNull);
5800 expect(expression.operator.type, TokenType.AMPERSAND); 5803 expect(expression.operator.type, TokenType.AMPERSAND);
5801 expect(expression.rightOperand, isNotNull); 5804 expect(expression.rightOperand, isNotNull);
5802 } 5805 }
5803 5806
5804 void test_parseBitwiseAndExpression_super() { 5807 void test_parseBitwiseAndExpression_super() {
(...skipping 2032 matching lines...) Expand 10 before | Expand all | Expand 10 after
7837 FunctionExpression, 7840 FunctionExpression,
7838 invocation.function); 7841 invocation.function);
7839 FunctionExpression expression = invocation.function as FunctionExpression; 7842 FunctionExpression expression = invocation.function as FunctionExpression;
7840 expect(expression.parameters, isNotNull); 7843 expect(expression.parameters, isNotNull);
7841 expect(expression.body, isNotNull); 7844 expect(expression.body, isNotNull);
7842 ArgumentList list = invocation.argumentList; 7845 ArgumentList list = invocation.argumentList;
7843 expect(list, isNotNull); 7846 expect(list, isNotNull);
7844 expect(list.arguments, hasLength(1)); 7847 expect(list.arguments, hasLength(1));
7845 } 7848 }
7846 7849
7850 void test_parseExpression_nonAwait() {
7851 MethodInvocation expression = ParserTestCase.parseExpression("await()");
7852 expect(expression.methodName.name, 'await');
7853 }
7854
7847 void test_parseExpression_superMethodInvocation() { 7855 void test_parseExpression_superMethodInvocation() {
7848 MethodInvocation invocation = 7856 MethodInvocation invocation =
7849 ParserTestCase.parse4("parseExpression", "super.m()"); 7857 ParserTestCase.parse4("parseExpression", "super.m()");
7850 expect(invocation.target, isNotNull); 7858 expect(invocation.target, isNotNull);
7851 expect(invocation.methodName, isNotNull); 7859 expect(invocation.methodName, isNotNull);
7852 expect(invocation.argumentList, isNotNull); 7860 expect(invocation.argumentList, isNotNull);
7853 } 7861 }
7854 7862
7855 void test_parseExpressionList_multiple() { 7863 void test_parseExpressionList_multiple() {
7856 List<Expression> result = 7864 List<Expression> result =
(...skipping 3124 matching lines...) Expand 10 before | Expand all | Expand 10 after
10981 // Parse the source. 10989 // Parse the source.
10982 // 10990 //
10983 Parser parser = new Parser(null, listener); 10991 Parser parser = new Parser(null, listener);
10984 return invokeParserMethodImpl( 10992 return invokeParserMethodImpl(
10985 parser, 10993 parser,
10986 methodName, 10994 methodName,
10987 <Object>[tokenStream], 10995 <Object>[tokenStream],
10988 tokenStream) as Token; 10996 tokenStream) as Token;
10989 } 10997 }
10990 } 10998 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698