| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.src.task.dart_test; | 5 library test.src.task.dart_test; |
| 6 | 6 |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 1548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1559 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); | 1559 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); |
| 1560 // validate | 1560 // validate |
| 1561 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); | 1561 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); |
| 1562 errorListener | 1562 errorListener |
| 1563 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | 1563 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 1564 } | 1564 } |
| 1565 } | 1565 } |
| 1566 | 1566 |
| 1567 @reflectiveTest | 1567 @reflectiveTest |
| 1568 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest { | 1568 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest { |
| 1569 /** |
| 1570 * Verify that the mutated states of the given [variable] correspond to the |
| 1571 * [mutatedInClosure] and [mutatedInScope] matchers. |
| 1572 */ |
| 1573 void expectMutated(VariableElement variable, Matcher mutatedInClosure, |
| 1574 Matcher mutatedInScope) { |
| 1575 expect(variable.isPotentiallyMutatedInClosure, mutatedInClosure); |
| 1576 expect(variable.isPotentiallyMutatedInScope, mutatedInScope); |
| 1577 } |
| 1578 |
| 1569 test_perform_local() { | 1579 test_perform_local() { |
| 1570 Source source = _newSource('/test.dart', ''' | 1580 Source source = _newSource('/test.dart', ''' |
| 1571 main() { | 1581 main() { |
| 1572 var v1 = 1; | 1582 var v1 = 1; |
| 1573 var v2 = 1; | 1583 var v2 = 1; |
| 1574 var v3 = 1; | 1584 var v3 = 1; |
| 1575 var v4 = 1; | 1585 var v4 = 1; |
| 1576 v2 = 2; | 1586 v2 = 2; |
| 1577 v4 = 2; | 1587 v4 = 2; |
| 1578 localFunction() { | 1588 localFunction() { |
| 1579 v3 = 3; | 1589 v3 = 3; |
| 1580 v4 = 3; | 1590 v4 = 3; |
| 1581 } | 1591 } |
| 1582 } | 1592 } |
| 1583 '''); | 1593 '''); |
| 1584 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1594 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1585 _computeResult(target, RESOLVED_UNIT5); | 1595 _computeResult(target, RESOLVED_UNIT5); |
| 1586 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); | 1596 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); |
| 1587 // validate | 1597 // validate |
| 1588 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 1598 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 1589 FunctionElement main = unit.element.functions[0]; | 1599 FunctionElement main = unit.element.functions[0]; |
| 1590 { | 1600 expectMutated(main.localVariables[0], isFalse, isFalse); |
| 1591 var v1 = main.localVariables[0] as VariableElementImpl; | 1601 expectMutated(main.localVariables[1], isFalse, isTrue); |
| 1592 expect(v1.isPotentiallyMutatedInClosure, isFalse); | 1602 expectMutated(main.localVariables[2], isTrue, isTrue); |
| 1593 expect(v1.isPotentiallyMutatedInScope, isFalse); | 1603 expectMutated(main.localVariables[3], isTrue, isTrue); |
| 1594 } | |
| 1595 { | |
| 1596 var v2 = main.localVariables[1] as VariableElementImpl; | |
| 1597 expect(v2.isPotentiallyMutatedInClosure, isFalse); | |
| 1598 expect(v2.isPotentiallyMutatedInScope, isTrue); | |
| 1599 } | |
| 1600 { | |
| 1601 var v3 = main.localVariables[2] as VariableElementImpl; | |
| 1602 expect(v3.isPotentiallyMutatedInClosure, isTrue); | |
| 1603 expect(v3.isPotentiallyMutatedInScope, isTrue); | |
| 1604 } | |
| 1605 { | |
| 1606 var v4 = main.localVariables[3] as VariableElementImpl; | |
| 1607 expect(v4.isPotentiallyMutatedInClosure, isTrue); | |
| 1608 expect(v4.isPotentiallyMutatedInScope, isTrue); | |
| 1609 } | |
| 1610 } | 1604 } |
| 1611 | 1605 |
| 1612 test_perform_parameter() { | 1606 test_perform_parameter() { |
| 1613 Source source = _newSource('/test.dart', ''' | 1607 Source source = _newSource('/test.dart', ''' |
| 1614 main(p1, p2, p3, p4) { | 1608 main(p1, p2, p3, p4) { |
| 1615 p2 = 2; | 1609 p2 = 2; |
| 1616 p4 = 2; | 1610 p4 = 2; |
| 1617 localFunction() { | 1611 localFunction() { |
| 1618 p3 = 3; | 1612 p3 = 3; |
| 1619 p4 = 3; | 1613 p4 = 3; |
| 1620 } | 1614 } |
| 1621 } | 1615 } |
| 1622 '''); | 1616 '''); |
| 1623 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1617 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1624 _computeResult(target, RESOLVED_UNIT5); | 1618 _computeResult(target, RESOLVED_UNIT5); |
| 1625 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); | 1619 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); |
| 1626 // validate | 1620 // validate |
| 1627 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 1621 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 1628 FunctionElement main = unit.element.functions[0]; | 1622 FunctionElement main = unit.element.functions[0]; |
| 1629 { | 1623 expectMutated(main.parameters[0], isFalse, isFalse); |
| 1630 var p1 = main.parameters[0] as VariableElementImpl; | 1624 expectMutated(main.parameters[1], isFalse, isTrue); |
| 1631 expect(p1.isPotentiallyMutatedInClosure, isFalse); | 1625 expectMutated(main.parameters[2], isTrue, isTrue); |
| 1632 expect(p1.isPotentiallyMutatedInScope, isFalse); | 1626 expectMutated(main.parameters[3], isTrue, isTrue); |
| 1633 } | |
| 1634 { | |
| 1635 var p2 = main.parameters[1] as VariableElementImpl; | |
| 1636 expect(p2.isPotentiallyMutatedInClosure, isFalse); | |
| 1637 expect(p2.isPotentiallyMutatedInScope, isTrue); | |
| 1638 } | |
| 1639 { | |
| 1640 var p3 = main.parameters[2] as VariableElementImpl; | |
| 1641 expect(p3.isPotentiallyMutatedInClosure, isTrue); | |
| 1642 expect(p3.isPotentiallyMutatedInScope, isTrue); | |
| 1643 } | |
| 1644 { | |
| 1645 var p4 = main.parameters[3] as VariableElementImpl; | |
| 1646 expect(p4.isPotentiallyMutatedInClosure, isTrue); | |
| 1647 expect(p4.isPotentiallyMutatedInScope, isTrue); | |
| 1648 } | |
| 1649 } | 1627 } |
| 1650 } | 1628 } |
| 1651 | 1629 |
| 1652 @reflectiveTest | 1630 @reflectiveTest |
| 1653 class ScanDartTaskTest extends _AbstractDartTaskTest { | 1631 class ScanDartTaskTest extends _AbstractDartTaskTest { |
| 1654 test_buildInputs() { | 1632 test_buildInputs() { |
| 1655 Map<String, TaskInput> inputs = ScanDartTask.buildInputs(emptySource); | 1633 Map<String, TaskInput> inputs = ScanDartTask.buildInputs(emptySource); |
| 1656 expect(inputs, isNotNull); | 1634 expect(inputs, isNotNull); |
| 1657 expect(inputs.keys, unorderedEquals([ScanDartTask.CONTENT_INPUT_NAME])); | 1635 expect(inputs.keys, unorderedEquals([ScanDartTask.CONTENT_INPUT_NAME])); |
| 1658 } | 1636 } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1824 return entryMap.putIfAbsent(target, () => new CacheEntry()); | 1802 return entryMap.putIfAbsent(target, () => new CacheEntry()); |
| 1825 } | 1803 } |
| 1826 | 1804 |
| 1827 TimestampedData<String> getContents(Source source) => source.contents; | 1805 TimestampedData<String> getContents(Source source) => source.contents; |
| 1828 | 1806 |
| 1829 noSuchMethod(Invocation invocation) { | 1807 noSuchMethod(Invocation invocation) { |
| 1830 print('noSuchMethod: ${invocation.memberName}'); | 1808 print('noSuchMethod: ${invocation.memberName}'); |
| 1831 return super.noSuchMethod(invocation); | 1809 return super.noSuchMethod(invocation); |
| 1832 } | 1810 } |
| 1833 } | 1811 } |
| OLD | NEW |