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

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

Issue 2990003002: update fasta parser compatibility tests to check error codes (Closed)
Patch Set: Created 3 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 | « pkg/analyzer/test/generated/parser_fasta_test.dart ('k') | no next file » | 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 import 'package:analyzer/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
7 import 'package:analyzer/dart/ast/token.dart'; 7 import 'package:analyzer/dart/ast/token.dart';
8 import 'package:analyzer/dart/ast/visitor.dart'; 8 import 'package:analyzer/dart/ast/visitor.dart';
9 import 'package:analyzer/error/error.dart'; 9 import 'package:analyzer/error/error.dart';
10 import 'package:analyzer/error/listener.dart'; 10 import 'package:analyzer/error/listener.dart';
(...skipping 7587 matching lines...) Expand 10 before | Expand all | Expand 10 after
7598 expect(list.parameters[0].toSource(), 'io. '); 7598 expect(list.parameters[0].toSource(), 'io. ');
7599 expect(list.parameters[1].toSource(), 'a'); 7599 expect(list.parameters[1].toSource(), 'a');
7600 expect(list.rightDelimiter, isNull); 7600 expect(list.rightDelimiter, isNull);
7601 expect(list.rightParenthesis, isNotNull); 7601 expect(list.rightParenthesis, isNotNull);
7602 } 7602 }
7603 7603
7604 void test_parseNormalFormalParameter_field_const_noType() { 7604 void test_parseNormalFormalParameter_field_const_noType() {
7605 NormalFormalParameter parameter = 7605 NormalFormalParameter parameter =
7606 parseNormalFormalParameter('const this.a'); 7606 parseNormalFormalParameter('const this.a');
7607 expect(parameter, isNotNull); 7607 expect(parameter, isNotNull);
7608 assertNoErrors(); 7608 if (usingFastaParser) {
7609 // TODO(danrubel): should not be generating an error
7610 assertErrorsWithCodes([ParserErrorCode.UNEXPECTED_TOKEN]);
7611 } else {
7612 assertNoErrors();
7613 }
7609 expect(parameter, new isInstanceOf<FieldFormalParameter>()); 7614 expect(parameter, new isInstanceOf<FieldFormalParameter>());
7610 FieldFormalParameter fieldParameter = parameter; 7615 FieldFormalParameter fieldParameter = parameter;
7611 expect(fieldParameter.keyword, isNotNull); 7616 expect(fieldParameter.keyword, isNotNull);
7612 expect(fieldParameter.type, isNull); 7617 expect(fieldParameter.type, isNull);
7613 expect(fieldParameter.identifier, isNotNull); 7618 expect(fieldParameter.identifier, isNotNull);
7614 expect(fieldParameter.parameters, isNull); 7619 expect(fieldParameter.parameters, isNull);
7615 } 7620 }
7616 7621
7617 void test_parseNormalFormalParameter_field_const_type() { 7622 void test_parseNormalFormalParameter_field_const_type() {
7618 NormalFormalParameter parameter = 7623 NormalFormalParameter parameter =
7619 parseNormalFormalParameter('const A this.a'); 7624 parseNormalFormalParameter('const A this.a');
7620 expect(parameter, isNotNull); 7625 expect(parameter, isNotNull);
7621 assertNoErrors(); 7626 if (usingFastaParser) {
7627 // TODO(danrubel): should not be generating an error
7628 assertErrorsWithCodes([ParserErrorCode.UNEXPECTED_TOKEN]);
7629 } else {
7630 assertNoErrors();
7631 }
7622 expect(parameter, new isInstanceOf<FieldFormalParameter>()); 7632 expect(parameter, new isInstanceOf<FieldFormalParameter>());
7623 FieldFormalParameter fieldParameter = parameter; 7633 FieldFormalParameter fieldParameter = parameter;
7624 expect(fieldParameter.keyword, isNotNull); 7634 expect(fieldParameter.keyword, isNotNull);
7625 expect(fieldParameter.type, isNotNull); 7635 expect(fieldParameter.type, isNotNull);
7626 expect(fieldParameter.identifier, isNotNull); 7636 expect(fieldParameter.identifier, isNotNull);
7627 expect(fieldParameter.parameters, isNull); 7637 expect(fieldParameter.parameters, isNull);
7628 } 7638 }
7629 7639
7630 void test_parseNormalFormalParameter_field_final_noType() { 7640 void test_parseNormalFormalParameter_field_final_noType() {
7631 NormalFormalParameter parameter = 7641 NormalFormalParameter parameter =
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
7967 7977
7968 void test_parseNormalFormalParameter_function_withDocComment() { 7978 void test_parseNormalFormalParameter_function_withDocComment() {
7969 var parameter = parseFormalParameter('/// Doc\nf()', ParameterKind.REQUIRED) 7979 var parameter = parseFormalParameter('/// Doc\nf()', ParameterKind.REQUIRED)
7970 as FunctionTypedFormalParameter; 7980 as FunctionTypedFormalParameter;
7971 expectCommentText(parameter.documentationComment, '/// Doc'); 7981 expectCommentText(parameter.documentationComment, '/// Doc');
7972 } 7982 }
7973 7983
7974 void test_parseNormalFormalParameter_simple_const_noType() { 7984 void test_parseNormalFormalParameter_simple_const_noType() {
7975 NormalFormalParameter parameter = parseNormalFormalParameter('const a'); 7985 NormalFormalParameter parameter = parseNormalFormalParameter('const a');
7976 expect(parameter, isNotNull); 7986 expect(parameter, isNotNull);
7977 assertNoErrors(); 7987 if (usingFastaParser) {
7988 // TODO(danrubel): should not be generating an error
7989 assertErrorsWithCodes([ParserErrorCode.UNEXPECTED_TOKEN]);
7990 } else {
7991 assertNoErrors();
7992 }
7978 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); 7993 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
7979 SimpleFormalParameter simpleParameter = parameter; 7994 SimpleFormalParameter simpleParameter = parameter;
7980 expect(simpleParameter.keyword, isNotNull); 7995 expect(simpleParameter.keyword, isNotNull);
7981 expect(simpleParameter.type, isNull); 7996 expect(simpleParameter.type, isNull);
7982 expect(simpleParameter.identifier, isNotNull); 7997 expect(simpleParameter.identifier, isNotNull);
7983 } 7998 }
7984 7999
7985 void test_parseNormalFormalParameter_simple_const_type() { 8000 void test_parseNormalFormalParameter_simple_const_type() {
7986 NormalFormalParameter parameter = parseNormalFormalParameter('const A a'); 8001 NormalFormalParameter parameter = parseNormalFormalParameter('const A a');
7987 expect(parameter, isNotNull); 8002 expect(parameter, isNotNull);
7988 assertNoErrors(); 8003 if (usingFastaParser) {
8004 // TODO(danrubel): should not be generating an error
8005 assertErrorsWithCodes([ParserErrorCode.UNEXPECTED_TOKEN]);
8006 } else {
8007 assertNoErrors();
8008 }
7989 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); 8009 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
7990 SimpleFormalParameter simpleParameter = parameter; 8010 SimpleFormalParameter simpleParameter = parameter;
7991 expect(simpleParameter.keyword, isNotNull); 8011 expect(simpleParameter.keyword, isNotNull);
7992 expect(simpleParameter.type, isNotNull); 8012 expect(simpleParameter.type, isNotNull);
7993 expect(simpleParameter.identifier, isNotNull); 8013 expect(simpleParameter.identifier, isNotNull);
7994 } 8014 }
7995 8015
7996 void test_parseNormalFormalParameter_simple_final_noType() { 8016 void test_parseNormalFormalParameter_simple_final_noType() {
7997 NormalFormalParameter parameter = parseNormalFormalParameter('final a'); 8017 NormalFormalParameter parameter = parseNormalFormalParameter('final a');
7998 expect(parameter, isNotNull); 8018 expect(parameter, isNotNull);
(...skipping 5759 matching lines...) Expand 10 before | Expand all | Expand 10 after
13758 assertNoErrors(); 13778 assertNoErrors();
13759 expect(unit.scriptTag, isNull); 13779 expect(unit.scriptTag, isNull);
13760 expect(unit.directives, hasLength(0)); 13780 expect(unit.directives, hasLength(0));
13761 expect(unit.declarations, hasLength(1)); 13781 expect(unit.declarations, hasLength(1));
13762 } 13782 }
13763 13783
13764 void test_parseCompilationUnit_operatorAsPrefix_parameterized() { 13784 void test_parseCompilationUnit_operatorAsPrefix_parameterized() {
13765 createParser('operator<dynamic> _operator = new operator.A();'); 13785 createParser('operator<dynamic> _operator = new operator.A();');
13766 CompilationUnit unit = parser.parseCompilationUnit2(); 13786 CompilationUnit unit = parser.parseCompilationUnit2();
13767 expect(unit, isNotNull); 13787 expect(unit, isNotNull);
13768 assertNoErrors(); 13788 if (usingFastaParser) {
13789 // TODO(danrubel): should not be generating an error
13790 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TYPE_NAME]);
13791 } else {
13792 assertNoErrors();
13793 }
13769 expect(unit.scriptTag, isNull); 13794 expect(unit.scriptTag, isNull);
13770 expect(unit.directives, hasLength(0)); 13795 expect(unit.directives, hasLength(0));
13771 expect(unit.declarations, hasLength(1)); 13796 expect(unit.declarations, hasLength(1));
13772 } 13797 }
13773 13798
13774 void test_parseCompilationUnit_script() { 13799 void test_parseCompilationUnit_script() {
13775 createParser('#! /bin/dart'); 13800 createParser('#! /bin/dart');
13776 CompilationUnit unit = parser.parseCompilationUnit2(); 13801 CompilationUnit unit = parser.parseCompilationUnit2();
13777 expect(unit, isNotNull); 13802 expect(unit, isNotNull);
13778 assertNoErrors(); 13803 assertNoErrors();
(...skipping 23 matching lines...) Expand all
13802 expect(unit.beginToken, isNotNull); 13827 expect(unit.beginToken, isNotNull);
13803 expect(unit.beginToken.keyword, Keyword.CLASS); 13828 expect(unit.beginToken.keyword, Keyword.CLASS);
13804 expect(unit.endToken, isNotNull); 13829 expect(unit.endToken, isNotNull);
13805 expect(unit.endToken.type, TokenType.EOF); 13830 expect(unit.endToken.type, TokenType.EOF);
13806 } 13831 }
13807 13832
13808 void test_parseCompilationUnit_typedefAsPrefix() { 13833 void test_parseCompilationUnit_typedefAsPrefix() {
13809 createParser('typedef.A _typedef = new typedef.A();'); 13834 createParser('typedef.A _typedef = new typedef.A();');
13810 CompilationUnit unit = parser.parseCompilationUnit2(); 13835 CompilationUnit unit = parser.parseCompilationUnit2();
13811 expect(unit, isNotNull); 13836 expect(unit, isNotNull);
13812 assertNoErrors(); 13837 if (usingFastaParser) {
13838 // TODO(danrubel): should not be generating an error
13839 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TYPE_NAME]);
13840 } else {
13841 assertNoErrors();
13842 }
13813 expect(unit.scriptTag, isNull); 13843 expect(unit.scriptTag, isNull);
13814 expect(unit.directives, hasLength(0)); 13844 expect(unit.directives, hasLength(0));
13815 expect(unit.declarations, hasLength(1)); 13845 expect(unit.declarations, hasLength(1));
13816 } 13846 }
13817 13847
13818 void test_parseCompilationUnitMember_abstractAsPrefix() { 13848 void test_parseCompilationUnitMember_abstractAsPrefix() {
13819 createParser('abstract.A _abstract = new abstract.A();'); 13849 createParser('abstract.A _abstract = new abstract.A();');
13820 CompilationUnitMember member = parseFullCompilationUnitMember(); 13850 CompilationUnitMember member = parseFullCompilationUnitMember();
13821 expect(member, isNotNull); 13851 expect(member, isNotNull);
13822 assertNoErrors(); 13852 if (usingFastaParser) {
13853 // TODO(danrubel): should not be generating an error
13854 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TYPE_NAME]);
13855 } else {
13856 assertNoErrors();
13857 }
13823 expect(member, new isInstanceOf<TopLevelVariableDeclaration>()); 13858 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
13824 TopLevelVariableDeclaration declaration = member; 13859 TopLevelVariableDeclaration declaration = member;
13825 expect(declaration.semicolon, isNotNull); 13860 expect(declaration.semicolon, isNotNull);
13826 expect(declaration.variables, isNotNull); 13861 expect(declaration.variables, isNotNull);
13827 } 13862 }
13828 13863
13829 void test_parseCompilationUnitMember_class() { 13864 void test_parseCompilationUnitMember_class() {
13830 createParser('class A {}'); 13865 createParser('class A {}');
13831 CompilationUnitMember member = parseFullCompilationUnitMember(); 13866 CompilationUnitMember member = parseFullCompilationUnitMember();
13832 expect(member, isNotNull); 13867 expect(member, isNotNull);
(...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after
15174 expectCommentText(typeVariable.documentationComment, '/// Doc'); 15209 expectCommentText(typeVariable.documentationComment, '/// Doc');
15175 } 15210 }
15176 15211
15177 /** 15212 /**
15178 * Assert that the given [name] is in declaration context. 15213 * Assert that the given [name] is in declaration context.
15179 */ 15214 */
15180 void _assertIsDeclarationName(SimpleIdentifier name) { 15215 void _assertIsDeclarationName(SimpleIdentifier name) {
15181 expect(name.inDeclarationContext(), isTrue); 15216 expect(name.inDeclarationContext(), isTrue);
15182 } 15217 }
15183 } 15218 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/parser_fasta_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698