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

Unified Diff: pkg/analyzer/test/generated/parser_test.dart

Issue 1413773003: Improve recovery for local variable declarations. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/parser_test.dart
diff --git a/pkg/analyzer/test/generated/parser_test.dart b/pkg/analyzer/test/generated/parser_test.dart
index 98e80de36f5522bf50147d2a8d31bbfa39935ccf..3f8a6616650a638b3142dffe6962480b14273eda 100644
--- a/pkg/analyzer/test/generated/parser_test.dart
+++ b/pkg/analyzer/test/generated/parser_test.dart
@@ -3221,6 +3221,17 @@ class B = Object with A {}''',
expect(expression.thenExpression.isSynthetic, isTrue);
}
+ void test_declarationBeforeDirective() {
+ CompilationUnit unit = ParserTestCase.parseCompilationUnit(
+ "class foo { } import 'bar.dart';",
+ [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]);
+ expect(unit.directives, hasLength(1));
+ expect(unit.declarations, hasLength(1));
+ ClassDeclaration classDecl = unit.childEntities.first;
+ expect(classDecl, isNotNull);
+ expect(classDecl.name.name, 'foo');
+ }
+
void test_equalityExpression_missing_LHS() {
BinaryExpression expression =
parseExpression("== y", [ParserErrorCode.MISSING_IDENTIFIER]);
@@ -3338,17 +3349,6 @@ class B = Object with A {}''',
parseExpression("m(f() => 0);", [ParserErrorCode.EXPECTED_TOKEN]);
}
- void test_declarationBeforeDirective() {
- CompilationUnit unit = ParserTestCase.parseCompilationUnit(
- "class foo { } import 'bar.dart';",
- [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]);
- expect(unit.directives, hasLength(1));
- expect(unit.declarations, hasLength(1));
- ClassDeclaration classDecl = unit.childEntities.first;
- expect(classDecl, isNotNull);
- expect(classDecl.name.name, 'foo');
- }
-
void test_importDirectivePartial_as() {
CompilationUnit unit = ParserTestCase.parseCompilationUnit(
"import 'b.dart' d as b;", [ParserErrorCode.UNEXPECTED_TOKEN]);
@@ -3549,6 +3549,41 @@ class C {
expect(field.name.isSynthetic, isTrue);
}
+ void test_incompleteLocalVariable_atTheEndOfBlock() {
+ Statement statement = ParserTestCase.parseStatement(
+ 'String v }', [ParserErrorCode.EXPECTED_TOKEN]);
+ expect(statement, new isInstanceOf<VariableDeclarationStatement>());
+ expect(statement.toSource(), 'String v;');
+ }
+
+ void test_incompleteLocalVariable_beforeIdentifier() {
+ Statement statement = ParserTestCase.parseStatement(
+ 'String v String v2;', [ParserErrorCode.EXPECTED_TOKEN]);
+ expect(statement, new isInstanceOf<VariableDeclarationStatement>());
+ expect(statement.toSource(), 'String v;');
+ }
+
+ void test_incompleteLocalVariable_beforeKeyword() {
+ Statement statement = ParserTestCase.parseStatement(
+ 'String v if (true) {}', [ParserErrorCode.EXPECTED_TOKEN]);
+ expect(statement, new isInstanceOf<VariableDeclarationStatement>());
+ expect(statement.toSource(), 'String v;');
+ }
+
+ void test_incompleteLocalVariable_beforeNextBlock() {
+ Statement statement = ParserTestCase.parseStatement(
+ 'String v {}', [ParserErrorCode.EXPECTED_TOKEN]);
+ expect(statement, new isInstanceOf<VariableDeclarationStatement>());
+ expect(statement.toSource(), 'String v;');
+ }
+
+ void test_incompleteLocalVariable_parameterizedType() {
+ Statement statement = ParserTestCase.parseStatement(
+ 'List<String> v {}', [ParserErrorCode.EXPECTED_TOKEN]);
+ expect(statement, new isInstanceOf<VariableDeclarationStatement>());
+ expect(statement.toSource(), 'List<String> v;');
+ }
+
void test_invalidFunctionBodyModifier() {
ParserTestCase.parseCompilationUnit(
"f() sync {}", [ParserErrorCode.MISSING_STAR_AFTER_SYNC]);
@@ -9423,7 +9458,7 @@ void''');
expect(identifier.name, lexeme);
}
- void test_parseStatement_emptyTypeArgumentListt() {
+ void test_parseStatement_emptyTypeArgumentList() {
VariableDeclarationStatement statement = parse4(
"parseStatement", "C<> c;", [ParserErrorCode.EXPECTED_TYPE_NAME]);
VariableDeclarationList variables = statement.variables;
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698