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