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

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

Issue 495733002: Don't use LinkedEditGroup.id. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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/test/services/correction/change_test.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.fix; 5 library test.services.correction.fix;
6 6
7 import 'package:analysis_server/src/services/correction/change.dart'; 7 import 'package:analysis_server/src/services/correction/change.dart';
8 import 'package:analysis_server/src/services/correction/fix.dart'; 8 import 'package:analysis_server/src/services/correction/fix.dart';
9 import 'package:analysis_server/src/services/index/index.dart'; 9 import 'package:analysis_server/src/services/index/index.dart';
10 import 'package:analysis_server/src/services/index/local_memory_index.dart'; 10 import 'package:analysis_server/src/services/index/local_memory_index.dart';
(...skipping 28 matching lines...) Expand all
39 fix = _assertHasFix(kind, error); 39 fix = _assertHasFix(kind, error);
40 change = fix.change; 40 change = fix.change;
41 // apply to "file" 41 // apply to "file"
42 List<FileEdit> fileEdits = change.fileEdits; 42 List<FileEdit> fileEdits = change.fileEdits;
43 expect(fileEdits, hasLength(1)); 43 expect(fileEdits, hasLength(1));
44 resultCode = applySequence(testCode, change.fileEdits[0].edits); 44 resultCode = applySequence(testCode, change.fileEdits[0].edits);
45 // verify 45 // verify
46 expect(resultCode, expected); 46 expect(resultCode, expected);
47 } 47 }
48 48
49 void assertHasPositionGroup(String id, List<Position> expectedPositions) {
50 List<LinkedEditGroup> linkedPositionGroups = change.linkedEditGroups;
51 for (LinkedEditGroup group in linkedPositionGroups) {
52 if (group.id == id) {
53 expect(group.positions, unorderedEquals(expectedPositions));
54 return;
55 }
56 }
57 fail('No PositionGroup with id=$id found in $linkedPositionGroups');
58 }
59
60 void assertNoFix(FixKind kind) { 49 void assertNoFix(FixKind kind) {
61 AnalysisError error = _findErrorToFix(); 50 AnalysisError error = _findErrorToFix();
62 List<Fix> fixes = computeFixes(searchEngine, testUnit, error); 51 List<Fix> fixes = computeFixes(searchEngine, testUnit, error);
63 for (Fix fix in fixes) { 52 for (Fix fix in fixes) {
64 if (fix.kind == kind) { 53 if (fix.kind == kind) {
65 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}'); 54 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}');
66 } 55 }
67 } 56 }
68 } 57 }
69 58
(...skipping 22 matching lines...) Expand all
92 } 81 }
93 82
94 List<Position> expectedPositions(List<String> patterns) { 83 List<Position> expectedPositions(List<String> patterns) {
95 List<Position> positions = <Position>[]; 84 List<Position> positions = <Position>[];
96 patterns.forEach((String search) { 85 patterns.forEach((String search) {
97 positions.add(expectedPosition(search)); 86 positions.add(expectedPosition(search));
98 }); 87 });
99 return positions; 88 return positions;
100 } 89 }
101 90
91 List<LinkedEditSuggestion> expectedSuggestions(LinkedEditSuggestionKind kind,
92 List<String> values) {
93 return values.map((value) {
94 return new LinkedEditSuggestion(kind, value);
95 }).toList();
96 }
97
102 void setUp() { 98 void setUp() {
103 super.setUp(); 99 super.setUp();
104 index = createLocalMemoryIndex(); 100 index = createLocalMemoryIndex();
105 searchEngine = new SearchEngineImpl(index); 101 searchEngine = new SearchEngineImpl(index);
106 verifyNoTestUnitErrors = false; 102 verifyNoTestUnitErrors = false;
107 } 103 }
108 104
109 void test_boolean() { 105 void test_boolean() {
110 _indexTestUnit(''' 106 _indexTestUnit('''
111 main() { 107 main() {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 175 }
180 '''); 176 ''');
181 assertHasFix(FixKind.CREATE_CLASS, ''' 177 assertHasFix(FixKind.CREATE_CLASS, '''
182 main() { 178 main() {
183 Test v = null; 179 Test v = null;
184 } 180 }
185 181
186 class Test { 182 class Test {
187 } 183 }
188 '''); 184 ''');
189 assertHasPositionGroup('NAME', expectedPositions(['Test v =', 'Test {'])); 185 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']);
190 } 186 }
191 187
192 void test_createConstructorSuperExplicit() { 188 void test_createConstructorSuperExplicit() {
193 _indexTestUnit(''' 189 _indexTestUnit('''
194 class A { 190 class A {
195 A(bool p1, int p2, double p3, String p4, {p5}); 191 A(bool p1, int p2, double p3, String p4, {p5});
196 } 192 }
197 class B extends A { 193 class B extends A {
198 B() {} 194 B() {}
199 } 195 }
(...skipping 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 class A { 1582 class A {
1587 main() { 1583 main() {
1588 myUndefinedMethod(0, 1.0, '3'); 1584 myUndefinedMethod(0, 1.0, '3');
1589 } 1585 }
1590 1586
1591 void myUndefinedMethod(int i, double d, String s) { 1587 void myUndefinedMethod(int i, double d, String s) {
1592 } 1588 }
1593 } 1589 }
1594 '''); 1590 ''');
1595 // linked positions 1591 // linked positions
1596 _assertHasLinkedPositions( 1592 int index = 0;
1597 'NAME', 1593 _assertLinkedGroup(
1594 change.linkedEditGroups[index++],
1595 ['void myUndefinedMethod(']);
1596 _assertLinkedGroup(
1597 change.linkedEditGroups[index++],
1598 ['myUndefinedMethod(0', 'myUndefinedMethod(int']); 1598 ['myUndefinedMethod(0', 'myUndefinedMethod(int']);
1599 _assertHasLinkedPositions('RETURN_TYPE', ['void myUndefinedMethod(']); 1599 _assertLinkedGroup(
1600 _assertHasLinkedPositions('TYPE0', ['int i']); 1600 change.linkedEditGroups[index++],
1601 _assertHasLinkedPositions('TYPE1', ['double d']); 1601 ['int i'],
1602 _assertHasLinkedPositions('TYPE2', ['String s']);
1603 _assertHasLinkedPositions('ARG0', ['i,']);
1604 _assertHasLinkedPositions('ARG1', ['d,']);
1605 _assertHasLinkedPositions('ARG2', ['s)']);
1606 // linked proposals
1607 _assertHasLinkedSuggestions(
1608 'TYPE0',
1609 expectedSuggestions( 1602 expectedSuggestions(
1610 LinkedEditSuggestionKind.TYPE, 1603 LinkedEditSuggestionKind.TYPE,
1611 ['int', 'num', 'Object', 'Comparable'])); 1604 ['int', 'num', 'Object', 'Comparable']));
1612 _assertHasLinkedSuggestions( 1605 _assertLinkedGroup(change.linkedEditGroups[index++], ['i,']);
1613 'TYPE1', 1606 _assertLinkedGroup(
1607 change.linkedEditGroups[index++],
1608 ['double d'],
1614 expectedSuggestions( 1609 expectedSuggestions(
1615 LinkedEditSuggestionKind.TYPE, 1610 LinkedEditSuggestionKind.TYPE,
1616 ['double', 'num', 'Object', 'Comparable'])); 1611 ['double', 'num', 'Object', 'Comparable']));
1617 _assertHasLinkedSuggestions( 1612 _assertLinkedGroup(change.linkedEditGroups[index++], ['d,']);
1618 'TYPE2', 1613 _assertLinkedGroup(
1614 change.linkedEditGroups[index++],
1615 ['String s'],
1619 expectedSuggestions( 1616 expectedSuggestions(
1620 LinkedEditSuggestionKind.TYPE, 1617 LinkedEditSuggestionKind.TYPE,
1621 ['String', 'Object', 'Comparable'])); 1618 ['String', 'Object', 'Comparable']));
1622 } 1619 _assertLinkedGroup(change.linkedEditGroups[index++], ['s)']);
1623
1624 List<LinkedEditSuggestion> expectedSuggestions(LinkedEditSuggestionKind kind,
1625 List<String> values) {
1626 return values.map((value) {
1627 return new LinkedEditSuggestion(kind, value);
1628 }).toList();
1629 } 1620 }
1630 1621
1631 void test_undefinedMethod_createUnqualified_returnType() { 1622 void test_undefinedMethod_createUnqualified_returnType() {
1632 _indexTestUnit(''' 1623 _indexTestUnit('''
1633 class A { 1624 class A {
1634 main() { 1625 main() {
1635 int v = myUndefinedMethod(); 1626 int v = myUndefinedMethod();
1636 } 1627 }
1637 } 1628 }
1638 '''); 1629 ''');
1639 assertHasFix(FixKind.CREATE_METHOD, ''' 1630 assertHasFix(FixKind.CREATE_METHOD, '''
1640 class A { 1631 class A {
1641 main() { 1632 main() {
1642 int v = myUndefinedMethod(); 1633 int v = myUndefinedMethod();
1643 } 1634 }
1644 1635
1645 int myUndefinedMethod() { 1636 int myUndefinedMethod() {
1646 } 1637 }
1647 } 1638 }
1648 '''); 1639 ''');
1649 // linked positions 1640 // linked positions
1650 _assertHasLinkedPositions( 1641 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']);
1651 'NAME', 1642 _assertLinkedGroup(
1643 change.linkedEditGroups[1],
1652 ['myUndefinedMethod();', 'myUndefinedMethod() {']); 1644 ['myUndefinedMethod();', 'myUndefinedMethod() {']);
1653 _assertHasLinkedPositions('RETURN_TYPE', ['int myUndefinedMethod(']);
1654 } 1645 }
1655 1646
1656 void test_undefinedMethod_createUnqualified_staticFromField() { 1647 void test_undefinedMethod_createUnqualified_staticFromField() {
1657 _indexTestUnit(''' 1648 _indexTestUnit('''
1658 class A { 1649 class A {
1659 static var f = myUndefinedMethod(); 1650 static var f = myUndefinedMethod();
1660 } 1651 }
1661 '''); 1652 ''');
1662 assertHasFix(FixKind.CREATE_METHOD, ''' 1653 assertHasFix(FixKind.CREATE_METHOD, '''
1663 class A { 1654 class A {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 Fix _assertHasFix(FixKind kind, AnalysisError error) { 1796 Fix _assertHasFix(FixKind kind, AnalysisError error) {
1806 List<Fix> fixes = computeFixes(searchEngine, testUnit, error); 1797 List<Fix> fixes = computeFixes(searchEngine, testUnit, error);
1807 for (Fix fix in fixes) { 1798 for (Fix fix in fixes) {
1808 if (fix.kind == kind) { 1799 if (fix.kind == kind) {
1809 return fix; 1800 return fix;
1810 } 1801 }
1811 } 1802 }
1812 throw fail('Expected to find fix $kind in\n${fixes.join('\n')}'); 1803 throw fail('Expected to find fix $kind in\n${fixes.join('\n')}');
1813 } 1804 }
1814 1805
1815 void _assertHasLinkedPositions(String groupId, List<String> expectedStrings) { 1806 void _assertLinkedGroup(LinkedEditGroup group, List<String> expectedStrings,
1807 [List<LinkedEditSuggestion> expectedSuggestions]) {
1816 List<Position> expectedPositions = _findResultPositions(expectedStrings); 1808 List<Position> expectedPositions = _findResultPositions(expectedStrings);
1817 List<LinkedEditGroup> groups = change.linkedEditGroups; 1809 expect(group.positions, unorderedEquals(expectedPositions));
1818 for (LinkedEditGroup group in groups) { 1810 if (expectedSuggestions != null) {
1819 if (group.id == groupId) { 1811 expect(group.suggestions, unorderedEquals(expectedSuggestions));
1820 List<Position> actualPositions = group.positions;
1821 expect(actualPositions, unorderedEquals(expectedPositions));
1822 return;
1823 }
1824 } 1812 }
1825 fail('No group with ID=$groupId foind in\n${groups.join('\n')}');
1826 }
1827
1828 void _assertHasLinkedSuggestions(String groupId,
1829 List<LinkedEditSuggestion> expected) {
1830 List<LinkedEditGroup> groups = change.linkedEditGroups;
1831 for (LinkedEditGroup group in groups) {
1832 if (group.id == groupId) {
1833 expect(group.suggestions, expected);
1834 return;
1835 }
1836 }
1837 fail('No group with ID=$groupId foind in\n${groups.join('\n')}');
1838 } 1813 }
1839 1814
1840 /** 1815 /**
1841 * We search for elements only already resolved lbiraries, and we use 1816 * We search for elements only already resolved lbiraries, and we use
1842 * `dart:async` elements in tests. 1817 * `dart:async` elements in tests.
1843 */ 1818 */
1844 void _ensureSdkAsyncLibraryResolved() { 1819 void _ensureSdkAsyncLibraryResolved() {
1845 resolveLibraryUnit(addSource('/other.dart', 'import "dart:async";')); 1820 resolveLibraryUnit(addSource('/other.dart', 'import "dart:async";'));
1846 } 1821 }
1847 1822
(...skipping 23 matching lines...) Expand all
1871 positions.add(new Position(testFile, offset)); 1846 positions.add(new Position(testFile, offset));
1872 } 1847 }
1873 return positions; 1848 return positions;
1874 } 1849 }
1875 1850
1876 void _indexTestUnit(String code) { 1851 void _indexTestUnit(String code) {
1877 resolveTestUnit(code); 1852 resolveTestUnit(code);
1878 index.indexUnit(context, testUnit); 1853 index.indexUnit(context, testUnit);
1879 } 1854 }
1880 } 1855 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/services/correction/change_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698