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

Unified Diff: pkg/analysis_server/test/services/correction/fix_test.dart

Issue 894373005: Quick Fix for adding 'async' to fix invalid 'await'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/test/services/correction/fix_test.dart
diff --git a/pkg/analysis_server/test/services/correction/fix_test.dart b/pkg/analysis_server/test/services/correction/fix_test.dart
index 3ca13a611ca212017e86f741e4a5713aa680e477..cc230ca9af9892868d6d6c9ff1121bcf51e2440f 100644
--- a/pkg/analysis_server/test/services/correction/fix_test.dart
+++ b/pkg/analysis_server/test/services/correction/fix_test.dart
@@ -12,6 +12,7 @@ import 'package:analysis_server/src/services/search/search_engine_internal.dart'
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/source/package_map_resolver.dart';
import 'package:analyzer/src/generated/error.dart';
+import 'package:analyzer/src/generated/parser.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:unittest/unittest.dart';
@@ -26,12 +27,15 @@ main() {
}
+typedef bool AnalysisErrorFilter(AnalysisError error);
+
+
@reflectiveTest
class FixProcessorTest extends AbstractSingleUnitTest {
Index index;
SearchEngineImpl searchEngine;
- bool checkHasSingleError = true;
+ AnalysisErrorFilter errorFilter = null;
Fix fix;
SourceChange change;
@@ -104,6 +108,59 @@ bool test() {
verifyNoTestUnitErrors = false;
}
+ void test_addSync_blockFunctionBody() {
+ _indexTestUnit('''
+foo() {}
+main() {
+ await foo();
+}
+''');
+ List<AnalysisError> errors = context.computeErrors(testSource);
+ expect(errors, hasLength(2));
+ // ParserError: Expected to find ';'
+ {
+ AnalysisError error = errors[0];
+ expect(error.message, "Expected to find ';'");
+ List<Fix> fixes = computeFixes(searchEngine, testUnit, error);
+ expect(fixes, isEmpty);
+ }
+ // Undefined name 'await'
+ {
+ AnalysisError error = errors[1];
+ expect(error.message, "Undefined name 'await'");
+ List<Fix> fixes = computeFixes(searchEngine, testUnit, error);
+ // has exactly one fix
+ expect(fixes, hasLength(1));
+ Fix fix = fixes[0];
+ expect(fix.kind, FixKind.ADD_ASYNC);
+ // apply to "file"
+ List<SourceFileEdit> fileEdits = fix.change.edits;
+ expect(fileEdits, hasLength(1));
+ resultCode = SourceEdit.applySequence(testCode, fileEdits[0].edits);
+ // verify
+ expect(resultCode, '''
+foo() {}
+main() async {
+ await foo();
+}
+''');
+ }
+ }
+
+ void test_addSync_expressionFunctionBody() {
+ errorFilter = (AnalysisError error) {
+ return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER;
+ };
+ _indexTestUnit('''
+foo() {}
+main() => await foo();
+''');
+ assertHasFix(FixKind.ADD_ASYNC, '''
+foo() {}
+main() async => await foo();
+''');
+ }
+
void test_boolean() {
_indexTestUnit('''
main() {
@@ -836,7 +893,6 @@ class A {
}
}
''');
- // TODO
assertHasFix(FixKind.CREATE_GETTER, '''
class A {
get test => null;
@@ -1992,7 +2048,9 @@ import 'package:my_pkg/my_lib.dart';
}
void test_replaceVarWithDynamic() {
- checkHasSingleError = false;
+ errorFilter = (AnalysisError error) {
+ return error.errorCode == ParserErrorCode.VAR_AS_TYPE_NAME;
+ };
_indexTestUnit('''
class A {
Map<String, var> m;
@@ -2714,9 +2772,10 @@ main() {
error.errorCode == HintCode.UNUSED_FIELD ||
error.errorCode == HintCode.UNUSED_LOCAL_VARIABLE;
});
- if (checkHasSingleError) {
- expect(errors, hasLength(1));
+ if (errorFilter != null) {
+ errors = errors.where(errorFilter).toList();
}
+ expect(errors, hasLength(1));
return errors[0];
}
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698