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

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

Issue 2829693002: Move 'general function type' unit tests into mixins to run them with Fasta. (Closed)
Patch Set: Created 3 years, 8 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 | « no previous file | 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 library analyzer.test.generated.parser_test; 5 library analyzer.test.generated.parser_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 8 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
9 import 'package:analyzer/dart/ast/token.dart'; 9 import 'package:analyzer/dart/ast/token.dart';
10 import 'package:analyzer/dart/ast/visitor.dart'; 10 import 'package:analyzer/dart/ast/visitor.dart';
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 expect(field.metadata, hasLength(0)); 383 expect(field.metadata, hasLength(0));
384 expect(field.staticKeyword, isNull); 384 expect(field.staticKeyword, isNull);
385 VariableDeclarationList list = field.fields; 385 VariableDeclarationList list = field.fields;
386 expect(list, isNotNull); 386 expect(list, isNotNull);
387 NodeList<VariableDeclaration> variables = list.variables; 387 NodeList<VariableDeclaration> variables = list.variables;
388 expect(variables, hasLength(1)); 388 expect(variables, hasLength(1));
389 VariableDeclaration variable = variables[0]; 389 VariableDeclaration variable = variables[0];
390 expect(variable.name, isNotNull); 390 expect(variable.name, isNotNull);
391 } 391 }
392 392
393 void test_parseClassMember_field_gftType_gftReturnType() {
394 createParser('''
395 Function(int) Function(String) v;
396 ''');
397 ClassMember member = parser.parseClassMember('C');
398 assertNoErrors();
399 expect(member, new isInstanceOf<FieldDeclaration>());
400 VariableDeclarationList fields = (member as FieldDeclaration).fields;
401 expect(fields.type, new isInstanceOf<GenericFunctionType>());
402 }
403
404 void test_parseClassMember_field_gftType_noReturnType() {
405 createParser('''
406 Function(int, String) v;
407 ''');
408 ClassMember member = parser.parseClassMember('C');
409 assertNoErrors();
410 expect(member, new isInstanceOf<FieldDeclaration>());
411 VariableDeclarationList fields = (member as FieldDeclaration).fields;
412 expect(fields.type, new isInstanceOf<GenericFunctionType>());
413 }
414
393 void test_parseClassMember_field_instance_prefixedType() { 415 void test_parseClassMember_field_instance_prefixedType() {
394 createParser('p.A f;'); 416 createParser('p.A f;');
395 ClassMember member = parser.parseClassMember('C'); 417 ClassMember member = parser.parseClassMember('C');
396 expect(member, isNotNull); 418 expect(member, isNotNull);
397 assertNoErrors(); 419 assertNoErrors();
398 expect(member, new isInstanceOf<FieldDeclaration>()); 420 expect(member, new isInstanceOf<FieldDeclaration>());
399 FieldDeclaration field = member; 421 FieldDeclaration field = member;
400 expect(field.covariantKeyword, isNull); 422 expect(field.covariantKeyword, isNull);
401 expect(field.documentationComment, isNull); 423 expect(field.documentationComment, isNull);
402 expect(field.metadata, hasLength(0)); 424 expect(field.metadata, hasLength(0));
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 expect(method.modifierKeyword, isNull); 799 expect(method.modifierKeyword, isNull);
778 expect(method.propertyKeyword, isNull); 800 expect(method.propertyKeyword, isNull);
779 expect(method.returnType, isNotNull); 801 expect(method.returnType, isNotNull);
780 expect(method.name, isNotNull); 802 expect(method.name, isNotNull);
781 expect(method.operatorKeyword, isNull); 803 expect(method.operatorKeyword, isNull);
782 expect(method.typeParameters, isNull); 804 expect(method.typeParameters, isNull);
783 expect(method.parameters, isNotNull); 805 expect(method.parameters, isNotNull);
784 expect(method.body, isNotNull); 806 expect(method.body, isNotNull);
785 } 807 }
786 808
809 void test_parseClassMember_method_gftReturnType_noReturnType() {
810 createParser('''
811 Function<A>(core.List<core.int> x) m() => null;
812 ''');
813 ClassMember member = parser.parseClassMember('C');
814 assertNoErrors();
815 expect(member, new isInstanceOf<MethodDeclaration>());
816 expect((member as MethodDeclaration).body,
817 new isInstanceOf<ExpressionFunctionBody>());
818 }
819
820 void test_parseClassMember_method_gftReturnType_voidReturnType() {
821 createParser('''
822 void Function<A>(core.List<core.int> x) m() => null;
823 ''');
824 ClassMember member = parser.parseClassMember('C');
825 assertNoErrors();
826 expect(member, new isInstanceOf<MethodDeclaration>());
827 expect((member as MethodDeclaration).body,
828 new isInstanceOf<ExpressionFunctionBody>());
829 }
830
787 void test_parseClassMember_method_native() { 831 void test_parseClassMember_method_native() {
788 createParser('m() native "str";'); 832 createParser('m() native "str";');
789 var method = parser.parseClassMember('C') as MethodDeclaration; 833 var method = parser.parseClassMember('C') as MethodDeclaration;
790 assertNoErrors(); 834 assertNoErrors();
791 835
792 var body = method.body as NativeFunctionBody; 836 var body = method.body as NativeFunctionBody;
793 expect(body.nativeKeyword, isNotNull); 837 expect(body.nativeKeyword, isNotNull);
794 expect(body.stringLiteral, isNotNull); 838 expect(body.stringLiteral, isNotNull);
795 expect(body.semicolon, isNotNull); 839 expect(body.semicolon, isNotNull);
796 } 840 }
(...skipping 9230 matching lines...) Expand 10 before | Expand all | Expand 10 after
10027 10071
10028 void test_parseArgumentList_trailing_comma() { 10072 void test_parseArgumentList_trailing_comma() {
10029 createParser('(x, y, z,)'); 10073 createParser('(x, y, z,)');
10030 ArgumentList argumentList = parser.parseArgumentList(); 10074 ArgumentList argumentList = parser.parseArgumentList();
10031 expectNotNullIfNoErrors(argumentList); 10075 expectNotNullIfNoErrors(argumentList);
10032 listener.assertNoErrors(); 10076 listener.assertNoErrors();
10033 NodeList<Expression> arguments = argumentList.arguments; 10077 NodeList<Expression> arguments = argumentList.arguments;
10034 expect(arguments, hasLength(3)); 10078 expect(arguments, hasLength(3));
10035 } 10079 }
10036 10080
10037 void test_parseClassMember_field_gftType_gftReturnType() {
10038 createParser('''
10039 Function(int) Function(String) v;
10040 ''');
10041 ClassMember member = parser.parseClassMember('C');
10042 listener.assertNoErrors();
10043 expect(member, new isInstanceOf<FieldDeclaration>());
10044 VariableDeclarationList fields = (member as FieldDeclaration).fields;
10045 expect(fields.type, new isInstanceOf<GenericFunctionType>());
10046 }
10047
10048 void test_parseClassMember_field_gftType_noReturnType() {
10049 createParser('''
10050 Function(int, String) v;
10051 ''');
10052 ClassMember member = parser.parseClassMember('C');
10053 listener.assertNoErrors();
10054 expect(member, new isInstanceOf<FieldDeclaration>());
10055 VariableDeclarationList fields = (member as FieldDeclaration).fields;
10056 expect(fields.type, new isInstanceOf<GenericFunctionType>());
10057 }
10058
10059 void test_parseClassMember_method_gftReturnType() {
10060 createParser('''
10061 void Function<A>(core.List<core.int> x) m() => null;
10062 ''');
10063 ClassMember member = parser.parseClassMember('C');
10064 listener.assertNoErrors();
10065 expect(member, new isInstanceOf<MethodDeclaration>());
10066 expect((member as MethodDeclaration).body,
10067 new isInstanceOf<ExpressionFunctionBody>());
10068 }
10069
10070 void test_parseClassMember_method_noReturnType() {
10071 createParser('''
10072 Function<A>(core.List<core.int> x) m() => null;
10073 ''');
10074 ClassMember member = parser.parseClassMember('C');
10075 listener.assertNoErrors();
10076 expect(member, new isInstanceOf<MethodDeclaration>());
10077 expect((member as MethodDeclaration).body,
10078 new isInstanceOf<ExpressionFunctionBody>());
10079 }
10080
10081 void test_parseCombinator_hide() { 10081 void test_parseCombinator_hide() {
10082 createParser('hide a;'); 10082 createParser('hide a;');
10083 Combinator combinator = parser.parseCombinator(); 10083 Combinator combinator = parser.parseCombinator();
10084 expectNotNullIfNoErrors(combinator); 10084 expectNotNullIfNoErrors(combinator);
10085 listener.assertNoErrors(); 10085 listener.assertNoErrors();
10086 expect(combinator, new isInstanceOf<HideCombinator>()); 10086 expect(combinator, new isInstanceOf<HideCombinator>());
10087 HideCombinator hideCombinator = combinator; 10087 HideCombinator hideCombinator = combinator;
10088 expect(hideCombinator.keyword, isNotNull); 10088 expect(hideCombinator.keyword, isNotNull);
10089 expect(hideCombinator.hiddenNames, hasLength(1)); 10089 expect(hideCombinator.hiddenNames, hasLength(1));
10090 } 10090 }
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
10671 List<CommentReference> references = parser.parseCommentReferences(tokens); 10671 List<CommentReference> references = parser.parseCommentReferences(tokens);
10672 expectNotNullIfNoErrors(references); 10672 expectNotNullIfNoErrors(references);
10673 listener.assertNoErrors(); 10673 listener.assertNoErrors();
10674 expect(references, hasLength(1)); 10674 expect(references, hasLength(1));
10675 CommentReference reference = references[0]; 10675 CommentReference reference = references[0];
10676 expect(reference, isNotNull); 10676 expect(reference, isNotNull);
10677 expect(reference.identifier, isNotNull); 10677 expect(reference.identifier, isNotNull);
10678 expect(reference.offset, 15); 10678 expect(reference.offset, 15);
10679 } 10679 }
10680 10680
10681 void test_parseCompilationUnitMember_function_gftReturnType() {
10682 createParser('''
10683 void Function<A>(core.List<core.int> x) f() => null;
10684 ''');
10685 CompilationUnit unit = parser.parseCompilationUnit2();
10686 listener.assertNoErrors();
10687 expect(unit, isNotNull);
10688 expect(unit.declarations, hasLength(1));
10689 }
10690
10691 void test_parseCompilationUnitMember_function_noReturnType() {
10692 createParser('''
10693 Function<A>(core.List<core.int> x) f() => null;
10694 ''');
10695 CompilationUnit unit = parser.parseCompilationUnit2();
10696 listener.assertNoErrors();
10697 expect(unit, isNotNull);
10698 expect(unit.declarations, hasLength(1));
10699 }
10700
10701 void test_parseCompilationUnitMember_variable_gftType_gftReturnType() {
10702 createParser('''
10703 Function(int) Function(String) v;
10704 ''');
10705 CompilationUnit unit = parser.parseCompilationUnit2();
10706 listener.assertNoErrors();
10707 expect(unit, isNotNull);
10708 expect(unit.declarations, hasLength(1));
10709 TopLevelVariableDeclaration declaration =
10710 unit.declarations[0] as TopLevelVariableDeclaration;
10711 expect(declaration.variables.type, new isInstanceOf<GenericFunctionType>());
10712 }
10713
10714 void test_parseCompilationUnitMember_variable_gftType_noReturnType() {
10715 createParser('''
10716 Function(int, String) v;
10717 ''');
10718 CompilationUnit unit = parser.parseCompilationUnit2();
10719 listener.assertNoErrors();
10720 expect(unit, isNotNull);
10721 expect(unit.declarations, hasLength(1));
10722 }
10723
10724 void test_parseConfiguration_noOperator_dottedIdentifier() { 10681 void test_parseConfiguration_noOperator_dottedIdentifier() {
10725 createParser("if (a.b) 'c.dart'"); 10682 createParser("if (a.b) 'c.dart'");
10726 Configuration configuration = parser.parseConfiguration(); 10683 Configuration configuration = parser.parseConfiguration();
10727 expectNotNullIfNoErrors(configuration); 10684 expectNotNullIfNoErrors(configuration);
10728 listener.assertNoErrors(); 10685 listener.assertNoErrors();
10729 expect(configuration.ifKeyword, isNotNull); 10686 expect(configuration.ifKeyword, isNotNull);
10730 expect(configuration.leftParenthesis, isNotNull); 10687 expect(configuration.leftParenthesis, isNotNull);
10731 expectDottedName(configuration.name, ["a", "b"]); 10688 expectDottedName(configuration.name, ["a", "b"]);
10732 expect(configuration.equalToken, isNull); 10689 expect(configuration.equalToken, isNull);
10733 expect(configuration.value, isNull); 10690 expect(configuration.value, isNull);
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
11314 } 11271 }
11315 11272
11316 void test_parseModifiers_var() { 11273 void test_parseModifiers_var() {
11317 createParser('var A'); 11274 createParser('var A');
11318 Modifiers modifiers = parser.parseModifiers(); 11275 Modifiers modifiers = parser.parseModifiers();
11319 expectNotNullIfNoErrors(modifiers); 11276 expectNotNullIfNoErrors(modifiers);
11320 listener.assertNoErrors(); 11277 listener.assertNoErrors();
11321 expect(modifiers.varKeyword, isNotNull); 11278 expect(modifiers.varKeyword, isNotNull);
11322 } 11279 }
11323 11280
11324 void test_parseNonLabeledStatement_localFunction_gftReturnType() {
11325 createParser('int Function(int) f(String s) => null;');
11326 Statement statement = parser.parseNonLabeledStatement();
11327 expectNotNullIfNoErrors(statement);
11328 listener.assertNoErrors();
11329 }
11330
11331 void test_parseNonLabeledStatement_variableDeclaration_final_namedFunction() {
11332 createParser('final int Function = 0;');
11333 Statement statement = parser.parseNonLabeledStatement();
11334 expectNotNullIfNoErrors(statement);
11335 listener.assertNoErrors();
11336 }
11337
11338 void test_parseNonLabeledStatement_variableDeclaration_gftType() {
11339 createParser('int Function(int) v;');
11340 Statement statement = parser.parseNonLabeledStatement();
11341 expectNotNullIfNoErrors(statement);
11342 listener.assertNoErrors();
11343 }
11344
11345 void
11346 test_parseNonLabeledStatement_variableDeclaration_gftType_functionReturnTy pe() {
11347 createParser(
11348 'Function Function(int x1, {Function x}) Function<B extends core.int>(in t x) l771;');
11349 Statement statement = parser.parseNonLabeledStatement();
11350 expectNotNullIfNoErrors(statement);
11351 listener.assertNoErrors();
11352 }
11353
11354 void
11355 test_parseNonLabeledStatement_variableDeclaration_gftType_gftReturnType() {
11356 createParser('Function(int) Function(int) v;');
11357 Statement statement = parser.parseNonLabeledStatement();
11358 expectNotNullIfNoErrors(statement);
11359 listener.assertNoErrors();
11360 }
11361
11362 void
11363 test_parseNonLabeledStatement_variableDeclaration_gftType_gftReturnType2() {
11364 createParser('int Function(int) Function(int) v;');
11365 Statement statement = parser.parseNonLabeledStatement();
11366 expectNotNullIfNoErrors(statement);
11367 listener.assertNoErrors();
11368 }
11369
11370 void
11371 test_parseNonLabeledStatement_variableDeclaration_gftType_noReturnType() {
11372 createParser('Function(int) v;');
11373 Statement statement = parser.parseNonLabeledStatement();
11374 expectNotNullIfNoErrors(statement);
11375 listener.assertNoErrors();
11376 }
11377
11378 void test_parseNonLabeledStatement_variableDeclaration_gftType_returnType() {
11379 createParser('int Function<T>() v;');
11380 Statement statement = parser.parseNonLabeledStatement();
11381 expectNotNullIfNoErrors(statement);
11382 listener.assertNoErrors();
11383 }
11384
11385 void
11386 test_parseNonLabeledStatement_variableDeclaration_gftType_voidReturnType() {
11387 createParser('void Function() v;');
11388 Statement statement = parser.parseNonLabeledStatement();
11389 expectNotNullIfNoErrors(statement);
11390 listener.assertNoErrors();
11391 }
11392
11393 void test_parseOptionalReturnType() { 11281 void test_parseOptionalReturnType() {
11394 // TODO(brianwilkerson) Implement tests for this method. 11282 // TODO(brianwilkerson) Implement tests for this method.
11395 } 11283 }
11396 11284
11397 void test_Parser() { 11285 void test_Parser() {
11398 expect(new Parser(null, null), isNotNull); 11286 expect(new Parser(null, null), isNotNull);
11399 } 11287 }
11400 11288
11401 void test_parseReturnStatement_noValue() { 11289 void test_parseReturnStatement_noValue() {
11402 createParser('return;'); 11290 createParser('return;');
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
11439 11327
11440 void test_parseReturnType_void() { 11328 void test_parseReturnType_void() {
11441 createParser('void'); 11329 createParser('void');
11442 TypeName typeName = parser.parseReturnType(false); 11330 TypeName typeName = parser.parseReturnType(false);
11443 expectNotNullIfNoErrors(typeName); 11331 expectNotNullIfNoErrors(typeName);
11444 listener.assertNoErrors(); 11332 listener.assertNoErrors();
11445 expect(typeName.name, isNotNull); 11333 expect(typeName.name, isNotNull);
11446 expect(typeName.typeArguments, isNull); 11334 expect(typeName.typeArguments, isNull);
11447 } 11335 }
11448 11336
11449 void test_parseStatement_function_gftReturnType() {
11450 createParser('''
11451 void Function<A>(core.List<core.int> x) m() => null;
11452 ''');
11453 Statement statement = parser.parseStatement2();
11454 expect(statement, new isInstanceOf<FunctionDeclarationStatement>());
11455 expect(
11456 (statement as FunctionDeclarationStatement)
11457 .functionDeclaration
11458 .functionExpression
11459 .body,
11460 new isInstanceOf<ExpressionFunctionBody>());
11461 }
11462
11463 void test_parseStatement_function_noReturnType() { 11337 void test_parseStatement_function_noReturnType() {
11464 createParser(''' 11338 createParser('''
11465 Function<A>(core.List<core.int> x) m() => null; 11339 Function<A>(core.List<core.int> x) m() => null;
11466 '''); 11340 ''');
11467 Statement statement = parser.parseStatement2(); 11341 Statement statement = parser.parseStatement2();
11468 expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); 11342 expect(statement, new isInstanceOf<FunctionDeclarationStatement>());
11469 expect( 11343 expect(
11470 (statement as FunctionDeclarationStatement) 11344 (statement as FunctionDeclarationStatement)
11471 .functionDeclaration 11345 .functionDeclaration
11472 .functionExpression 11346 .functionExpression
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
12678 assertNoErrors(); 12552 assertNoErrors();
12679 var invocation = statement.expression as FunctionExpressionInvocation; 12553 var invocation = statement.expression as FunctionExpressionInvocation;
12680 12554
12681 FunctionExpression expression = invocation.function as FunctionExpression; 12555 FunctionExpression expression = invocation.function as FunctionExpression;
12682 expect(expression.parameters, isNotNull); 12556 expect(expression.parameters, isNotNull);
12683 expect(expression.body, isNotNull); 12557 expect(expression.body, isNotNull);
12684 expect(invocation.typeArguments, isNull); 12558 expect(invocation.typeArguments, isNull);
12685 expect(invocation.argumentList.arguments, hasLength(1)); 12559 expect(invocation.argumentList.arguments, hasLength(1));
12686 } 12560 }
12687 12561
12562 void test_parseNonLabeledStatement_localFunction_gftReturnType() {
12563 var statement = parseStatement('int Function(int) f(String s) => null;')
12564 as FunctionDeclarationStatement;
12565 assertNoErrors();
12566 FunctionDeclaration function = statement.functionDeclaration;
12567 expect(function.returnType, new isInstanceOf<GenericFunctionType>());
12568 }
12569
12688 void test_parseNonLabeledStatement_null() { 12570 void test_parseNonLabeledStatement_null() {
12689 var statement = parseStatement('null;') as ExpressionStatement; 12571 var statement = parseStatement('null;') as ExpressionStatement;
12690 assertNoErrors(); 12572 assertNoErrors();
12691 expect(statement.expression, isNotNull); 12573 expect(statement.expression, isNotNull);
12692 } 12574 }
12693 12575
12694 void test_parseNonLabeledStatement_startingWithBuiltInIdentifier() { 12576 void test_parseNonLabeledStatement_startingWithBuiltInIdentifier() {
12695 var statement = parseStatement('library.getName();') as ExpressionStatement; 12577 var statement = parseStatement('library.getName();') as ExpressionStatement;
12696 assertNoErrors(); 12578 assertNoErrors();
12697 expect(statement.expression, isNotNull); 12579 expect(statement.expression, isNotNull);
12698 } 12580 }
12699 12581
12700 void test_parseNonLabeledStatement_true() { 12582 void test_parseNonLabeledStatement_true() {
12701 var statement = parseStatement('true;') as ExpressionStatement; 12583 var statement = parseStatement('true;') as ExpressionStatement;
12702 assertNoErrors(); 12584 assertNoErrors();
12703 expect(statement.expression, isNotNull); 12585 expect(statement.expression, isNotNull);
12704 } 12586 }
12705 12587
12706 void test_parseNonLabeledStatement_typeCast() { 12588 void test_parseNonLabeledStatement_typeCast() {
12707 var statement = parseStatement('double.NAN as num;') as ExpressionStatement; 12589 var statement = parseStatement('double.NAN as num;') as ExpressionStatement;
12708 assertNoErrors(); 12590 assertNoErrors();
12709 expect(statement.expression, isNotNull); 12591 expect(statement.expression, isNotNull);
12710 } 12592 }
12711 12593
12594 void test_parseNonLabeledStatement_variableDeclaration_final_namedFunction() {
12595 var statement = parseStatement('final int Function = 0;')
12596 as VariableDeclarationStatement;
12597 assertNoErrors();
12598 List<VariableDeclaration> variables = statement.variables.variables;
12599 expect(variables, hasLength(1));
12600 expect(variables[0].name.name, 'Function');
12601 }
12602
12603 void test_parseNonLabeledStatement_variableDeclaration_gftType() {
12604 var statement =
12605 parseStatement('int Function(int) v;') as VariableDeclarationStatement;
12606 assertNoErrors();
12607 VariableDeclarationList variableList = statement.variables;
12608 List<VariableDeclaration> variables = variableList.variables;
12609 expect(variables, hasLength(1));
12610 expect(variables[0].name.name, 'v');
12611 expect(variableList.type, new isInstanceOf<GenericFunctionType>());
12612 }
12613
12614 void
12615 test_parseNonLabeledStatement_variableDeclaration_gftType_functionReturnTy pe() {
12616 var statement = parseStatement(
12617 'Function Function(int x1, {Function x}) Function<B extends core.int >(int x) v;')
12618 as VariableDeclarationStatement;
12619 assertNoErrors();
12620 VariableDeclarationList variableList = statement.variables;
12621 List<VariableDeclaration> variables = variableList.variables;
12622 expect(variables, hasLength(1));
12623 expect(variables[0].name.name, 'v');
12624 expect(variableList.type, new isInstanceOf<GenericFunctionType>());
12625 }
12626
12627 void
12628 test_parseNonLabeledStatement_variableDeclaration_gftType_gftReturnType() {
12629 var statement = parseStatement('Function(int) Function(int) v;')
12630 as VariableDeclarationStatement;
12631 assertNoErrors();
12632 VariableDeclarationList variableList = statement.variables;
12633 List<VariableDeclaration> variables = variableList.variables;
12634 expect(variables, hasLength(1));
12635 expect(variables[0].name.name, 'v');
12636 expect(variableList.type, new isInstanceOf<GenericFunctionType>());
12637 }
12638
12639 void
12640 test_parseNonLabeledStatement_variableDeclaration_gftType_gftReturnType2() {
12641 var statement = parseStatement('int Function(int) Function(int) v;')
12642 as VariableDeclarationStatement;
12643 assertNoErrors();
12644 VariableDeclarationList variableList = statement.variables;
12645 List<VariableDeclaration> variables = variableList.variables;
12646 expect(variables, hasLength(1));
12647 expect(variables[0].name.name, 'v');
12648 expect(variableList.type, new isInstanceOf<GenericFunctionType>());
12649 }
12650
12651 void
12652 test_parseNonLabeledStatement_variableDeclaration_gftType_noReturnType() {
12653 var statement =
12654 parseStatement('Function(int) v;') as VariableDeclarationStatement;
12655 assertNoErrors();
12656 VariableDeclarationList variableList = statement.variables;
12657 List<VariableDeclaration> variables = variableList.variables;
12658 expect(variables, hasLength(1));
12659 expect(variables[0].name.name, 'v');
12660 expect(variableList.type, new isInstanceOf<GenericFunctionType>());
12661 }
12662
12663 void test_parseNonLabeledStatement_variableDeclaration_gftType_returnType() {
12664 var statement =
12665 parseStatement('int Function<T>() v;') as VariableDeclarationStatement;
12666 assertNoErrors();
12667 VariableDeclarationList variableList = statement.variables;
12668 List<VariableDeclaration> variables = variableList.variables;
12669 expect(variables, hasLength(1));
12670 expect(variables[0].name.name, 'v');
12671 expect(variableList.type, new isInstanceOf<GenericFunctionType>());
12672 }
12673
12674 void
12675 test_parseNonLabeledStatement_variableDeclaration_gftType_voidReturnType() {
12676 var statement =
12677 parseStatement('void Function() v;') as VariableDeclarationStatement;
12678 assertNoErrors();
12679 VariableDeclarationList variableList = statement.variables;
12680 List<VariableDeclaration> variables = variableList.variables;
12681 expect(variables, hasLength(1));
12682 expect(variables[0].name.name, 'v');
12683 expect(variableList.type, new isInstanceOf<GenericFunctionType>());
12684 }
12685
12712 void test_parseStatement_emptyTypeArgumentList() { 12686 void test_parseStatement_emptyTypeArgumentList() {
12713 var declaration = parseStatement('C<> c;') as VariableDeclarationStatement; 12687 var declaration = parseStatement('C<> c;') as VariableDeclarationStatement;
12714 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TYPE_NAME]); 12688 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TYPE_NAME]);
12715 VariableDeclarationList variables = declaration.variables; 12689 VariableDeclarationList variables = declaration.variables;
12716 TypeName type = variables.type; 12690 TypeName type = variables.type;
12717 TypeArgumentList argumentList = type.typeArguments; 12691 TypeArgumentList argumentList = type.typeArguments;
12718 expect(argumentList.leftBracket, isNotNull); 12692 expect(argumentList.leftBracket, isNotNull);
12719 expect(argumentList.arguments, hasLength(1)); 12693 expect(argumentList.arguments, hasLength(1));
12720 expect(argumentList.arguments[0].isSynthetic, isTrue); 12694 expect(argumentList.arguments[0].isSynthetic, isTrue);
12721 expect(argumentList.rightBracket, isNotNull); 12695 expect(argumentList.rightBracket, isNotNull);
12722 } 12696 }
12723 12697
12698 void test_parseStatement_function_gftReturnType() {
12699 var statement =
12700 parseStatement('void Function<A>(core.List<core.int> x) m() => null;')
12701 as FunctionDeclarationStatement;
12702 expect(statement.functionDeclaration.functionExpression.body,
12703 new isInstanceOf<ExpressionFunctionBody>());
12704 }
12705
12724 void test_parseStatement_functionDeclaration_noReturnType() { 12706 void test_parseStatement_functionDeclaration_noReturnType() {
12725 var statement = parseStatement('true;') as ExpressionStatement; 12707 var statement = parseStatement('true;') as ExpressionStatement;
12726 assertNoErrors(); 12708 assertNoErrors();
12727 expect(statement.expression, isNotNull); 12709 expect(statement.expression, isNotNull);
12728 } 12710 }
12729 12711
12730 void 12712 void
12731 test_parseStatement_functionDeclaration_noReturnType_typeParameterComments () { 12713 test_parseStatement_functionDeclaration_noReturnType_typeParameterComments () {
12732 enableGenericMethodComments = true; 12714 enableGenericMethodComments = true;
12733 var statement = 12715 var statement =
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
13752 createParser('void f<T>(T t) {}'); 13734 createParser('void f<T>(T t) {}');
13753 CompilationUnitMember member = parseFullCompilationUnitMember(); 13735 CompilationUnitMember member = parseFullCompilationUnitMember();
13754 expect(member, isNotNull); 13736 expect(member, isNotNull);
13755 assertNoErrors(); 13737 assertNoErrors();
13756 expect(member, new isInstanceOf<FunctionDeclaration>()); 13738 expect(member, new isInstanceOf<FunctionDeclaration>());
13757 FunctionDeclaration declaration = member; 13739 FunctionDeclaration declaration = member;
13758 expect(declaration.functionExpression, isNotNull); 13740 expect(declaration.functionExpression, isNotNull);
13759 expect(declaration.propertyKeyword, isNull); 13741 expect(declaration.propertyKeyword, isNull);
13760 } 13742 }
13761 13743
13744 void test_parseCompilationUnitMember_function_gftReturnType() {
13745 createParser('''
13746 void Function<A>(core.List<core.int> x) f() => null;
13747 ''');
13748 CompilationUnit unit = parser.parseCompilationUnit2();
13749 assertNoErrors();
13750 expect(unit, isNotNull);
13751 expect(unit.declarations, hasLength(1));
13752 }
13753
13754 void test_parseCompilationUnitMember_function_noReturnType() {
13755 createParser('''
13756 Function<A>(core.List<core.int> x) f() => null;
13757 ''');
13758 CompilationUnit unit = parser.parseCompilationUnit2();
13759 assertNoErrors();
13760 expect(unit, isNotNull);
13761 expect(unit.declarations, hasLength(1));
13762 }
13763
13762 void test_parseCompilationUnitMember_function_noType() { 13764 void test_parseCompilationUnitMember_function_noType() {
13763 createParser('f() {}'); 13765 createParser('f() {}');
13764 CompilationUnitMember member = parseFullCompilationUnitMember(); 13766 CompilationUnitMember member = parseFullCompilationUnitMember();
13765 expect(member, isNotNull); 13767 expect(member, isNotNull);
13766 assertNoErrors(); 13768 assertNoErrors();
13767 expect(member, new isInstanceOf<FunctionDeclaration>()); 13769 expect(member, new isInstanceOf<FunctionDeclaration>());
13768 FunctionDeclaration declaration = member; 13770 FunctionDeclaration declaration = member;
13769 expect(declaration.functionExpression, isNotNull); 13771 expect(declaration.functionExpression, isNotNull);
13770 expect(declaration.propertyKeyword, isNull); 13772 expect(declaration.propertyKeyword, isNull);
13771 } 13773 }
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
13996 CompilationUnitMember member = parseFullCompilationUnitMember(); 13998 CompilationUnitMember member = parseFullCompilationUnitMember();
13997 expect(member, isNotNull); 13999 expect(member, isNotNull);
13998 assertNoErrors(); 14000 assertNoErrors();
13999 expect(member, new isInstanceOf<TopLevelVariableDeclaration>()); 14001 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
14000 TopLevelVariableDeclaration declaration = member; 14002 TopLevelVariableDeclaration declaration = member;
14001 expect(declaration.semicolon, isNotNull); 14003 expect(declaration.semicolon, isNotNull);
14002 expect(declaration.variables, isNotNull); 14004 expect(declaration.variables, isNotNull);
14003 expect(declaration.variables.keyword.lexeme, 'var'); 14005 expect(declaration.variables.keyword.lexeme, 'var');
14004 } 14006 }
14005 14007
14008 void test_parseCompilationUnitMember_variable_gftType_gftReturnType() {
14009 createParser('''
14010 Function(int) Function(String) v;
14011 ''');
14012 CompilationUnit unit = parser.parseCompilationUnit2();
14013 assertNoErrors();
14014 expect(unit, isNotNull);
14015 expect(unit.declarations, hasLength(1));
14016 TopLevelVariableDeclaration declaration =
14017 unit.declarations[0] as TopLevelVariableDeclaration;
14018 expect(declaration.variables.type, new isInstanceOf<GenericFunctionType>());
14019 }
14020
14021 void test_parseCompilationUnitMember_variable_gftType_noReturnType() {
14022 createParser('''
14023 Function(int, String) v;
14024 ''');
14025 CompilationUnit unit = parser.parseCompilationUnit2();
14026 assertNoErrors();
14027 expect(unit, isNotNull);
14028 expect(unit.declarations, hasLength(1));
14029 }
14030
14006 void test_parseCompilationUnitMember_variable_withDocumentationComment() { 14031 void test_parseCompilationUnitMember_variable_withDocumentationComment() {
14007 createParser('/// Doc\nvar x = 0;'); 14032 createParser('/// Doc\nvar x = 0;');
14008 var declaration = 14033 var declaration =
14009 parseFullCompilationUnitMember() as TopLevelVariableDeclaration; 14034 parseFullCompilationUnitMember() as TopLevelVariableDeclaration;
14010 expectCommentText(declaration.documentationComment, '/// Doc'); 14035 expectCommentText(declaration.documentationComment, '/// Doc');
14011 } 14036 }
14012 14037
14013 void test_parseCompilationUnitMember_variableGet() { 14038 void test_parseCompilationUnitMember_variableGet() {
14014 createParser('String get = null;'); 14039 createParser('String get = null;');
14015 CompilationUnitMember member = parseFullCompilationUnitMember(); 14040 CompilationUnitMember member = parseFullCompilationUnitMember();
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
14921 expectCommentText(typeVariable.documentationComment, '/// Doc'); 14946 expectCommentText(typeVariable.documentationComment, '/// Doc');
14922 } 14947 }
14923 14948
14924 /** 14949 /**
14925 * Assert that the given [name] is in declaration context. 14950 * Assert that the given [name] is in declaration context.
14926 */ 14951 */
14927 void _assertIsDeclarationName(SimpleIdentifier name) { 14952 void _assertIsDeclarationName(SimpleIdentifier name) {
14928 expect(name.inDeclarationContext(), isTrue); 14953 expect(name.inDeclarationContext(), isTrue);
14929 } 14954 }
14930 } 14955 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698