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

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1132103002: Remove memento. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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
OLDNEW
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/context/cache.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/element.dart'; 9 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/error.dart'; 10 import 'package:analyzer/src/generated/error.dart';
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 part 'part.dart'; 201 part 'part.dart';
202 class A {} 202 class A {}
203 class B = Object with A; 203 class B = Object with A;
204 '''); 204 ''');
205 expect(outputs, hasLength(3)); 205 expect(outputs, hasLength(3));
206 expect(outputs[CLASS_ELEMENTS], hasLength(2)); 206 expect(outputs[CLASS_ELEMENTS], hasLength(2));
207 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); 207 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull);
208 expect(outputs[RESOLVED_UNIT1], isNotNull); 208 expect(outputs[RESOLVED_UNIT1], isNotNull);
209 } 209 }
210 210
211 test_perform_useMemento() {
212 Source source = newSource('/test.dart', r'''
213 class A {}
214 class B {}
215 class C {}
216 ''');
217 AnalysisTarget target = new LibrarySpecificUnit(source, source);
218 _computeResult(target, RESOLVED_UNIT1);
219 // update content
220 context.setContents(source, r'''
221 class C {}
222 class A {}
223 class B {}
224 ''');
225 assertIsInvalid(target, RESOLVED_UNIT1);
226 // recompute
227 _computeResult(target, RESOLVED_UNIT1);
228 assertIsValid(target, RESOLVED_UNIT1);
229 // values are produced using memento
230 List<ClassElement> newClassElements = outputs[CLASS_ELEMENTS];
231 CompilationUnit newUnit = outputs[RESOLVED_UNIT1];
232 CompilationUnitElement newUnitElement = outputs[COMPILATION_UNIT_ELEMENT];
233 expect(
234 newClassElements.map((_) => _.name), unorderedEquals(['A', 'B', 'C']));
235 expect(newUnitElement, same(oldOutputs[COMPILATION_UNIT_ELEMENT]));
236 expect(newUnit.element, newUnitElement);
237 }
238
239 void _performBuildTask(String content) { 211 void _performBuildTask(String content) {
240 Source source = newSource('/test.dart', content); 212 Source source = newSource('/test.dart', content);
241 AnalysisTarget target = new LibrarySpecificUnit(source, source); 213 AnalysisTarget target = new LibrarySpecificUnit(source, source);
242 _computeResult(target, RESOLVED_UNIT1); 214 _computeResult(target, RESOLVED_UNIT1);
243 expect(task, new isInstanceOf<BuildCompilationUnitElementTask>()); 215 expect(task, new isInstanceOf<BuildCompilationUnitElementTask>());
244 } 216 }
245 } 217 }
246 218
247 @reflectiveTest 219 @reflectiveTest
248 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { 220 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest {
(...skipping 1498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); 1719 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1));
1748 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); 1720 expect(outputs[EXPORTED_LIBRARIES], hasLength(1));
1749 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); 1721 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2);
1750 expect(outputs[INCLUDED_PARTS], hasLength(1)); 1722 expect(outputs[INCLUDED_PARTS], hasLength(1));
1751 expect(outputs[PARSE_ERRORS], hasLength(1)); 1723 expect(outputs[PARSE_ERRORS], hasLength(1));
1752 expect(outputs[PARSED_UNIT], isNotNull); 1724 expect(outputs[PARSED_UNIT], isNotNull);
1753 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); 1725 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY);
1754 expect(outputs[UNITS], hasLength(2)); 1726 expect(outputs[UNITS], hasLength(2));
1755 } 1727 }
1756 1728
1757 test_perform_useMemento() {
1758 String content = r'''
1759 library lib;
1760 import 'lib2.dart';
1761 export 'lib3.dart';
1762 part 'part.dart';
1763 class A {''';
1764 AnalysisTarget target = newSource('/test.dart', content);
1765 _computeResult(target, PARSED_UNIT);
1766 // update content
1767 context.setContents(target, content);
1768 assertIsInvalid(target, PARSED_UNIT);
1769 // recompute
1770 _computeResult(target, PARSED_UNIT);
1771 assertIsValid(target, PARSED_UNIT);
1772 // values from the memento are returned
1773 assertSameResults(ParseDartTask.DESCRIPTOR.results);
1774 }
1775
1776 void _performParseTask(String content) { 1729 void _performParseTask(String content) {
1777 AnalysisTarget target = newSource('/test.dart', content); 1730 AnalysisTarget target = newSource('/test.dart', content);
1778 _computeResult(target, PARSED_UNIT); 1731 _computeResult(target, PARSED_UNIT);
1779 expect(task, new isInstanceOf<ParseDartTask>()); 1732 expect(task, new isInstanceOf<ParseDartTask>());
1780 } 1733 }
1781 1734
1782 static void _assertHasCore(List<Source> sources, int lenght) { 1735 static void _assertHasCore(List<Source> sources, int lenght) {
1783 expect(sources, hasLength(lenght)); 1736 expect(sources, hasLength(lenght));
1784 expect(sources, contains(predicate((Source s) { 1737 expect(sources, contains(predicate((Source s) {
1785 return s.fullName.endsWith('core.dart'); 1738 return s.fullName.endsWith('core.dart');
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 } 2008 }
2056 2009
2057 test_perform_noErrors() { 2010 test_perform_noErrors() {
2058 _performScanTask('class A {}'); 2011 _performScanTask('class A {}');
2059 expect(outputs, hasLength(3)); 2012 expect(outputs, hasLength(3));
2060 expect(outputs[LINE_INFO], isNotNull); 2013 expect(outputs[LINE_INFO], isNotNull);
2061 expect(outputs[SCAN_ERRORS], hasLength(0)); 2014 expect(outputs[SCAN_ERRORS], hasLength(0));
2062 expect(outputs[TOKEN_STREAM], isNotNull); 2015 expect(outputs[TOKEN_STREAM], isNotNull);
2063 } 2016 }
2064 2017
2065 test_perform_useMemento() {
2066 AnalysisTarget target = newSource('/test.dart', 'main() {}');
2067 _computeResult(target, TOKEN_STREAM);
2068 // update content
2069 context.setContents(target, 'main() {}');
2070 assertIsInvalid(target, TOKEN_STREAM);
2071 // recompute
2072 _computeResult(target, TOKEN_STREAM);
2073 assertIsValid(target, TOKEN_STREAM);
2074 // values from the memento are returned
2075 assertSameResults(ScanDartTask.DESCRIPTOR.results);
2076 }
2077
2078 void _performScanTask(String content) { 2018 void _performScanTask(String content) {
2079 AnalysisTarget target = newSource('/test.dart', content); 2019 AnalysisTarget target = newSource('/test.dart', content);
2080 _computeResult(target, TOKEN_STREAM); 2020 _computeResult(target, TOKEN_STREAM);
2081 expect(task, new isInstanceOf<ScanDartTask>()); 2021 expect(task, new isInstanceOf<ScanDartTask>());
2082 } 2022 }
2083 } 2023 }
2084 2024
2085 @reflectiveTest 2025 @reflectiveTest
2086 class VerifyUnitTaskTest extends _AbstractDartTaskTest { 2026 class VerifyUnitTaskTest extends _AbstractDartTaskTest {
2087 test_perform_verifyError() { 2027 test_perform_verifyError() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2143 /** 2083 /**
2144 * Fill [errorListener] with [result] errors in the current [task]. 2084 * Fill [errorListener] with [result] errors in the current [task].
2145 */ 2085 */
2146 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 2086 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
2147 List<AnalysisError> errors = task.outputs[result]; 2087 List<AnalysisError> errors = task.outputs[result];
2148 expect(errors, isNotNull, reason: result.name); 2088 expect(errors, isNotNull, reason: result.name);
2149 errorListener = new GatheringErrorListener(); 2089 errorListener = new GatheringErrorListener();
2150 errorListener.addAll(errors); 2090 errorListener.addAll(errors);
2151 } 2091 }
2152 } 2092 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/context/cache_test.dart ('k') | pkg/analyzer/test/src/task/driver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698