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

Unified Diff: pkg/analysis_server/test/services/completion/local_declaration_visitor_test.dart

Issue 1138963005: Fix exception in code completion (issue 23439) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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
Index: pkg/analysis_server/test/services/completion/local_declaration_visitor_test.dart
diff --git a/pkg/analysis_server/test/services/completion/local_declaration_visitor_test.dart b/pkg/analysis_server/test/services/completion/local_declaration_visitor_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..230291d8ad777fb675d009564ced3ff86e8e4718
--- /dev/null
+++ b/pkg/analysis_server/test/services/completion/local_declaration_visitor_test.dart
@@ -0,0 +1,86 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library test.services.completion.local_declaration_visitor_test;
+
+import 'package:analysis_server/src/services/completion/local_declaration_visitor.dart';
+import 'package:analyzer/src/generated/ast.dart';
+import 'package:analyzer/src/generated/error.dart';
+import 'package:analyzer/src/generated/parser.dart';
+import 'package:analyzer/src/generated/scanner.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+import 'package:unittest/unittest.dart';
+
+main() {
+ groupSep = ' | ';
+ defineReflectiveTests(LocalDeclarationVisitorTest);
+}
+
+@reflectiveTest
+class LocalDeclarationVisitorTest {
+ CompilationUnit parseCompilationUnit(String source) {
+ AnalysisErrorListener listener = AnalysisErrorListener.NULL_LISTENER;
+ Scanner scanner =
+ new Scanner(null, new CharSequenceReader(source), listener);
+ Token token = scanner.tokenize();
+ Parser parser = new Parser(null, listener);
+ CompilationUnit unit = parser.parseCompilationUnit(token);
+ expect(unit, isNotNull);
+ return unit;
+ }
+
+ test_visitForEachStatement() {
+ CompilationUnit unit = parseCompilationUnit('''
+class MyClass {}
+f(List<MyClass> list) {
+ for(MyClas( x in list) {}
+}
+''');
+ NodeList<CompilationUnitMember> declarations = unit.declarations;
+ expect(declarations, hasLength(2));
+ FunctionDeclaration f = declarations[1];
+ expect(f, isNotNull);
+ BlockFunctionBody body = f.functionExpression.body;
+ Statement statement = body.block.statements[0];
+ expect(statement, new isInstanceOf<ForEachStatement>());
+ statement.accept(new TestVisitor(statement.offset));
+ }
+}
+
+class TestVisitor extends LocalDeclarationVisitor {
+ TestVisitor(int offset) : super(offset);
+
+ @override
+ void declaredClass(ClassDeclaration declaration) {}
+
+ @override
+ void declaredClassTypeAlias(ClassTypeAlias declaration) {}
+
+ @override
+ void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) {}
+
+ @override
+ void declaredFunction(FunctionDeclaration declaration) {}
+
+ @override
+ void declaredFunctionTypeAlias(FunctionTypeAlias declaration) {}
+
+ @override
+ void declaredLabel(Label label, bool isCaseLabel) {}
+
+ @override
+ void declaredLocalVar(SimpleIdentifier name, TypeName type) {
+ expect(name, isNotNull);
+ }
+
+ @override
+ void declaredMethod(MethodDeclaration declaration) {}
+
+ @override
+ void declaredParam(SimpleIdentifier name, TypeName type) {}
+
+ @override
+ void declaredTopLevelVar(
+ VariableDeclarationList varList, VariableDeclaration varDecl) {}
+}

Powered by Google App Engine
This is Rietveld 408576698