| 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/general.dart'; | 9 import 'package:analyzer/task/general.dart'; |
| 10 import 'package:analyzer/task/html.dart'; | 10 import 'package:analyzer/task/html.dart'; |
| 11 import 'package:analyzer/task/model.dart'; | 11 import 'package:analyzer/task/model.dart'; |
| 12 import 'package:html/dom.dart'; |
| 12 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 13 | 14 |
| 14 import '../../reflective_tests.dart'; | 15 import '../../reflective_tests.dart'; |
| 15 import '../../utils.dart'; | 16 import '../../utils.dart'; |
| 16 import '../context/abstract_context.dart'; | 17 import '../context/abstract_context.dart'; |
| 17 | 18 |
| 18 main() { | 19 main() { |
| 19 initializeTestEnvironment(); | 20 initializeTestEnvironment(); |
| 20 runReflectiveTests(DartScriptsTaskTest); | 21 runReflectiveTests(DartScriptsTaskTest); |
| 21 runReflectiveTests(HtmlErrorsTaskTest); | 22 runReflectiveTests(HtmlErrorsTaskTest); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 computeResult(target, HTML_ERRORS, matcher: isHtmlErrorsTask); | 222 computeResult(target, HTML_ERRORS, matcher: isHtmlErrorsTask); |
| 222 expect(outputs[HTML_ERRORS], hasLength(1)); | 223 expect(outputs[HTML_ERRORS], hasLength(1)); |
| 223 } | 224 } |
| 224 | 225 |
| 225 test_perform_htmlErrors() { | 226 test_perform_htmlErrors() { |
| 226 AnalysisTarget target = newSource( | 227 AnalysisTarget target = newSource( |
| 227 '/test.html', | 228 '/test.html', |
| 228 r''' | 229 r''' |
| 229 <html> | 230 <html> |
| 230 <head> | 231 <head> |
| 231 <title>test page</title> | 232 <title>test page</not-title> |
| 232 </head> | 233 </head> |
| 233 <body> | 234 <body> |
| 234 Test | 235 Test |
| 235 </body> | 236 </body> |
| 236 </html> | 237 </html> |
| 237 '''); | 238 '''); |
| 238 computeResult(target, HTML_ERRORS, matcher: isHtmlErrorsTask); | 239 computeResult(target, HTML_ERRORS, matcher: isHtmlErrorsTask); |
| 239 expect(outputs[HTML_ERRORS], hasLength(1)); | 240 expect(outputs[HTML_ERRORS], hasLength(1)); |
| 240 } | 241 } |
| 241 | 242 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 expect(location.columnNumber, 1); | 329 expect(location.columnNumber, 1); |
| 329 } | 330 } |
| 330 { | 331 { |
| 331 int offset = code.indexOf('<title>'); | 332 int offset = code.indexOf('<title>'); |
| 332 LineInfo_Location location = lineInfo.getLocation(offset); | 333 LineInfo_Location location = lineInfo.getLocation(offset); |
| 333 expect(location.lineNumber, 4); | 334 expect(location.lineNumber, 4); |
| 334 expect(location.columnNumber, 5); | 335 expect(location.columnNumber, 5); |
| 335 } | 336 } |
| 336 } | 337 } |
| 337 } | 338 } |
| 339 |
| 340 test_perform_noDocType() { |
| 341 String code = r''' |
| 342 <div>AAA</div> |
| 343 <span>BBB</span> |
| 344 '''; |
| 345 AnalysisTarget target = newSource('/test.html', code); |
| 346 computeResult(target, HTML_DOCUMENT); |
| 347 expect(task, isParseHtmlTask); |
| 348 // validate Document |
| 349 { |
| 350 Document document = outputs[HTML_DOCUMENT]; |
| 351 expect(document, isNotNull); |
| 352 // artificial <html> |
| 353 expect(document.nodes, hasLength(1)); |
| 354 Element htmlElement = document.nodes[0]; |
| 355 expect(htmlElement.localName, 'html'); |
| 356 // artificial <body> |
| 357 expect(htmlElement.nodes, hasLength(2)); |
| 358 Element bodyElement = htmlElement.nodes[1]; |
| 359 expect(bodyElement.localName, 'body'); |
| 360 // actual nodes |
| 361 expect(bodyElement.nodes, hasLength(4)); |
| 362 expect((bodyElement.nodes[0] as Element).localName, 'div'); |
| 363 expect((bodyElement.nodes[2] as Element).localName, 'span'); |
| 364 } |
| 365 // it's OK to don't have DOCTYPE |
| 366 expect(outputs[HTML_DOCUMENT_ERRORS], isEmpty); |
| 367 } |
| 338 } | 368 } |
| OLD | NEW |