| 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 '../../utils.dart'; |
| 15 import '../context/abstract_context.dart'; | 15 import '../context/abstract_context.dart'; |
| 16 | 16 |
| 17 main() { | 17 main() { |
| 18 initializeTestEnvironment(); | 18 initializeTestEnvironment(); |
| 19 runReflectiveTests(DartScriptsTaskTest); | 19 runReflectiveTests(DartScriptsTaskTest); |
| 20 runReflectiveTests(HtmlErrorsTaskTest); | 20 runReflectiveTests(HtmlErrorsTaskTest); |
| 21 runReflectiveTests(ParseHtmlTaskTest); | 21 runReflectiveTests(ParseHtmlTaskTest); |
| 22 } | 22 } |
| 23 | 23 |
| 24 isInstanceOf isDartScriptsTask = new isInstanceOf<DartScriptsTask>(); |
| 25 isInstanceOf isHtmlErrorsTask = new isInstanceOf<HtmlErrorsTask>(); |
| 26 isInstanceOf isParseHtmlTask = new isInstanceOf<ParseHtmlTask>(); |
| 27 |
| 24 @reflectiveTest | 28 @reflectiveTest |
| 25 class DartScriptsTaskTest extends AbstractContextTest { | 29 class DartScriptsTaskTest extends AbstractContextTest { |
| 26 test_buildInputs() { | 30 test_buildInputs() { |
| 27 Source source = newSource('/test.html'); | 31 Source source = newSource('/test.html'); |
| 28 Map<String, TaskInput> inputs = DartScriptsTask.buildInputs(source); | 32 Map<String, TaskInput> inputs = DartScriptsTask.buildInputs(source); |
| 29 expect(inputs, isNotNull); | 33 expect(inputs, isNotNull); |
| 30 expect(inputs.keys, unorderedEquals([DartScriptsTask.DOCUMENT_INPUT])); | 34 expect(inputs.keys, unorderedEquals([DartScriptsTask.DOCUMENT_INPUT])); |
| 31 } | 35 } |
| 32 | 36 |
| 33 test_constructor() { | 37 test_constructor() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 '/test.html', | 69 '/test.html', |
| 66 ''' | 70 ''' |
| 67 <!DOCTYPE html> | 71 <!DOCTYPE html> |
| 68 <html> | 72 <html> |
| 69 <head> | 73 <head> |
| 70 <script type='application/dart'>$content</script> | 74 <script type='application/dart'>$content</script> |
| 71 </head> | 75 </head> |
| 72 <body> | 76 <body> |
| 73 </body> | 77 </body> |
| 74 </html>'''); | 78 </html>'''); |
| 75 computeResult(target, REFERENCED_LIBRARIES); | 79 computeResult(target, REFERENCED_LIBRARIES, matcher: isDartScriptsTask); |
| 76 expect(task, new isInstanceOf<DartScriptsTask>()); | |
| 77 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); | 80 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); |
| 78 expect(outputs[DART_SCRIPTS], hasLength(1)); | 81 expect(outputs[DART_SCRIPTS], hasLength(1)); |
| 79 DartScript script = outputs[DART_SCRIPTS][0]; | 82 DartScript script = outputs[DART_SCRIPTS][0]; |
| 80 expect(script.fragments, hasLength(1)); | 83 expect(script.fragments, hasLength(1)); |
| 81 ScriptFragment fragment = script.fragments[0]; | 84 ScriptFragment fragment = script.fragments[0]; |
| 82 expect(fragment.content, content); | 85 expect(fragment.content, content); |
| 83 } | 86 } |
| 84 | 87 |
| 85 void test_perform_empty_source_reference() { | 88 void test_perform_empty_source_reference() { |
| 86 AnalysisTarget target = newSource( | 89 AnalysisTarget target = newSource( |
| 87 '/test.html', | 90 '/test.html', |
| 88 r''' | 91 r''' |
| 89 <!DOCTYPE html> | 92 <!DOCTYPE html> |
| 90 <html> | 93 <html> |
| 91 <head> | 94 <head> |
| 92 <script type='application/dart' src=''/> | 95 <script type='application/dart' src=''/> |
| 93 </head> | 96 </head> |
| 94 <body> | 97 <body> |
| 95 </body> | 98 </body> |
| 96 </html>'''); | 99 </html>'''); |
| 97 computeResult(target, REFERENCED_LIBRARIES); | 100 computeResult(target, REFERENCED_LIBRARIES, matcher: isDartScriptsTask); |
| 98 expect(task, new isInstanceOf<DartScriptsTask>()); | |
| 99 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); | 101 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); |
| 100 expect(outputs[DART_SCRIPTS], hasLength(0)); | 102 expect(outputs[DART_SCRIPTS], hasLength(0)); |
| 101 } | 103 } |
| 102 | 104 |
| 103 void test_perform_invalid_source_reference() { | 105 void test_perform_invalid_source_reference() { |
| 104 AnalysisTarget target = newSource( | 106 AnalysisTarget target = newSource( |
| 105 '/test.html', | 107 '/test.html', |
| 106 r''' | 108 r''' |
| 107 <!DOCTYPE html> | 109 <!DOCTYPE html> |
| 108 <html> | 110 <html> |
| 109 <head> | 111 <head> |
| 110 <script type='application/dart' src='an;invalid:[]uri'/> | 112 <script type='application/dart' src='an;invalid:[]uri'/> |
| 111 </head> | 113 </head> |
| 112 <body> | 114 <body> |
| 113 </body> | 115 </body> |
| 114 </html>'''); | 116 </html>'''); |
| 115 computeResult(target, REFERENCED_LIBRARIES); | 117 computeResult(target, REFERENCED_LIBRARIES, matcher: isDartScriptsTask); |
| 116 expect(task, new isInstanceOf<DartScriptsTask>()); | |
| 117 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); | 118 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); |
| 118 expect(outputs[DART_SCRIPTS], hasLength(0)); | 119 expect(outputs[DART_SCRIPTS], hasLength(0)); |
| 119 } | 120 } |
| 120 | 121 |
| 121 void test_perform_non_existing_source_reference() { | 122 void test_perform_non_existing_source_reference() { |
| 122 AnalysisTarget target = newSource( | 123 AnalysisTarget target = newSource( |
| 123 '/test.html', | 124 '/test.html', |
| 124 r''' | 125 r''' |
| 125 <!DOCTYPE html> | 126 <!DOCTYPE html> |
| 126 <html> | 127 <html> |
| 127 <head> | 128 <head> |
| 128 <script type='application/dart' src='does/not/exist.dart'/> | 129 <script type='application/dart' src='does/not/exist.dart'/> |
| 129 </head> | 130 </head> |
| 130 <body> | 131 <body> |
| 131 </body> | 132 </body> |
| 132 </html>'''); | 133 </html>'''); |
| 133 computeResult(target, REFERENCED_LIBRARIES); | 134 computeResult(target, REFERENCED_LIBRARIES, matcher: isDartScriptsTask); |
| 134 expect(task, new isInstanceOf<DartScriptsTask>()); | |
| 135 expect(outputs[REFERENCED_LIBRARIES], hasLength(1)); | 135 expect(outputs[REFERENCED_LIBRARIES], hasLength(1)); |
| 136 expect(outputs[DART_SCRIPTS], hasLength(0)); | 136 expect(outputs[DART_SCRIPTS], hasLength(0)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 test_perform_none() { | 139 test_perform_none() { |
| 140 AnalysisTarget target = newSource( | 140 AnalysisTarget target = newSource( |
| 141 '/test.html', | 141 '/test.html', |
| 142 r''' | 142 r''' |
| 143 <!DOCTYPE html> | 143 <!DOCTYPE html> |
| 144 <html> | 144 <html> |
| 145 <head> | 145 <head> |
| 146 <title>test page</title> | 146 <title>test page</title> |
| 147 </head> | 147 </head> |
| 148 <body> | 148 <body> |
| 149 Test | 149 Test |
| 150 </body> | 150 </body> |
| 151 </html> | 151 </html> |
| 152 '''); | 152 '''); |
| 153 computeResult(target, REFERENCED_LIBRARIES); | 153 computeResult(target, REFERENCED_LIBRARIES, matcher: isDartScriptsTask); |
| 154 expect(task, new isInstanceOf<DartScriptsTask>()); | |
| 155 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); | 154 expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); |
| 156 expect(outputs[DART_SCRIPTS], hasLength(0)); | 155 expect(outputs[DART_SCRIPTS], hasLength(0)); |
| 157 } | 156 } |
| 158 | 157 |
| 159 void test_perform_referenced_source() { | 158 void test_perform_referenced_source() { |
| 160 AnalysisTarget target = newSource( | 159 AnalysisTarget target = newSource( |
| 161 '/test.html', | 160 '/test.html', |
| 162 r''' | 161 r''' |
| 163 <!DOCTYPE html> | 162 <!DOCTYPE html> |
| 164 <html> | 163 <html> |
| 165 <head> | 164 <head> |
| 166 <script type='application/dart' src='test.dart'/> | 165 <script type='application/dart' src='test.dart'/> |
| 167 </head> | 166 </head> |
| 168 <body> | 167 <body> |
| 169 </body> | 168 </body> |
| 170 </html>'''); | 169 </html>'''); |
| 171 computeResult(target, REFERENCED_LIBRARIES); | 170 computeResult(target, REFERENCED_LIBRARIES, matcher: isDartScriptsTask); |
| 172 expect(task, new isInstanceOf<DartScriptsTask>()); | |
| 173 expect(outputs[REFERENCED_LIBRARIES], hasLength(1)); | 171 expect(outputs[REFERENCED_LIBRARIES], hasLength(1)); |
| 174 expect(outputs[DART_SCRIPTS], hasLength(0)); | 172 expect(outputs[DART_SCRIPTS], hasLength(0)); |
| 175 } | 173 } |
| 176 } | 174 } |
| 177 | 175 |
| 178 @reflectiveTest | 176 @reflectiveTest |
| 179 class HtmlErrorsTaskTest extends AbstractContextTest { | 177 class HtmlErrorsTaskTest extends AbstractContextTest { |
| 180 test_buildInputs() { | 178 test_buildInputs() { |
| 181 Source source = newSource('/test.html'); | 179 Source source = newSource('/test.html'); |
| 182 Map<String, TaskInput> inputs = HtmlErrorsTask.buildInputs(source); | 180 Map<String, TaskInput> inputs = HtmlErrorsTask.buildInputs(source); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 <html> | 222 <html> |
| 225 <head> | 223 <head> |
| 226 <title>test page</title> | 224 <title>test page</title> |
| 227 <script type='application/dart'> | 225 <script type='application/dart'> |
| 228 void buttonPressed() { | 226 void buttonPressed() { |
| 229 </script> | 227 </script> |
| 230 </head> | 228 </head> |
| 231 <body>Test</body> | 229 <body>Test</body> |
| 232 </html> | 230 </html> |
| 233 '''); | 231 '''); |
| 234 computeResult(target, HTML_ERRORS); | 232 computeResult(target, HTML_ERRORS, matcher: isHtmlErrorsTask); |
| 235 expect(task, new isInstanceOf<HtmlErrorsTask>()); | |
| 236 expect(outputs[HTML_ERRORS], hasLength(1)); | 233 expect(outputs[HTML_ERRORS], hasLength(1)); |
| 237 } | 234 } |
| 238 | 235 |
| 239 test_perform_htmlErrors() { | 236 test_perform_htmlErrors() { |
| 240 AnalysisTarget target = newSource( | 237 AnalysisTarget target = newSource( |
| 241 '/test.html', | 238 '/test.html', |
| 242 r''' | 239 r''' |
| 243 <html> | 240 <html> |
| 244 <head> | 241 <head> |
| 245 <title>test page</title> | 242 <title>test page</title> |
| 246 </head> | 243 </head> |
| 247 <body> | 244 <body> |
| 248 Test | 245 Test |
| 249 </body> | 246 </body> |
| 250 </html> | 247 </html> |
| 251 '''); | 248 '''); |
| 252 computeResult(target, HTML_ERRORS); | 249 computeResult(target, HTML_ERRORS, matcher: isHtmlErrorsTask); |
| 253 expect(task, new isInstanceOf<HtmlErrorsTask>()); | |
| 254 expect(outputs[HTML_ERRORS], hasLength(1)); | 250 expect(outputs[HTML_ERRORS], hasLength(1)); |
| 255 } | 251 } |
| 256 | 252 |
| 257 test_perform_noErrors() { | 253 test_perform_noErrors() { |
| 258 AnalysisTarget target = newSource( | 254 AnalysisTarget target = newSource( |
| 259 '/test.html', | 255 '/test.html', |
| 260 r''' | 256 r''' |
| 261 <!DOCTYPE html> | 257 <!DOCTYPE html> |
| 262 <html> | 258 <html> |
| 263 <head> | 259 <head> |
| 264 <title>test page</title> | 260 <title>test page</title> |
| 265 </head> | 261 </head> |
| 266 <body> | 262 <body> |
| 267 Test | 263 Test |
| 268 </body> | 264 </body> |
| 269 </html> | 265 </html> |
| 270 '''); | 266 '''); |
| 271 computeResult(target, HTML_ERRORS); | 267 computeResult(target, HTML_ERRORS, matcher: isHtmlErrorsTask); |
| 272 expect(task, new isInstanceOf<HtmlErrorsTask>()); | |
| 273 expect(outputs[HTML_ERRORS], isEmpty); | 268 expect(outputs[HTML_ERRORS], isEmpty); |
| 274 } | 269 } |
| 275 } | 270 } |
| 276 | 271 |
| 277 @reflectiveTest | 272 @reflectiveTest |
| 278 class ParseHtmlTaskTest extends AbstractContextTest { | 273 class ParseHtmlTaskTest extends AbstractContextTest { |
| 279 test_buildInputs() { | 274 test_buildInputs() { |
| 280 Source source = newSource('/test.html'); | 275 Source source = newSource('/test.html'); |
| 281 Map<String, TaskInput> inputs = ParseHtmlTask.buildInputs(source); | 276 Map<String, TaskInput> inputs = ParseHtmlTask.buildInputs(source); |
| 282 expect(inputs, isNotNull); | 277 expect(inputs, isNotNull); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 <html> | 313 <html> |
| 319 <head> | 314 <head> |
| 320 <title>test page</title> | 315 <title>test page</title> |
| 321 </head> | 316 </head> |
| 322 <body> | 317 <body> |
| 323 <h1 Test> | 318 <h1 Test> |
| 324 </body> | 319 </body> |
| 325 </html> | 320 </html> |
| 326 '''); | 321 '''); |
| 327 computeResult(target, HTML_DOCUMENT); | 322 computeResult(target, HTML_DOCUMENT); |
| 328 expect(task, new isInstanceOf<ParseHtmlTask>()); | 323 expect(task, isParseHtmlTask); |
| 329 expect(outputs[HTML_DOCUMENT], isNotNull); | 324 expect(outputs[HTML_DOCUMENT], isNotNull); |
| 330 expect(outputs[HTML_DOCUMENT_ERRORS], isNotEmpty); | 325 expect(outputs[HTML_DOCUMENT_ERRORS], isNotEmpty); |
| 331 } | 326 } |
| 332 } | 327 } |
| OLD | NEW |