| OLD | NEW |
| 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library test.services.correction.fix; | 8 library test.services.correction.fix; |
| 9 | 9 |
| 10 import 'package:analysis_services/correction/change.dart'; | 10 import 'package:analysis_services/correction/change.dart'; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 change = fix.change; | 43 change = fix.change; |
| 44 // apply to "file" | 44 // apply to "file" |
| 45 List<FileEdit> fileEdits = change.edits; | 45 List<FileEdit> fileEdits = change.edits; |
| 46 expect(fileEdits, hasLength(1)); | 46 expect(fileEdits, hasLength(1)); |
| 47 resultCode = _applyEdits(testCode, change.edits[0].edits); | 47 resultCode = _applyEdits(testCode, change.edits[0].edits); |
| 48 // verify | 48 // verify |
| 49 expect(resultCode, expected); | 49 expect(resultCode, expected); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void assertHasPositionGroup(String id, List<Position> expectedPositions) { | 52 void assertHasPositionGroup(String id, List<Position> expectedPositions) { |
| 53 List<LinkedPositionGroup> linkedPositionGroups = | 53 List<LinkedEditGroup> linkedPositionGroups = change.linkedEditGroups; |
| 54 change.linkedPositionGroups; | 54 for (LinkedEditGroup group in linkedPositionGroups) { |
| 55 for (LinkedPositionGroup group in linkedPositionGroups) { | |
| 56 if (group.id == id) { | 55 if (group.id == id) { |
| 57 expect(group.positions, unorderedEquals(expectedPositions)); | 56 expect(group.positions, unorderedEquals(expectedPositions)); |
| 58 return; | 57 return; |
| 59 } | 58 } |
| 60 } | 59 } |
| 61 fail('No PositionGroup with id=$id found in $linkedPositionGroups'); | 60 fail('No PositionGroup with id=$id found in $linkedPositionGroups'); |
| 62 } | 61 } |
| 63 | 62 |
| 64 void assertNoFix(FixKind kind) { | 63 void assertNoFix(FixKind kind) { |
| 65 AnalysisError error = _findErrorToFix(); | 64 AnalysisError error = _findErrorToFix(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 85 } | 84 } |
| 86 | 85 |
| 87 bool test() { | 86 bool test() { |
| 88 } | 87 } |
| 89 '''); | 88 '''); |
| 90 } | 89 } |
| 91 | 90 |
| 92 Position expectedPosition(String search) { | 91 Position expectedPosition(String search) { |
| 93 int offset = resultCode.indexOf(search); | 92 int offset = resultCode.indexOf(search); |
| 94 int length = getLeadingIdentifierLength(search); | 93 int length = getLeadingIdentifierLength(search); |
| 95 return new Position(testFile, offset, length); | 94 return new Position(testFile, offset); |
| 96 } | 95 } |
| 97 | 96 |
| 98 List<Position> expectedPositions(List<String> patterns) { | 97 List<Position> expectedPositions(List<String> patterns) { |
| 99 List<Position> positions = <Position>[]; | 98 List<Position> positions = <Position>[]; |
| 100 patterns.forEach((String search) { | 99 patterns.forEach((String search) { |
| 101 positions.add(expectedPosition(search)); | 100 positions.add(expectedPosition(search)); |
| 102 }); | 101 }); |
| 103 return positions; | 102 return positions; |
| 104 } | 103 } |
| 105 | 104 |
| (...skipping 1495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1601 'NAME', | 1600 'NAME', |
| 1602 ['myUndefinedMethod(0', 'myUndefinedMethod(int']); | 1601 ['myUndefinedMethod(0', 'myUndefinedMethod(int']); |
| 1603 _assertHasLinkedPositions('RETURN_TYPE', ['void myUndefinedMethod(']); | 1602 _assertHasLinkedPositions('RETURN_TYPE', ['void myUndefinedMethod(']); |
| 1604 _assertHasLinkedPositions('TYPE0', ['int i']); | 1603 _assertHasLinkedPositions('TYPE0', ['int i']); |
| 1605 _assertHasLinkedPositions('TYPE1', ['double d']); | 1604 _assertHasLinkedPositions('TYPE1', ['double d']); |
| 1606 _assertHasLinkedPositions('TYPE2', ['String s']); | 1605 _assertHasLinkedPositions('TYPE2', ['String s']); |
| 1607 _assertHasLinkedPositions('ARG0', ['i,']); | 1606 _assertHasLinkedPositions('ARG0', ['i,']); |
| 1608 _assertHasLinkedPositions('ARG1', ['d,']); | 1607 _assertHasLinkedPositions('ARG1', ['d,']); |
| 1609 _assertHasLinkedPositions('ARG2', ['s)']); | 1608 _assertHasLinkedPositions('ARG2', ['s)']); |
| 1610 // linked proposals | 1609 // linked proposals |
| 1611 _assertHasLinkedProposals('TYPE0', ['int', 'num', 'Object', 'Comparable']); | 1610 _assertHasLinkedSuggestions( |
| 1612 _assertHasLinkedProposals( | 1611 'TYPE0', |
| 1612 expectedSuggestions( |
| 1613 LinkedEditSuggestionKind.TYPE, |
| 1614 ['int', 'num', 'Object', 'Comparable'])); |
| 1615 _assertHasLinkedSuggestions( |
| 1613 'TYPE1', | 1616 'TYPE1', |
| 1614 ['double', 'num', 'Object', 'Comparable']); | 1617 expectedSuggestions( |
| 1615 _assertHasLinkedProposals('TYPE2', ['String', 'Object', 'Comparable']); | 1618 LinkedEditSuggestionKind.TYPE, |
| 1619 ['double', 'num', 'Object', 'Comparable'])); |
| 1620 _assertHasLinkedSuggestions( |
| 1621 'TYPE2', |
| 1622 expectedSuggestions( |
| 1623 LinkedEditSuggestionKind.TYPE, |
| 1624 ['String', 'Object', 'Comparable'])); |
| 1625 } |
| 1626 |
| 1627 List<LinkedEditSuggestion> expectedSuggestions(LinkedEditSuggestionKind kind, |
| 1628 List<String> values) { |
| 1629 return values.map((value) { |
| 1630 return new LinkedEditSuggestion(kind, value); |
| 1631 }).toList(); |
| 1616 } | 1632 } |
| 1617 | 1633 |
| 1618 void test_undefinedMethod_createUnqualified_returnType() { | 1634 void test_undefinedMethod_createUnqualified_returnType() { |
| 1619 _indexTestUnit(''' | 1635 _indexTestUnit(''' |
| 1620 class A { | 1636 class A { |
| 1621 main() { | 1637 main() { |
| 1622 int v = myUndefinedMethod(); | 1638 int v = myUndefinedMethod(); |
| 1623 } | 1639 } |
| 1624 } | 1640 } |
| 1625 '''); | 1641 '''); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1804 for (Fix fix in fixes) { | 1820 for (Fix fix in fixes) { |
| 1805 if (fix.kind == kind) { | 1821 if (fix.kind == kind) { |
| 1806 return fix; | 1822 return fix; |
| 1807 } | 1823 } |
| 1808 } | 1824 } |
| 1809 throw fail('Expected to find fix $kind in\n${fixes.join('\n')}'); | 1825 throw fail('Expected to find fix $kind in\n${fixes.join('\n')}'); |
| 1810 } | 1826 } |
| 1811 | 1827 |
| 1812 void _assertHasLinkedPositions(String groupId, List<String> expectedStrings) { | 1828 void _assertHasLinkedPositions(String groupId, List<String> expectedStrings) { |
| 1813 List<Position> expectedPositions = _findResultPositions(expectedStrings); | 1829 List<Position> expectedPositions = _findResultPositions(expectedStrings); |
| 1814 List<LinkedPositionGroup> groups = change.linkedPositionGroups; | 1830 List<LinkedEditGroup> groups = change.linkedEditGroups; |
| 1815 for (LinkedPositionGroup group in groups) { | 1831 for (LinkedEditGroup group in groups) { |
| 1816 if (group.id == groupId) { | 1832 if (group.id == groupId) { |
| 1817 List<Position> actualPositions = group.positions; | 1833 List<Position> actualPositions = group.positions; |
| 1818 expect(actualPositions, unorderedEquals(expectedPositions)); | 1834 expect(actualPositions, unorderedEquals(expectedPositions)); |
| 1819 return; | 1835 return; |
| 1820 } | 1836 } |
| 1821 } | 1837 } |
| 1822 fail('No group with ID=$groupId foind in\n${groups.join('\n')}'); | 1838 fail('No group with ID=$groupId foind in\n${groups.join('\n')}'); |
| 1823 } | 1839 } |
| 1824 | 1840 |
| 1825 void _assertHasLinkedProposals(String groupId, List<String> expected) { | 1841 void _assertHasLinkedSuggestions(String groupId, |
| 1826 List<LinkedPositionGroup> groups = change.linkedPositionGroups; | 1842 List<LinkedEditSuggestion> expected) { |
| 1827 for (LinkedPositionGroup group in groups) { | 1843 List<LinkedEditGroup> groups = change.linkedEditGroups; |
| 1844 for (LinkedEditGroup group in groups) { |
| 1828 if (group.id == groupId) { | 1845 if (group.id == groupId) { |
| 1829 expect(group.proposals, expected); | 1846 expect(group.suggestions, expected); |
| 1830 return; | 1847 return; |
| 1831 } | 1848 } |
| 1832 } | 1849 } |
| 1833 fail('No group with ID=$groupId foind in\n${groups.join('\n')}'); | 1850 fail('No group with ID=$groupId foind in\n${groups.join('\n')}'); |
| 1834 } | 1851 } |
| 1835 | 1852 |
| 1836 /** | 1853 /** |
| 1837 * We search for elements only already resolved lbiraries, and we use | 1854 * We search for elements only already resolved lbiraries, and we use |
| 1838 * `dart:async` elements in tests. | 1855 * `dart:async` elements in tests. |
| 1839 */ | 1856 */ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1857 reason: 'Exactly 1 error expected, but ${errors.length} found:\n' + | 1874 reason: 'Exactly 1 error expected, but ${errors.length} found:\n' + |
| 1858 errors.join('\n')); | 1875 errors.join('\n')); |
| 1859 return errors[0]; | 1876 return errors[0]; |
| 1860 } | 1877 } |
| 1861 | 1878 |
| 1862 List<Position> _findResultPositions(List<String> searchStrings) { | 1879 List<Position> _findResultPositions(List<String> searchStrings) { |
| 1863 List<Position> positions = <Position>[]; | 1880 List<Position> positions = <Position>[]; |
| 1864 for (String search in searchStrings) { | 1881 for (String search in searchStrings) { |
| 1865 int offset = resultCode.indexOf(search); | 1882 int offset = resultCode.indexOf(search); |
| 1866 int length = getLeadingIdentifierLength(search); | 1883 int length = getLeadingIdentifierLength(search); |
| 1867 positions.add(new Position(testFile, offset, length)); | 1884 positions.add(new Position(testFile, offset)); |
| 1868 } | 1885 } |
| 1869 return positions; | 1886 return positions; |
| 1870 } | 1887 } |
| 1871 | 1888 |
| 1872 void _indexTestUnit(String code) { | 1889 void _indexTestUnit(String code) { |
| 1873 resolveTestUnit(code); | 1890 resolveTestUnit(code); |
| 1874 index.indexUnit(context, testUnit); | 1891 index.indexUnit(context, testUnit); |
| 1875 } | 1892 } |
| 1876 } | 1893 } |
| OLD | NEW |