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

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

Issue 618833003: Add 'Introduce new local with cast type' quick assist. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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/correction/assist_test.dart
diff --git a/pkg/analysis_server/test/services/correction/assist_test.dart b/pkg/analysis_server/test/services/correction/assist_test.dart
index be91abda9e747b33599e7d56152db747407b2145..f7e46fbf51469a23a60cd30910143278cf325699 100644
--- a/pkg/analysis_server/test/services/correction/assist_test.dart
+++ b/pkg/analysis_server/test/services/correction/assist_test.dart
@@ -904,16 +904,16 @@ main() {
assertNoAssistAt('import ', AssistKind.IMPORT_ADD_SHOW);
}
- void test_importAddShow_BAD_unused() {
+ void test_importAddShow_BAD_unresolvedUri() {
_indexTestUnit('''
-import 'dart:math';
+import '/no/such/lib.dart';
''');
assertNoAssistAt('import ', AssistKind.IMPORT_ADD_SHOW);
}
- void test_importAddShow_BAD_unresolvedUri() {
+ void test_importAddShow_BAD_unused() {
_indexTestUnit('''
-import '/no/such/lib.dart';
+import 'dart:math';
''');
assertNoAssistAt('import ', AssistKind.IMPORT_ADD_SHOW);
}
@@ -973,6 +973,84 @@ main() {
''');
}
+ void test_introduceLocalCastType_BAD_notBlock() {
+ _indexTestUnit('''
+main(p) {
+ if (p is String)
+ print('not a block');
+}
+''');
+ assertNoAssistAt('if (p', AssistKind.INTRODUCE_LOCAL_CAST_TYPE);
+ }
+
+ void test_introduceLocalCastType_BAD_notIsExpression() {
+ _indexTestUnit('''
+main(p) {
+ if (p == null) {
+ }
+}
+''');
+ assertNoAssistAt('if (p', AssistKind.INTRODUCE_LOCAL_CAST_TYPE);
+ }
+
+ void test_introduceLocalCastType_OK_if() {
+ _indexTestUnit('''
+class MyTypeName {}
+main(p) {
+ if (p is MyTypeName) {
+ }
+ p = null;
+}
+''');
+ String expected = '''
+class MyTypeName {}
+main(p) {
+ if (p is MyTypeName) {
+ MyTypeName myTypeName = p;
+ }
+ p = null;
+}
+''';
+ assertHasAssistAt(
+ 'is MyType',
+ AssistKind.INTRODUCE_LOCAL_CAST_TYPE,
+ expected);
+ _assertLinkedGroup(
+ change.linkedEditGroups[0],
+ ['myTypeName = '],
+ expectedSuggestions(
+ LinkedEditSuggestionKind.VARIABLE,
+ ['myTypeName', 'typeName', 'name']));
+ // another good location
+ assertHasAssistAt('if (p', AssistKind.INTRODUCE_LOCAL_CAST_TYPE, expected);
+ }
+
+ void test_introduceLocalCastType_OK_while() {
+ _indexTestUnit('''
+main(p) {
+ while (p is String) {
+ }
+ p = null;
+}
+''');
+ String expected = '''
+main(p) {
+ while (p is String) {
+ String s = p;
+ }
+ p = null;
+}
+''';
+ assertHasAssistAt(
+ 'is String',
+ AssistKind.INTRODUCE_LOCAL_CAST_TYPE,
+ expected);
+ assertHasAssistAt(
+ 'while (p',
+ AssistKind.INTRODUCE_LOCAL_CAST_TYPE,
+ expected);
+ }
+
void test_invertIfStatement_blocks() {
_indexTestUnit('''
main() {

Powered by Google App Engine
This is Rietveld 408576698