| 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/src/context/cache.dart'; |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 9 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/error.dart'; | 10 import 'package:analyzer/src/generated/error.dart'; |
| 10 import 'package:analyzer/src/generated/resolver.dart'; | 11 import 'package:analyzer/src/generated/resolver.dart'; |
| 11 import 'package:analyzer/src/generated/source.dart'; | 12 import 'package:analyzer/src/generated/source.dart'; |
| 12 import 'package:analyzer/src/task/dart.dart'; | 13 import 'package:analyzer/src/task/dart.dart'; |
| 13 import 'package:analyzer/task/dart.dart'; | 14 import 'package:analyzer/task/dart.dart'; |
| 14 import 'package:analyzer/task/general.dart'; | 15 import 'package:analyzer/task/general.dart'; |
| 15 import 'package:analyzer/task/model.dart'; | 16 import 'package:analyzer/task/model.dart'; |
| 16 import 'package:unittest/unittest.dart'; | 17 import 'package:unittest/unittest.dart'; |
| (...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1506 expect(outputs, hasLength(7)); | 1507 expect(outputs, hasLength(7)); |
| 1507 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); | 1508 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); |
| 1508 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); | 1509 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); |
| 1509 expect(outputs[INCLUDED_PARTS], hasLength(1)); | 1510 expect(outputs[INCLUDED_PARTS], hasLength(1)); |
| 1510 expect(outputs[PARSE_ERRORS], hasLength(1)); | 1511 expect(outputs[PARSE_ERRORS], hasLength(1)); |
| 1511 expect(outputs[PARSED_UNIT], isNotNull); | 1512 expect(outputs[PARSED_UNIT], isNotNull); |
| 1512 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 1513 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 1513 expect(outputs[UNITS], hasLength(2)); | 1514 expect(outputs[UNITS], hasLength(2)); |
| 1514 } | 1515 } |
| 1515 | 1516 |
| 1517 test_perform_useMemento() { |
| 1518 String content = r''' |
| 1519 library lib; |
| 1520 import 'lib2.dart'; |
| 1521 export 'lib3.dart'; |
| 1522 part 'part.dart'; |
| 1523 class A {'''; |
| 1524 AnalysisTarget target = newSource('/test.dart', content); |
| 1525 _computeResult(target, PARSED_UNIT); |
| 1526 // update content |
| 1527 context.setContents(target, content); |
| 1528 assertIsInvalid(target, PARSED_UNIT); |
| 1529 // recompute |
| 1530 _computeResult(target, PARSED_UNIT); |
| 1531 assertIsValid(target, PARSED_UNIT); |
| 1532 // values from the memento are returned |
| 1533 assertSameResults(ParseDartTask.DESCRIPTOR.results); |
| 1534 } |
| 1535 |
| 1516 void _performParseTask(String content) { | 1536 void _performParseTask(String content) { |
| 1517 AnalysisTarget target = newSource('/test.dart', content); | 1537 AnalysisTarget target = newSource('/test.dart', content); |
| 1518 _computeResult(target, PARSED_UNIT); | 1538 _computeResult(target, PARSED_UNIT); |
| 1519 expect(task, new isInstanceOf<ParseDartTask>()); | 1539 expect(task, new isInstanceOf<ParseDartTask>()); |
| 1520 } | 1540 } |
| 1521 | 1541 |
| 1522 static void _assertHasCore(List<Source> sources, int lenght) { | 1542 static void _assertHasCore(List<Source> sources, int lenght) { |
| 1523 expect(sources, hasLength(lenght)); | 1543 expect(sources, hasLength(lenght)); |
| 1524 expect(sources, contains(predicate((Source s) { | 1544 expect(sources, contains(predicate((Source s) { |
| 1525 return s.fullName.endsWith('core.dart'); | 1545 return s.fullName.endsWith('core.dart'); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1800 expect(outputs[LINE_INFO], isNotNull); | 1820 expect(outputs[LINE_INFO], isNotNull); |
| 1801 expect(outputs[SCAN_ERRORS], hasLength(0)); | 1821 expect(outputs[SCAN_ERRORS], hasLength(0)); |
| 1802 expect(outputs[TOKEN_STREAM], isNotNull); | 1822 expect(outputs[TOKEN_STREAM], isNotNull); |
| 1803 } | 1823 } |
| 1804 | 1824 |
| 1805 test_perform_useMemento() { | 1825 test_perform_useMemento() { |
| 1806 AnalysisTarget target = newSource('/test.dart', 'main() {}'); | 1826 AnalysisTarget target = newSource('/test.dart', 'main() {}'); |
| 1807 _computeResult(target, TOKEN_STREAM); | 1827 _computeResult(target, TOKEN_STREAM); |
| 1808 // update content | 1828 // update content |
| 1809 context.setContents(target, 'main() {}'); | 1829 context.setContents(target, 'main() {}'); |
| 1830 assertIsInvalid(target, TOKEN_STREAM); |
| 1810 // recompute | 1831 // recompute |
| 1811 _computeResult(target, TOKEN_STREAM); | 1832 _computeResult(target, TOKEN_STREAM); |
| 1812 // values from the mememto are returned | 1833 assertIsValid(target, TOKEN_STREAM); |
| 1813 assertSameResults([LINE_INFO, SCAN_ERRORS, TOKEN_STREAM]); | 1834 // values from the memento are returned |
| 1835 assertSameResults(ScanDartTask.DESCRIPTOR.results); |
| 1814 } | 1836 } |
| 1815 | 1837 |
| 1816 void _performScanTask(String content) { | 1838 void _performScanTask(String content) { |
| 1817 AnalysisTarget target = newSource('/test.dart', content); | 1839 AnalysisTarget target = newSource('/test.dart', content); |
| 1818 _computeResult(target, TOKEN_STREAM); | 1840 _computeResult(target, TOKEN_STREAM); |
| 1819 expect(task, new isInstanceOf<ScanDartTask>()); | 1841 expect(task, new isInstanceOf<ScanDartTask>()); |
| 1820 } | 1842 } |
| 1821 } | 1843 } |
| 1822 | 1844 |
| 1823 @reflectiveTest | 1845 @reflectiveTest |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1841 } | 1863 } |
| 1842 | 1864 |
| 1843 class _AbstractDartTaskTest extends AbstractContextTest { | 1865 class _AbstractDartTaskTest extends AbstractContextTest { |
| 1844 Source emptySource; | 1866 Source emptySource; |
| 1845 | 1867 |
| 1846 AnalysisTask task; | 1868 AnalysisTask task; |
| 1847 Map<ResultDescriptor<dynamic>, dynamic> oldOutputs; | 1869 Map<ResultDescriptor<dynamic>, dynamic> oldOutputs; |
| 1848 Map<ResultDescriptor<dynamic>, dynamic> outputs; | 1870 Map<ResultDescriptor<dynamic>, dynamic> outputs; |
| 1849 GatheringErrorListener errorListener = new GatheringErrorListener(); | 1871 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 1850 | 1872 |
| 1873 void assertIsInvalid(AnalysisTarget target, ResultDescriptor descriptor) { |
| 1874 CacheEntry entry = context.getCacheEntry(target); |
| 1875 expect(entry.isInvalid(descriptor), isTrue); |
| 1876 } |
| 1877 |
| 1878 void assertIsValid(AnalysisTarget target, ResultDescriptor descriptor) { |
| 1879 CacheEntry entry = context.getCacheEntry(target); |
| 1880 expect(entry.isValid(descriptor), isTrue); |
| 1881 } |
| 1882 |
| 1851 void assertSameResults(List<ResultDescriptor> descriptors) { | 1883 void assertSameResults(List<ResultDescriptor> descriptors) { |
| 1852 descriptors.forEach((descriptor) { | 1884 descriptors.forEach((descriptor) { |
| 1853 var oldResult = oldOutputs[descriptor]; | 1885 var oldResult = oldOutputs[descriptor]; |
| 1854 var newResult = outputs[descriptor]; | 1886 var newResult = outputs[descriptor]; |
| 1855 expect(newResult, same(oldResult), reason: descriptor.name); | 1887 expect(newResult, same(oldResult), reason: descriptor.name); |
| 1856 }); | 1888 }); |
| 1857 } | 1889 } |
| 1858 | 1890 |
| 1859 void setUp() { | 1891 void setUp() { |
| 1860 super.setUp(); | 1892 super.setUp(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1871 /** | 1903 /** |
| 1872 * Fill [errorListener] with [result] errors in the current [task]. | 1904 * Fill [errorListener] with [result] errors in the current [task]. |
| 1873 */ | 1905 */ |
| 1874 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 1906 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 1875 List<AnalysisError> errors = task.outputs[result]; | 1907 List<AnalysisError> errors = task.outputs[result]; |
| 1876 expect(errors, isNotNull, reason: result.name); | 1908 expect(errors, isNotNull, reason: result.name); |
| 1877 errorListener = new GatheringErrorListener(); | 1909 errorListener = new GatheringErrorListener(); |
| 1878 errorListener.addAll(errors); | 1910 errorListener.addAll(errors); |
| 1879 } | 1911 } |
| 1880 } | 1912 } |
| OLD | NEW |