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 library test.src.context.context_test; | 5 library test.src.context.context_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analyzer/src/cancelable_future.dart'; | 9 import 'package:analyzer/src/cancelable_future.dart'; |
10 import 'package:analyzer/src/context/cache.dart'; | 10 import 'package:analyzer/src/context/cache.dart'; |
(...skipping 11 matching lines...) Expand all Loading... |
22 AnalysisNotScheduledError, | 22 AnalysisNotScheduledError, |
23 AnalysisOptions, | 23 AnalysisOptions, |
24 AnalysisOptionsImpl, | 24 AnalysisOptionsImpl, |
25 AnalysisResult, | 25 AnalysisResult, |
26 CacheState, | 26 CacheState, |
27 ChangeNotice, | 27 ChangeNotice, |
28 ChangeSet, | 28 ChangeSet, |
29 IncrementalAnalysisCache, | 29 IncrementalAnalysisCache, |
30 TimestampedData; | 30 TimestampedData; |
31 import 'package:analyzer/src/generated/error.dart'; | 31 import 'package:analyzer/src/generated/error.dart'; |
32 import 'package:analyzer/src/generated/html.dart' as ht; | |
33 import 'package:analyzer/src/generated/java_engine.dart'; | 32 import 'package:analyzer/src/generated/java_engine.dart'; |
34 import 'package:analyzer/src/generated/resolver.dart'; | 33 import 'package:analyzer/src/generated/resolver.dart'; |
35 import 'package:analyzer/src/generated/scanner.dart'; | 34 import 'package:analyzer/src/generated/scanner.dart'; |
36 import 'package:analyzer/src/generated/source.dart'; | 35 import 'package:analyzer/src/generated/source.dart'; |
37 import 'package:analyzer/src/task/dart.dart'; | 36 import 'package:analyzer/src/task/dart.dart'; |
| 37 import 'package:analyzer/src/task/html.dart'; |
38 import 'package:analyzer/task/dart.dart'; | 38 import 'package:analyzer/task/dart.dart'; |
39 import 'package:analyzer/task/model.dart'; | 39 import 'package:analyzer/task/model.dart'; |
40 import 'package:html/dom.dart' show Document; | 40 import 'package:html/dom.dart' show Document; |
41 import 'package:unittest/unittest.dart'; | 41 import 'package:unittest/unittest.dart'; |
42 import 'package:watcher/src/utils.dart'; | 42 import 'package:watcher/src/utils.dart'; |
43 | 43 |
44 import '../../generated/engine_test.dart'; | 44 import '../../generated/engine_test.dart'; |
45 import '../../generated/test_support.dart'; | 45 import '../../generated/test_support.dart'; |
46 import '../../reflective_tests.dart'; | 46 import '../../reflective_tests.dart'; |
47 import 'abstract_context.dart'; | 47 import 'abstract_context.dart'; |
48 import 'package:analyzer/src/task/html.dart'; | |
49 | 48 |
50 main() { | 49 main() { |
51 groupSep = ' | '; | 50 groupSep = ' | '; |
52 runReflectiveTests(AnalysisContextImplTest); | 51 runReflectiveTests(AnalysisContextImplTest); |
53 runReflectiveTests(LimitedInvalidateTest); | 52 runReflectiveTests(LimitedInvalidateTest); |
54 } | 53 } |
55 | 54 |
56 @reflectiveTest | 55 @reflectiveTest |
57 class AnalysisContextImplTest extends AbstractContextTest { | 56 class AnalysisContextImplTest extends AbstractContextTest { |
58 void test_parseHtmlUnit_resolveDirectives() { | |
59 Source libSource = addSource("/lib.dart", r''' | |
60 library lib; | |
61 class ClassA {}'''); | |
62 Source source = addSource("/lib.html", r''' | |
63 <!DOCTYPE html> | |
64 <html> | |
65 <head> | |
66 <script type='application/dart'> | |
67 import 'lib.dart'; | |
68 ClassA v = null; | |
69 </script> | |
70 </head> | |
71 <body> | |
72 </body> | |
73 </html>'''); | |
74 Document document = context.parseHtmlDocument(source); | |
75 expect(document, isNotNull); | |
76 List<DartScript> scripts = context.computeResult(source, DART_SCRIPTS); | |
77 expect(scripts, hasLength(1)); | |
78 CompilationUnit unit = context.computeResult(scripts[0], PARSED_UNIT); | |
79 ImportDirective importNode = unit.directives[0] as ImportDirective; | |
80 expect(importNode.uriContent, isNotNull); | |
81 expect(importNode.source, libSource); | |
82 } | |
83 | |
84 void fail_performAnalysisTask_importedLibraryDelete_html() { | 57 void fail_performAnalysisTask_importedLibraryDelete_html() { |
85 // NOTE: This was failing before converting to the new task model. | 58 // NOTE: This was failing before converting to the new task model. |
86 Source htmlSource = addSource("/page.html", r''' | 59 Source htmlSource = addSource("/page.html", r''' |
87 <html><body><script type="application/dart"> | 60 <html><body><script type="application/dart"> |
88 import 'libB.dart'; | 61 import 'libB.dart'; |
89 main() {print('hello dart');} | 62 main() {print('hello dart');} |
90 </script></body></html>'''); | 63 </script></body></html>'''); |
91 Source libBSource = addSource("/libB.dart", "library libB;"); | 64 Source libBSource = addSource("/libB.dart", "library libB;"); |
92 _analyzeAll_assertFinished(); | 65 _analyzeAll_assertFinished(); |
93 context.computeErrors(htmlSource); | 66 context.computeErrors(htmlSource); |
94 expect( | 67 expect( |
95 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, | 68 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, |
96 reason: "libB resolved 1"); | 69 reason: "libB resolved 1"); |
97 expect(!_hasAnalysisErrorWithErrorSeverity(context.getErrors(htmlSource)), | 70 expect(!_hasAnalysisErrorWithErrorSeverity(context.getErrors(htmlSource)), |
98 isTrue, reason: "htmlSource doesn't have errors"); | 71 isTrue, reason: "htmlSource doesn't have errors"); |
99 // remove libB.dart content and analyze | 72 // remove libB.dart content and analyze |
100 context.setContents(libBSource, null); | 73 context.setContents(libBSource, null); |
101 _analyzeAll_assertFinished(); | 74 _analyzeAll_assertFinished(); |
102 context.computeErrors(htmlSource); | 75 context.computeErrors(htmlSource); |
103 AnalysisErrorInfo errors = context.getErrors(htmlSource); | 76 AnalysisErrorInfo errors = context.getErrors(htmlSource); |
104 expect(_hasAnalysisErrorWithErrorSeverity(errors), isTrue, | 77 expect(_hasAnalysisErrorWithErrorSeverity(errors), isTrue, |
105 reason: "htmlSource has an error"); | 78 reason: "htmlSource has an error"); |
106 } | 79 } |
107 | 80 |
108 void fail_recordLibraryElements() { | 81 void fail_recordLibraryElements() { |
109 fail("Implement this"); | 82 fail("Implement this"); |
110 } | 83 } |
111 | 84 |
112 void fail_unreadableSource() { | |
113 Source test1 = addSource("/test1.dart", r''' | |
114 import 'test2.dart'; | |
115 library test1;'''); | |
116 Source test2 = addSource("/test2.dart", r''' | |
117 import 'test1.dart'; | |
118 import 'test3.dart'; | |
119 library test2;'''); | |
120 Source test3 = _addSourceWithException("/test3.dart"); | |
121 _analyzeAll_assertFinished(); | |
122 // test1 and test2 should have been successfully analyzed | |
123 // despite the fact that test3 couldn't be read. | |
124 expect(context.computeLibraryElement(test1), isNotNull); | |
125 expect(context.computeLibraryElement(test2), isNotNull); | |
126 expect(context.computeLibraryElement(test3), isNull); | |
127 } | |
128 | |
129 @override | 85 @override |
130 void tearDown() { | 86 void tearDown() { |
131 context = null; | 87 context = null; |
132 sourceFactory = null; | 88 sourceFactory = null; |
133 super.tearDown(); | 89 super.tearDown(); |
134 } | 90 } |
135 | 91 |
136 Future test_applyChanges_add() { | 92 Future test_applyChanges_add() { |
137 SourcesChangedListener listener = new SourcesChangedListener(); | 93 SourcesChangedListener listener = new SourcesChangedListener(); |
138 context.onSourcesChanged.listen(listener.onData); | 94 context.onSourcesChanged.listen(listener.onData); |
(...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 // Expected result | 1249 // Expected result |
1294 } | 1250 } |
1295 } | 1251 } |
1296 | 1252 |
1297 void test_parseHtmlDocument() { | 1253 void test_parseHtmlDocument() { |
1298 Source source = addSource("/lib.html", "<!DOCTYPE html><html></html>"); | 1254 Source source = addSource("/lib.html", "<!DOCTYPE html><html></html>"); |
1299 Document document = context.parseHtmlDocument(source); | 1255 Document document = context.parseHtmlDocument(source); |
1300 expect(document, isNotNull); | 1256 expect(document, isNotNull); |
1301 } | 1257 } |
1302 | 1258 |
| 1259 void test_parseHtmlUnit_resolveDirectives() { |
| 1260 Source libSource = addSource("/lib.dart", r''' |
| 1261 library lib; |
| 1262 class ClassA {}'''); |
| 1263 Source source = addSource("/lib.html", r''' |
| 1264 <!DOCTYPE html> |
| 1265 <html> |
| 1266 <head> |
| 1267 <script type='application/dart'> |
| 1268 import 'lib.dart'; |
| 1269 ClassA v = null; |
| 1270 </script> |
| 1271 </head> |
| 1272 <body> |
| 1273 </body> |
| 1274 </html>'''); |
| 1275 Document document = context.parseHtmlDocument(source); |
| 1276 expect(document, isNotNull); |
| 1277 List<DartScript> scripts = context.computeResult(source, DART_SCRIPTS); |
| 1278 expect(scripts, hasLength(1)); |
| 1279 CompilationUnit unit = context.computeResult(scripts[0], PARSED_UNIT); |
| 1280 ImportDirective importNode = unit.directives[0] as ImportDirective; |
| 1281 expect(importNode.uriContent, isNotNull); |
| 1282 expect(importNode.source, libSource); |
| 1283 } |
| 1284 |
1303 void test_performAnalysisTask_addPart() { | 1285 void test_performAnalysisTask_addPart() { |
1304 Source libSource = addSource("/lib.dart", r''' | 1286 Source libSource = addSource("/lib.dart", r''' |
1305 library lib; | 1287 library lib; |
1306 part 'part.dart';'''); | 1288 part 'part.dart';'''); |
1307 // run all tasks without part | 1289 // run all tasks without part |
1308 _analyzeAll_assertFinished(); | 1290 _analyzeAll_assertFinished(); |
1309 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libSource)), | 1291 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libSource)), |
1310 isTrue, reason: "lib has errors"); | 1292 isTrue, reason: "lib has errors"); |
1311 // add part and run all tasks | 1293 // add part and run all tasks |
1312 Source partSource = addSource("/part.dart", r''' | 1294 Source partSource = addSource("/part.dart", r''' |
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2253 } | 2235 } |
2254 } | 2236 } |
2255 | 2237 |
2256 class _AnalysisContextImplTest_test_applyChanges_removeContainer | 2238 class _AnalysisContextImplTest_test_applyChanges_removeContainer |
2257 implements SourceContainer { | 2239 implements SourceContainer { |
2258 Source libB; | 2240 Source libB; |
2259 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); | 2241 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); |
2260 @override | 2242 @override |
2261 bool contains(Source source) => source == libB; | 2243 bool contains(Source source) => source == libB; |
2262 } | 2244 } |
OLD | NEW |