OLD | NEW |
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/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
9 import 'package:analyzer/dart/ast/visitor.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
(...skipping 1513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1524 ParserErrorCode.EXPECTED_TOKEN /*>*/, | 1524 ParserErrorCode.EXPECTED_TOKEN /*>*/, |
1525 ParserErrorCode.MISSING_IDENTIFIER, | 1525 ParserErrorCode.MISSING_IDENTIFIER, |
1526 ParserErrorCode.EXPECTED_TOKEN /*(*/, | 1526 ParserErrorCode.EXPECTED_TOKEN /*(*/, |
1527 ParserErrorCode.EXPECTED_TOKEN /*)*/, | 1527 ParserErrorCode.EXPECTED_TOKEN /*)*/, |
1528 ParserErrorCode.MISSING_FUNCTION_BODY | 1528 ParserErrorCode.MISSING_FUNCTION_BODY |
1529 ]); | 1529 ]); |
1530 expect(method.typeParameters.toString(), '<E, hello>', | 1530 expect(method.typeParameters.toString(), '<E, hello>', |
1531 reason: 'parser recovers what it can'); | 1531 reason: 'parser recovers what it can'); |
1532 } | 1532 } |
1533 | 1533 |
| 1534 void test_method_invalidTypeParameterExtends() { |
| 1535 // Regression test for https://github.com/dart-lang/sdk/issues/25739. |
| 1536 |
| 1537 // TODO(jmesserly): ideally we'd be better at parser recovery here. |
| 1538 enableGenericMethods = true; |
| 1539 MethodDeclaration method = parse3( |
| 1540 "parseClassMember", |
| 1541 <Object>["C"], |
| 1542 "f<E>(E extends num p);", |
| 1543 [ |
| 1544 ParserErrorCode.MISSING_IDENTIFIER, // `extends` is a keyword |
| 1545 ParserErrorCode.EXPECTED_TOKEN, // comma |
| 1546 ParserErrorCode.EXPECTED_TOKEN, // close paren |
| 1547 ParserErrorCode.MISSING_FUNCTION_BODY |
| 1548 ]); |
| 1549 expect(method.parameters.toString(), '(E, extends)', |
| 1550 reason: 'parser recovers what it can'); |
| 1551 } |
| 1552 |
| 1553 |
| 1554 void test_method_invalidTypeParameterExtendsComment() { |
| 1555 // Regression test for https://github.com/dart-lang/sdk/issues/25739. |
| 1556 |
| 1557 // TODO(jmesserly): ideally we'd be better at parser recovery here. |
| 1558 // Also, this behavior is slightly different from how we would parse a |
| 1559 // normal generic method, because we "discover" the comment at a different |
| 1560 // point in the parser. This has a slight effect on the AST that results |
| 1561 // from error recovery. |
| 1562 enableGenericMethodComments = true; |
| 1563 MethodDeclaration method = parse3( |
| 1564 "parseClassMember", |
| 1565 <Object>["C"], |
| 1566 "f/*<E>*/(dynamic/*=E extends num*/p);", |
| 1567 [ |
| 1568 ParserErrorCode.MISSING_IDENTIFIER, // `extends` is a keyword |
| 1569 ParserErrorCode.EXPECTED_TOKEN, // comma |
| 1570 ParserErrorCode.MISSING_IDENTIFIER, // `extends` is a keyword |
| 1571 ParserErrorCode.EXPECTED_TOKEN, // close paren |
| 1572 ParserErrorCode.MISSING_FUNCTION_BODY |
| 1573 ]); |
| 1574 expect(method.parameters.toString(), '(E extends, extends)', |
| 1575 reason: 'parser recovers what it can'); |
| 1576 } |
| 1577 |
1534 void test_missingAssignableSelector_identifiersAssigned() { | 1578 void test_missingAssignableSelector_identifiersAssigned() { |
1535 parseExpression("x.y = y;"); | 1579 parseExpression("x.y = y;"); |
1536 } | 1580 } |
1537 | 1581 |
1538 void test_missingAssignableSelector_prefix_minusMinus_literal() { | 1582 void test_missingAssignableSelector_prefix_minusMinus_literal() { |
1539 parseExpression("--0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); | 1583 parseExpression("--0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); |
1540 } | 1584 } |
1541 | 1585 |
1542 void test_missingAssignableSelector_prefix_plusPlus_literal() { | 1586 void test_missingAssignableSelector_prefix_plusPlus_literal() { |
1543 parseExpression("++0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); | 1587 parseExpression("++0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); |
(...skipping 9995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11539 new Scanner(null, new CharSequenceReader(source), listener); | 11583 new Scanner(null, new CharSequenceReader(source), listener); |
11540 Token tokenStream = scanner.tokenize(); | 11584 Token tokenStream = scanner.tokenize(); |
11541 // | 11585 // |
11542 // Parse the source. | 11586 // Parse the source. |
11543 // | 11587 // |
11544 Parser parser = new Parser(null, listener); | 11588 Parser parser = new Parser(null, listener); |
11545 return invokeParserMethodImpl( | 11589 return invokeParserMethodImpl( |
11546 parser, methodName, <Object>[tokenStream], tokenStream) as Token; | 11590 parser, methodName, <Object>[tokenStream], tokenStream) as Token; |
11547 } | 11591 } |
11548 } | 11592 } |
OLD | NEW |