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.html_test; | 5 library test.src.task.html_test; |
6 | 6 |
7 import 'package:analyzer/src/generated/source.dart'; | 7 import 'package:analyzer/src/generated/source.dart'; |
8 import 'package:analyzer/src/task/html.dart'; | 8 import 'package:analyzer/src/task/html.dart'; |
9 import 'package:analyzer/task/html.dart'; | 9 import 'package:analyzer/task/html.dart'; |
10 import 'package:analyzer/task/model.dart'; | 10 import 'package:analyzer/task/model.dart'; |
11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
12 | 12 |
13 import '../../reflective_tests.dart'; | 13 import '../../reflective_tests.dart'; |
| 14 import '../../utils.dart'; |
14 import '../context/abstract_context.dart'; | 15 import '../context/abstract_context.dart'; |
15 | 16 |
16 main() { | 17 main() { |
17 groupSep = ' | '; | 18 initializeTestEnvironment(); |
18 runReflectiveTests(DartScriptsTaskTest); | 19 runReflectiveTests(DartScriptsTaskTest); |
19 runReflectiveTests(HtmlErrorsTaskTest); | 20 runReflectiveTests(HtmlErrorsTaskTest); |
20 runReflectiveTests(ParseHtmlTaskTest); | 21 runReflectiveTests(ParseHtmlTaskTest); |
21 } | 22 } |
22 | 23 |
23 @reflectiveTest | 24 @reflectiveTest |
24 class DartScriptsTaskTest extends AbstractContextTest { | 25 class DartScriptsTaskTest extends AbstractContextTest { |
25 test_buildInputs() { | 26 test_buildInputs() { |
26 Source source = newSource('/test.html'); | 27 Source source = newSource('/test.html'); |
27 Map<String, TaskInput> inputs = DartScriptsTask.buildInputs(source); | 28 Map<String, TaskInput> inputs = DartScriptsTask.buildInputs(source); |
(...skipping 25 matching lines...) Expand all Loading... |
53 | 54 |
54 test_descriptor() { | 55 test_descriptor() { |
55 TaskDescriptor descriptor = DartScriptsTask.DESCRIPTOR; | 56 TaskDescriptor descriptor = DartScriptsTask.DESCRIPTOR; |
56 expect(descriptor, isNotNull); | 57 expect(descriptor, isNotNull); |
57 } | 58 } |
58 | 59 |
59 void test_perform_embedded_source() { | 60 void test_perform_embedded_source() { |
60 String content = r''' | 61 String content = r''' |
61 void buttonPressed() {} | 62 void buttonPressed() {} |
62 '''; | 63 '''; |
63 AnalysisTarget target = newSource('/test.html', ''' | 64 AnalysisTarget target = newSource( |
| 65 '/test.html', |
| 66 ''' |
64 <!DOCTYPE html> | 67 <!DOCTYPE html> |
65 <html> | 68 <html> |
66 <head> | 69 <head> |
67 <script type='application/dart'>$content</script> | 70 <script type='application/dart'>$content</script> |
68 </head> | 71 </head> |
69 <body> | 72 <body> |
70 </body> | 73 </body> |
71 </html>'''); | 74 </html>'''); |
72 computeResult(target, REFERENCED_LIBRARIES); | 75 computeResult(target, REFERENCED_LIBRARIES); |
73 expect(task, new isInstanceOf<DartScriptsTask>()); | 76 expect(task, new isInstanceOf<DartScriptsTask>()); |
74 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); | 77 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); |
75 expect(outputs[DART_SCRIPTS], hasLength(1)); | 78 expect(outputs[DART_SCRIPTS], hasLength(1)); |
76 DartScript script = outputs[DART_SCRIPTS][0]; | 79 DartScript script = outputs[DART_SCRIPTS][0]; |
77 expect(script.fragments, hasLength(1)); | 80 expect(script.fragments, hasLength(1)); |
78 ScriptFragment fragment = script.fragments[0]; | 81 ScriptFragment fragment = script.fragments[0]; |
79 expect(fragment.content, content); | 82 expect(fragment.content, content); |
80 } | 83 } |
81 | 84 |
82 void test_perform_empty_source_reference() { | 85 void test_perform_empty_source_reference() { |
83 AnalysisTarget target = newSource('/test.html', r''' | 86 AnalysisTarget target = newSource( |
| 87 '/test.html', |
| 88 r''' |
84 <!DOCTYPE html> | 89 <!DOCTYPE html> |
85 <html> | 90 <html> |
86 <head> | 91 <head> |
87 <script type='application/dart' src=''/> | 92 <script type='application/dart' src=''/> |
88 </head> | 93 </head> |
89 <body> | 94 <body> |
90 </body> | 95 </body> |
91 </html>'''); | 96 </html>'''); |
92 computeResult(target, REFERENCED_LIBRARIES); | 97 computeResult(target, REFERENCED_LIBRARIES); |
93 expect(task, new isInstanceOf<DartScriptsTask>()); | 98 expect(task, new isInstanceOf<DartScriptsTask>()); |
94 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); | 99 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); |
95 expect(outputs[DART_SCRIPTS], hasLength(0)); | 100 expect(outputs[DART_SCRIPTS], hasLength(0)); |
96 } | 101 } |
97 | 102 |
98 void test_perform_invalid_source_reference() { | 103 void test_perform_invalid_source_reference() { |
99 AnalysisTarget target = newSource('/test.html', r''' | 104 AnalysisTarget target = newSource( |
| 105 '/test.html', |
| 106 r''' |
100 <!DOCTYPE html> | 107 <!DOCTYPE html> |
101 <html> | 108 <html> |
102 <head> | 109 <head> |
103 <script type='application/dart' src='an;invalid:[]uri'/> | 110 <script type='application/dart' src='an;invalid:[]uri'/> |
104 </head> | 111 </head> |
105 <body> | 112 <body> |
106 </body> | 113 </body> |
107 </html>'''); | 114 </html>'''); |
108 computeResult(target, REFERENCED_LIBRARIES); | 115 computeResult(target, REFERENCED_LIBRARIES); |
109 expect(task, new isInstanceOf<DartScriptsTask>()); | 116 expect(task, new isInstanceOf<DartScriptsTask>()); |
110 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); | 117 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); |
111 expect(outputs[DART_SCRIPTS], hasLength(0)); | 118 expect(outputs[DART_SCRIPTS], hasLength(0)); |
112 } | 119 } |
113 | 120 |
114 void test_perform_non_existing_source_reference() { | 121 void test_perform_non_existing_source_reference() { |
115 AnalysisTarget target = newSource('/test.html', r''' | 122 AnalysisTarget target = newSource( |
| 123 '/test.html', |
| 124 r''' |
116 <!DOCTYPE html> | 125 <!DOCTYPE html> |
117 <html> | 126 <html> |
118 <head> | 127 <head> |
119 <script type='application/dart' src='does/not/exist.dart'/> | 128 <script type='application/dart' src='does/not/exist.dart'/> |
120 </head> | 129 </head> |
121 <body> | 130 <body> |
122 </body> | 131 </body> |
123 </html>'''); | 132 </html>'''); |
124 computeResult(target, REFERENCED_LIBRARIES); | 133 computeResult(target, REFERENCED_LIBRARIES); |
125 expect(task, new isInstanceOf<DartScriptsTask>()); | 134 expect(task, new isInstanceOf<DartScriptsTask>()); |
126 expect(outputs[REFERENCED_LIBRARIES], hasLength(1)); | 135 expect(outputs[REFERENCED_LIBRARIES], hasLength(1)); |
127 expect(outputs[DART_SCRIPTS], hasLength(0)); | 136 expect(outputs[DART_SCRIPTS], hasLength(0)); |
128 } | 137 } |
129 | 138 |
130 test_perform_none() { | 139 test_perform_none() { |
131 AnalysisTarget target = newSource('/test.html', r''' | 140 AnalysisTarget target = newSource( |
| 141 '/test.html', |
| 142 r''' |
132 <!DOCTYPE html> | 143 <!DOCTYPE html> |
133 <html> | 144 <html> |
134 <head> | 145 <head> |
135 <title>test page</title> | 146 <title>test page</title> |
136 </head> | 147 </head> |
137 <body> | 148 <body> |
138 Test | 149 Test |
139 </body> | 150 </body> |
140 </html> | 151 </html> |
141 '''); | 152 '''); |
142 computeResult(target, REFERENCED_LIBRARIES); | 153 computeResult(target, REFERENCED_LIBRARIES); |
143 expect(task, new isInstanceOf<DartScriptsTask>()); | 154 expect(task, new isInstanceOf<DartScriptsTask>()); |
144 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); | 155 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); |
145 expect(outputs[DART_SCRIPTS], hasLength(0)); | 156 expect(outputs[DART_SCRIPTS], hasLength(0)); |
146 } | 157 } |
147 | 158 |
148 void test_perform_referenced_source() { | 159 void test_perform_referenced_source() { |
149 AnalysisTarget target = newSource('/test.html', r''' | 160 AnalysisTarget target = newSource( |
| 161 '/test.html', |
| 162 r''' |
150 <!DOCTYPE html> | 163 <!DOCTYPE html> |
151 <html> | 164 <html> |
152 <head> | 165 <head> |
153 <script type='application/dart' src='test.dart'/> | 166 <script type='application/dart' src='test.dart'/> |
154 </head> | 167 </head> |
155 <body> | 168 <body> |
156 </body> | 169 </body> |
157 </html>'''); | 170 </html>'''); |
158 computeResult(target, REFERENCED_LIBRARIES); | 171 computeResult(target, REFERENCED_LIBRARIES); |
159 expect(task, new isInstanceOf<DartScriptsTask>()); | 172 expect(task, new isInstanceOf<DartScriptsTask>()); |
160 expect(outputs[REFERENCED_LIBRARIES], hasLength(1)); | 173 expect(outputs[REFERENCED_LIBRARIES], hasLength(1)); |
161 expect(outputs[DART_SCRIPTS], hasLength(0)); | 174 expect(outputs[DART_SCRIPTS], hasLength(0)); |
162 } | 175 } |
163 } | 176 } |
164 | 177 |
165 @reflectiveTest | 178 @reflectiveTest |
166 class HtmlErrorsTaskTest extends AbstractContextTest { | 179 class HtmlErrorsTaskTest extends AbstractContextTest { |
167 test_buildInputs() { | 180 test_buildInputs() { |
168 Source source = newSource('/test.html'); | 181 Source source = newSource('/test.html'); |
169 Map<String, TaskInput> inputs = HtmlErrorsTask.buildInputs(source); | 182 Map<String, TaskInput> inputs = HtmlErrorsTask.buildInputs(source); |
170 expect(inputs, isNotNull); | 183 expect(inputs, isNotNull); |
171 expect(inputs.keys, unorderedEquals([ | 184 expect( |
172 HtmlErrorsTask.DART_ERRORS_INPUT, | 185 inputs.keys, |
173 HtmlErrorsTask.DOCUMENT_ERRORS_INPUT | 186 unorderedEquals([ |
174 ])); | 187 HtmlErrorsTask.DART_ERRORS_INPUT, |
| 188 HtmlErrorsTask.DOCUMENT_ERRORS_INPUT |
| 189 ])); |
175 } | 190 } |
176 | 191 |
177 test_constructor() { | 192 test_constructor() { |
178 Source source = newSource('/test.html'); | 193 Source source = newSource('/test.html'); |
179 HtmlErrorsTask task = new HtmlErrorsTask(context, source); | 194 HtmlErrorsTask task = new HtmlErrorsTask(context, source); |
180 expect(task, isNotNull); | 195 expect(task, isNotNull); |
181 expect(task.context, context); | 196 expect(task.context, context); |
182 expect(task.target, source); | 197 expect(task.target, source); |
183 } | 198 } |
184 | 199 |
(...skipping 10 matching lines...) Expand all Loading... |
195 HtmlErrorsTask task = new HtmlErrorsTask(null, source); | 210 HtmlErrorsTask task = new HtmlErrorsTask(null, source); |
196 expect(task.description, isNotNull); | 211 expect(task.description, isNotNull); |
197 } | 212 } |
198 | 213 |
199 test_descriptor() { | 214 test_descriptor() { |
200 TaskDescriptor descriptor = HtmlErrorsTask.DESCRIPTOR; | 215 TaskDescriptor descriptor = HtmlErrorsTask.DESCRIPTOR; |
201 expect(descriptor, isNotNull); | 216 expect(descriptor, isNotNull); |
202 } | 217 } |
203 | 218 |
204 test_perform_dartErrors() { | 219 test_perform_dartErrors() { |
205 AnalysisTarget target = newSource('/test.html', r''' | 220 AnalysisTarget target = newSource( |
| 221 '/test.html', |
| 222 r''' |
206 <!DOCTYPE html> | 223 <!DOCTYPE html> |
207 <html> | 224 <html> |
208 <head> | 225 <head> |
209 <title>test page</title> | 226 <title>test page</title> |
210 <script type='application/dart'> | 227 <script type='application/dart'> |
211 void buttonPressed() { | 228 void buttonPressed() { |
212 </script> | 229 </script> |
213 </head> | 230 </head> |
214 <body>Test</body> | 231 <body>Test</body> |
215 </html> | 232 </html> |
216 '''); | 233 '''); |
217 computeResult(target, HTML_ERRORS); | 234 computeResult(target, HTML_ERRORS); |
218 expect(task, new isInstanceOf<HtmlErrorsTask>()); | 235 expect(task, new isInstanceOf<HtmlErrorsTask>()); |
219 expect(outputs[HTML_ERRORS], hasLength(1)); | 236 expect(outputs[HTML_ERRORS], hasLength(1)); |
220 } | 237 } |
221 | 238 |
222 test_perform_htmlErrors() { | 239 test_perform_htmlErrors() { |
223 AnalysisTarget target = newSource('/test.html', r''' | 240 AnalysisTarget target = newSource( |
| 241 '/test.html', |
| 242 r''' |
224 <html> | 243 <html> |
225 <head> | 244 <head> |
226 <title>test page</title> | 245 <title>test page</title> |
227 </head> | 246 </head> |
228 <body> | 247 <body> |
229 Test | 248 Test |
230 </body> | 249 </body> |
231 </html> | 250 </html> |
232 '''); | 251 '''); |
233 computeResult(target, HTML_ERRORS); | 252 computeResult(target, HTML_ERRORS); |
234 expect(task, new isInstanceOf<HtmlErrorsTask>()); | 253 expect(task, new isInstanceOf<HtmlErrorsTask>()); |
235 expect(outputs[HTML_ERRORS], hasLength(1)); | 254 expect(outputs[HTML_ERRORS], hasLength(1)); |
236 } | 255 } |
237 | 256 |
238 test_perform_noErrors() { | 257 test_perform_noErrors() { |
239 AnalysisTarget target = newSource('/test.html', r''' | 258 AnalysisTarget target = newSource( |
| 259 '/test.html', |
| 260 r''' |
240 <!DOCTYPE html> | 261 <!DOCTYPE html> |
241 <html> | 262 <html> |
242 <head> | 263 <head> |
243 <title>test page</title> | 264 <title>test page</title> |
244 </head> | 265 </head> |
245 <body> | 266 <body> |
246 Test | 267 Test |
247 </body> | 268 </body> |
248 </html> | 269 </html> |
249 '''); | 270 '''); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 ParseHtmlTask task = new ParseHtmlTask(null, source); | 304 ParseHtmlTask task = new ParseHtmlTask(null, source); |
284 expect(task.description, isNotNull); | 305 expect(task.description, isNotNull); |
285 } | 306 } |
286 | 307 |
287 test_descriptor() { | 308 test_descriptor() { |
288 TaskDescriptor descriptor = ParseHtmlTask.DESCRIPTOR; | 309 TaskDescriptor descriptor = ParseHtmlTask.DESCRIPTOR; |
289 expect(descriptor, isNotNull); | 310 expect(descriptor, isNotNull); |
290 } | 311 } |
291 | 312 |
292 test_perform() { | 313 test_perform() { |
293 AnalysisTarget target = newSource('/test.html', r''' | 314 AnalysisTarget target = newSource( |
| 315 '/test.html', |
| 316 r''' |
294 <!DOCTYPE html> | 317 <!DOCTYPE html> |
295 <html> | 318 <html> |
296 <head> | 319 <head> |
297 <title>test page</title> | 320 <title>test page</title> |
298 </head> | 321 </head> |
299 <body> | 322 <body> |
300 <h1 Test> | 323 <h1 Test> |
301 </body> | 324 </body> |
302 </html> | 325 </html> |
303 '''); | 326 '''); |
304 computeResult(target, HTML_DOCUMENT); | 327 computeResult(target, HTML_DOCUMENT); |
305 expect(task, new isInstanceOf<ParseHtmlTask>()); | 328 expect(task, new isInstanceOf<ParseHtmlTask>()); |
306 expect(outputs[HTML_DOCUMENT], isNotNull); | 329 expect(outputs[HTML_DOCUMENT], isNotNull); |
307 expect(outputs[HTML_DOCUMENT_ERRORS], isNotEmpty); | 330 expect(outputs[HTML_DOCUMENT_ERRORS], isNotEmpty); |
308 } | 331 } |
309 } | 332 } |
OLD | NEW |