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

Side by Side Diff: pkg/analysis_server/test/services/correction/assist_test.dart

Issue 1012913002: Casted variable declarations for 'if (v is! Type)' should be declared after IfStatement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/assist_internal.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 test.services.correction.assist; 5 library test.services.correction.assist;
6 6
7 import 'package:analysis_server/src/protocol.dart'; 7 import 'package:analysis_server/src/protocol.dart';
8 import 'package:analysis_server/src/services/correction/assist.dart'; 8 import 'package:analysis_server/src/services/correction/assist.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 void test_introduceLocalTestedType_BAD_notIsExpression() { 1569 void test_introduceLocalTestedType_BAD_notIsExpression() {
1570 resolveTestUnit(''' 1570 resolveTestUnit('''
1571 main(p) { 1571 main(p) {
1572 if (p == null) { 1572 if (p == null) {
1573 } 1573 }
1574 } 1574 }
1575 '''); 1575 ''');
1576 assertNoAssistAt('if (p', AssistKind.INTRODUCE_LOCAL_CAST_TYPE); 1576 assertNoAssistAt('if (p', AssistKind.INTRODUCE_LOCAL_CAST_TYPE);
1577 } 1577 }
1578 1578
1579 void test_introduceLocalTestedType_OK_if() { 1579 void test_introduceLocalTestedType_OK_if_is() {
1580 resolveTestUnit(''' 1580 resolveTestUnit('''
1581 class MyTypeName {} 1581 class MyTypeName {}
1582 main(p) { 1582 main(p) {
1583 if (p is MyTypeName) { 1583 if (p is MyTypeName) {
1584 } 1584 }
1585 p = null; 1585 p = null;
1586 } 1586 }
1587 '''); 1587 ''');
1588 String expected = ''' 1588 String expected = '''
1589 class MyTypeName {} 1589 class MyTypeName {}
1590 main(p) { 1590 main(p) {
1591 if (p is MyTypeName) { 1591 if (p is MyTypeName) {
1592 MyTypeName myTypeName = p; 1592 MyTypeName myTypeName = p;
1593 } 1593 }
1594 p = null; 1594 p = null;
1595 } 1595 }
1596 '''; 1596 ''';
1597 assertHasAssistAt( 1597 assertHasAssistAt(
1598 'is MyType', AssistKind.INTRODUCE_LOCAL_CAST_TYPE, expected); 1598 'is MyType', AssistKind.INTRODUCE_LOCAL_CAST_TYPE, expected);
1599 _assertLinkedGroup(change.linkedEditGroups[0], [ 1599 _assertLinkedGroup(change.linkedEditGroups[0], [
1600 'myTypeName = ' 1600 'myTypeName = '
1601 ], expectedSuggestions( 1601 ], expectedSuggestions(
1602 LinkedEditSuggestionKind.VARIABLE, ['myTypeName', 'typeName', 'name'])); 1602 LinkedEditSuggestionKind.VARIABLE, ['myTypeName', 'typeName', 'name']));
1603 // another good location 1603 // another good location
1604 assertHasAssistAt('if (p', AssistKind.INTRODUCE_LOCAL_CAST_TYPE, expected); 1604 assertHasAssistAt('if (p', AssistKind.INTRODUCE_LOCAL_CAST_TYPE, expected);
1605 } 1605 }
1606 1606
1607 void test_introduceLocalTestedType_OK_if_isNot() {
1608 resolveTestUnit('''
1609 class MyTypeName {}
1610 main(p) {
1611 if (p is! MyTypeName) {
1612 return;
1613 }
1614 }
1615 ''');
1616 String expected = '''
1617 class MyTypeName {}
1618 main(p) {
1619 if (p is! MyTypeName) {
1620 return;
1621 }
1622 MyTypeName myTypeName = p;
1623 }
1624 ''';
1625 assertHasAssistAt(
1626 'is! MyType', AssistKind.INTRODUCE_LOCAL_CAST_TYPE, expected);
1627 _assertLinkedGroup(change.linkedEditGroups[0], [
1628 'myTypeName = '
1629 ], expectedSuggestions(
1630 LinkedEditSuggestionKind.VARIABLE, ['myTypeName', 'typeName', 'name']));
1631 // another good location
1632 assertHasAssistAt('if (p', AssistKind.INTRODUCE_LOCAL_CAST_TYPE, expected);
1633 }
1634
1607 void test_introduceLocalTestedType_OK_while() { 1635 void test_introduceLocalTestedType_OK_while() {
1608 resolveTestUnit(''' 1636 resolveTestUnit('''
1609 main(p) { 1637 main(p) {
1610 while (p is String) { 1638 while (p is String) {
1611 } 1639 }
1612 p = null; 1640 p = null;
1613 } 1641 }
1614 '''); 1642 ''');
1615 String expected = ''' 1643 String expected = '''
1616 main(p) { 1644 main(p) {
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2863 positions.add(new Position(testFile, offset)); 2891 positions.add(new Position(testFile, offset));
2864 } 2892 }
2865 return positions; 2893 return positions;
2866 } 2894 }
2867 2895
2868 void _setStartEndSelection() { 2896 void _setStartEndSelection() {
2869 offset = findOffset('// start\n') + '// start\n'.length; 2897 offset = findOffset('// start\n') + '// start\n'.length;
2870 length = findOffset('// end') - offset; 2898 length = findOffset('// end') - offset;
2871 } 2899 }
2872 } 2900 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/assist_internal.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698