| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 polymer.test.linter_test; | 5 library polymer.test.linter_test; |
| 6 | 6 |
| 7 import 'package:polymer/src/build/common.dart'; | 7 import 'package:polymer/src/build/common.dart'; |
| 8 import 'package:polymer/src/build/linter.dart'; | 8 import 'package:polymer/src/build/linter.dart'; |
| 9 import 'package:source_maps/span.dart'; | 9 import 'package:source_maps/span.dart'; |
| 10 import 'package:unittest/compact_vm_config.dart'; | 10 import 'package:unittest/compact_vm_config.dart'; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 '<script src="packages/polymer/boot.js"></script>' | 43 '<script src="packages/polymer/boot.js"></script>' |
| 44 '<script type="application/dart" src="packages/polymer/init.dart">' | 44 '<script type="application/dart" src="packages/polymer/init.dart">' |
| 45 '</script>' | 45 '</script>' |
| 46 '<script src="packages/browser/dart.js"></script>' | 46 '<script src="packages/browser/dart.js"></script>' |
| 47 '</html>', | 47 '</html>', |
| 48 }, { | 48 }, { |
| 49 'a|web/test.html.messages': 'warning: $BOOT_JS_DEPRECATED ' | 49 'a|web/test.html.messages': 'warning: $BOOT_JS_DEPRECATED ' |
| 50 '(web/test.html 1 0)', | 50 '(web/test.html 1 0)', |
| 51 }); | 51 }); |
| 52 }); | 52 }); |
| 53 group('single script tag per document', () { |
| 54 _testLinter('two top-level tags', { |
| 55 'a|web/test.html': '<!DOCTYPE html><html>' |
| 56 '<script type="application/dart" src="a.dart">' |
| 57 '</script>\n' |
| 58 '<script type="application/dart" src="b.dart">' |
| 59 '</script>' |
| 60 '<script src="packages/browser/dart.js"></script>' |
| 61 }, { |
| 62 'a|web/test.html.messages': |
| 63 'warning: Only one "application/dart" script tag per document is' |
| 64 ' allowed. (web/test.html 1 0)', |
| 65 }); |
| 66 |
| 67 _testLinter('two top-level tags, non entrypoint', { |
| 68 'a|lib/test.html': '<!DOCTYPE html><html>' |
| 69 '<script type="application/dart" src="a.dart">' |
| 70 '</script>\n' |
| 71 '<script type="application/dart" src="b.dart">' |
| 72 '</script>' |
| 73 '<script src="packages/browser/dart.js"></script>' |
| 74 }, { |
| 75 'a|lib/test.html.messages': |
| 76 'warning: Only one "application/dart" script tag per document is' |
| 77 ' allowed. (lib/test.html 1 0)', |
| 78 }); |
| 79 |
| 80 _testLinter('tags inside elements', { |
| 81 'a|web/test.html': '<!DOCTYPE html><html>' |
| 82 '<polymer-element name="x-a">' |
| 83 '<script type="application/dart" src="a.dart">' |
| 84 '</script>' |
| 85 '</polymer-element>\n' |
| 86 '<script type="application/dart" src="b.dart">' |
| 87 '</script>' |
| 88 '<script src="packages/browser/dart.js"></script>' |
| 89 }, { |
| 90 'a|web/test.html.messages': |
| 91 'warning: Only one "application/dart" script tag per document is' |
| 92 ' allowed. (web/test.html 1 0)', |
| 93 }); |
| 94 }); |
| 53 | 95 |
| 54 group('doctype warning', () { | 96 group('doctype warning', () { |
| 55 _testLinter('in web', { | 97 _testLinter('in web', { |
| 56 'a|web/test.html': '<html></html>', | 98 'a|web/test.html': '<html></html>', |
| 57 }, { | 99 }, { |
| 58 'a|web/test.html.messages': | 100 'a|web/test.html.messages': |
| 59 'warning: Unexpected start tag (html). Expected DOCTYPE. ' | 101 'warning: Unexpected start tag (html). Expected DOCTYPE. ' |
| 60 '(web/test.html 0 0)\n' | 102 '(web/test.html 0 0)\n' |
| 61 'error: $USE_INIT_DART\n' | 103 'error: $USE_INIT_DART\n' |
| 62 'error: $USE_DART_JS', | 104 'error: $USE_DART_JS', |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 }); | 248 }); |
| 207 | 249 |
| 208 | 250 |
| 209 group('script type matches code', () { | 251 group('script type matches code', () { |
| 210 _testLinter('top-level, .dart url', { | 252 _testLinter('top-level, .dart url', { |
| 211 'a|lib/test.html': '''<html> | 253 'a|lib/test.html': '''<html> |
| 212 <script src="foo.dart"></script> | 254 <script src="foo.dart"></script> |
| 213 </html>'''.replaceAll(' ', ''), | 255 </html>'''.replaceAll(' ', ''), |
| 214 }, { | 256 }, { |
| 215 'a|lib/test.html.messages': | 257 'a|lib/test.html.messages': |
| 216 'warning: script tag with .dart source file but no type will be ' | 258 'warning: Wrong script type, expected type="application/dart".' |
| 217 'treated as JavaScript. Did you forget type="application/dart"?' | |
| 218 ' (lib/test.html 1 0)' | 259 ' (lib/test.html 1 0)' |
| 219 }); | 260 }); |
| 220 | 261 |
| 221 _testLinter('in polymer-element, .dart url', { | 262 _testLinter('in polymer-element, .dart url', { |
| 222 'a|lib/test.html': '''<html> | 263 'a|lib/test.html': '''<html> |
| 223 <polymer-element name="x-a"> | 264 <polymer-element name="x-a"> |
| 224 <script src="foo.dart"></script> | 265 <script src="foo.dart"></script> |
| 225 </polymer-element> | 266 </polymer-element> |
| 226 </html>'''.replaceAll(' ', ''), | 267 </html>'''.replaceAll(' ', ''), |
| 227 }, { | 268 }, { |
| 228 'a|lib/test.html.messages': | 269 'a|lib/test.html.messages': |
| 229 'warning: script tag with .dart source file but no type will be ' | 270 'warning: Wrong script type, expected type="application/dart".' |
| 230 'treated as JavaScript. Did you forget type="application/dart"?' | |
| 231 ' (lib/test.html 2 0)' | 271 ' (lib/test.html 2 0)' |
| 232 }); | 272 }); |
| 233 | 273 |
| 234 _testLinter('in polymer-element, .js url', { | 274 _testLinter('in polymer-element, .js url', { |
| 235 'a|lib/test.html': '''<html> | 275 'a|lib/test.html': '''<html> |
| 236 <polymer-element name="x-a"> | 276 <polymer-element name="x-a"> |
| 237 <script src="foo.js"></script> | 277 <script src="foo.js"></script> |
| 238 </polymer-element> | 278 </polymer-element> |
| 239 </html>'''.replaceAll(' ', ''), | 279 </html>'''.replaceAll(' ', ''), |
| 240 }, { | 280 }, { |
| 241 'a|lib/test.html.messages': '' | 281 'a|lib/test.html.messages': '' |
| 242 }); | 282 }); |
| 243 | 283 |
| 244 _testLinter('in polymer-element, inlined', { | 284 _testLinter('in polymer-element, inlined', { |
| 245 'a|lib/test.html': '''<html> | 285 'a|lib/test.html': '''<html> |
| 246 <polymer-element name="x-a"> | 286 <polymer-element name="x-a"> |
| 247 <script>foo...</script> | 287 <script>foo...</script> |
| 248 </polymer-element> | 288 </polymer-element> |
| 249 </html>'''.replaceAll(' ', ''), | 289 </html>'''.replaceAll(' ', ''), |
| 250 }, { | 290 }, { |
| 251 'a|lib/test.html.messages': | 291 'a|lib/test.html.messages': |
| 252 'warning: script tag in polymer element with no type will ' | 292 'warning: script tag in polymer element with no type will ' |
| 253 'be treated as JavaScript. Did you forget type="application/dart"?' | 293 'be treated as JavaScript. Did you forget type="application/dart"?' |
| 254 ' (lib/test.html 2 0)' | 294 ' (lib/test.html 2 0)' |
| 255 }); | 295 }); |
| 256 | 296 |
| 257 _testLinter('top-level, dart type & .dart url', { | 297 _testLinter('top-level, dart type & .dart url', { |
| 258 'a|lib/test.html': '''<html> | 298 'a|lib/test.html': '''<html> |
| 259 <script type="applicatino/dart" src="foo.dart"></script> | 299 <script type="application/dart" src="foo.dart"></script> |
| 260 </html>'''.replaceAll(' ', ''), | 300 </html>'''.replaceAll(' ', ''), |
| 261 }, { | 301 }, { |
| 262 'a|lib/test.html.messages': '' | 302 'a|lib/test.html.messages': '' |
| 263 }); | 303 }); |
| 264 | 304 |
| 265 _testLinter('top-level, dart type & .js url', { | 305 _testLinter('top-level, dart type & .js url', { |
| 266 'a|lib/test.html': '''<html> | 306 'a|lib/test.html': '''<html> |
| 267 <script type="application/dart" src="foo.js"></script> | 307 <script type="application/dart" src="foo.js"></script> |
| 268 </html>'''.replaceAll(' ', ''), | 308 </html>'''.replaceAll(' ', ''), |
| 269 }, { | 309 }, { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 | 524 |
| 485 | 525 |
| 486 _testFormatter(String kind, String message, Span span) { | 526 _testFormatter(String kind, String message, Span span) { |
| 487 var formattedMessage = '$kind: $message'; | 527 var formattedMessage = '$kind: $message'; |
| 488 if (span != null) { | 528 if (span != null) { |
| 489 formattedMessage = '$formattedMessage ' | 529 formattedMessage = '$formattedMessage ' |
| 490 '(${span.sourceUrl} ${span.start.line} ${span.start.column})'; | 530 '(${span.sourceUrl} ${span.start.line} ${span.start.column})'; |
| 491 } | 531 } |
| 492 return formattedMessage; | 532 return formattedMessage; |
| 493 } | 533 } |
| OLD | NEW |