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/visitor.dart'; | 8 import 'package:analyzer/dart/ast/visitor.dart'; |
9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
(...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1511 ParserErrorCode.EXPECTED_TOKEN /*>*/, | 1511 ParserErrorCode.EXPECTED_TOKEN /*>*/, |
1512 ParserErrorCode.MISSING_IDENTIFIER, | 1512 ParserErrorCode.MISSING_IDENTIFIER, |
1513 ParserErrorCode.EXPECTED_TOKEN /*(*/, | 1513 ParserErrorCode.EXPECTED_TOKEN /*(*/, |
1514 ParserErrorCode.EXPECTED_TOKEN /*)*/, | 1514 ParserErrorCode.EXPECTED_TOKEN /*)*/, |
1515 ParserErrorCode.MISSING_FUNCTION_BODY | 1515 ParserErrorCode.MISSING_FUNCTION_BODY |
1516 ]); | 1516 ]); |
1517 expect(method.typeParameters.toString(), '<E, hello>', | 1517 expect(method.typeParameters.toString(), '<E, hello>', |
1518 reason: 'parser recovers what it can'); | 1518 reason: 'parser recovers what it can'); |
1519 } | 1519 } |
1520 | 1520 |
1521 void test_method_invalidTypeParameterExtends() { | |
1522 // Regression test for https://github.com/dart-lang/sdk/issues/25739. | |
1523 | |
1524 // TODO(jmesserly): ideally we'd be better at parser recovery here. | |
1525 enableGenericMethods = true; | |
1526 MethodDeclaration method = parse3( | |
1527 "parseClassMember", | |
1528 <Object>["C"], | |
1529 "f<E>(E extends num p);", | |
1530 [ | |
1531 ParserErrorCode.MISSING_IDENTIFIER, // `extends` is a keyword | |
1532 ParserErrorCode.EXPECTED_TOKEN, // comma | |
1533 ParserErrorCode.EXPECTED_TOKEN, // close paren | |
1534 ParserErrorCode.MISSING_FUNCTION_BODY | |
1535 ]); | |
1536 expect(method.parameters.toString(), '(E, extends)', | |
1537 reason: 'parser recovers what it can'); | |
1538 } | |
1539 | |
1540 | |
1541 void test_method_invalidTypeParameterExtendsComment() { | |
1542 // Regression test for https://github.com/dart-lang/sdk/issues/25739. | |
1543 | |
1544 // TODO(jmesserly): ideally we'd be better at parser recovery here. | |
1545 // Also, this behavior is slightly different from how we would parse a | |
1546 // normal generic method, because we "discover" the comment at a different | |
1547 // point in the parser. This has a slight effect on the AST that results | |
1548 // from error recovery. | |
1549 enableGenericMethodComments = true; | |
1550 MethodDeclaration method = parse3( | |
1551 "parseClassMember", | |
1552 <Object>["C"], | |
1553 "f/*<E>*/(dynamic/*=E extends num*/p);", | |
Brian Wilkerson
2016/02/12 17:56:55
When we're inserting the tokens from the comment,
| |
1554 [ | |
1555 ParserErrorCode.MISSING_IDENTIFIER, // `extends` is a keyword | |
1556 ParserErrorCode.EXPECTED_TOKEN, // comma | |
1557 ParserErrorCode.MISSING_IDENTIFIER, // `extends` is a keyword | |
1558 ParserErrorCode.EXPECTED_TOKEN, // close paren | |
1559 ParserErrorCode.MISSING_FUNCTION_BODY | |
1560 ]); | |
1561 expect(method.parameters.toString(), '(E extends, extends)', | |
Brian Wilkerson
2016/02/12 17:56:55
I don't think this actually tests that the comment
| |
1562 reason: 'parser recovers what it can'); | |
1563 } | |
1564 | |
1521 void test_missingAssignableSelector_identifiersAssigned() { | 1565 void test_missingAssignableSelector_identifiersAssigned() { |
1522 parseExpression("x.y = y;"); | 1566 parseExpression("x.y = y;"); |
1523 } | 1567 } |
1524 | 1568 |
1525 void test_missingAssignableSelector_prefix_minusMinus_literal() { | 1569 void test_missingAssignableSelector_prefix_minusMinus_literal() { |
1526 parseExpression("--0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); | 1570 parseExpression("--0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); |
1527 } | 1571 } |
1528 | 1572 |
1529 void test_missingAssignableSelector_prefix_plusPlus_literal() { | 1573 void test_missingAssignableSelector_prefix_plusPlus_literal() { |
1530 parseExpression("++0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); | 1574 parseExpression("++0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); |
(...skipping 9971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11502 new Scanner(null, new CharSequenceReader(source), listener); | 11546 new Scanner(null, new CharSequenceReader(source), listener); |
11503 Token tokenStream = scanner.tokenize(); | 11547 Token tokenStream = scanner.tokenize(); |
11504 // | 11548 // |
11505 // Parse the source. | 11549 // Parse the source. |
11506 // | 11550 // |
11507 Parser parser = new Parser(null, listener); | 11551 Parser parser = new Parser(null, listener); |
11508 return invokeParserMethodImpl( | 11552 return invokeParserMethodImpl( |
11509 parser, methodName, <Object>[tokenStream], tokenStream) as Token; | 11553 parser, methodName, <Object>[tokenStream], tokenStream) as Token; |
11510 } | 11554 } |
11511 } | 11555 } |
OLD | NEW |