| 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:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 | 10 |
| 11 import 'common.dart'; | 11 import 'common.dart'; |
| 12 | 12 |
| 13 void main() { | 13 void main() { |
| 14 _testLinter('nothing to report', { | 14 _testLinter('nothing to report', { |
| 15 'a|lib/test.html': '<!DOCTYPE html><html></html>', | 15 'a|lib/test.html': '<!DOCTYPE html><html></html>', |
| 16 }, []); | 16 }, []); |
| 17 | 17 |
| 18 group('must have import to polymer.html', () { | 18 group('must have proper initialization imports', () { |
| 19 _testLinter('nothing to report', { | 19 _testLinter('nothing to report', { |
| 20 'a|web/test.html': '<!DOCTYPE html><html>' | 20 'a|web/test.html': '<!DOCTYPE html><html>' |
| 21 '<link rel="import" href="packages/polymer/polymer.html">' | 21 '<link rel="import" href="packages/polymer/polymer.html">' |
| 22 '<script type="application/dart" src="foo.dart">' | 22 '<script type="application/dart" src="foo.dart">' |
| 23 '</script>' | 23 '</script>' |
| 24 '<script src="packages/browser/dart.js"></script>' | 24 '<script src="packages/browser/dart.js"></script>' |
| 25 '</html>', | 25 '</html>', |
| 26 }, []); | 26 }, []); |
| 27 | 27 |
| 28 _testLinter('missing everything', { | 28 _testLinter('missing polymer.html', { |
| 29 'a|web/test.html': '<!DOCTYPE html><html></html>', | 29 'a|web/test.html': '<!DOCTYPE html><html>' |
| 30 }, [ | |
| 31 'warning: $USE_POLYMER_HTML', | |
| 32 ]); | |
| 33 | |
| 34 _testLinter('using deprecated boot.js', { | |
| 35 'a|web/test.html': '<!DOCTYPE html><html>\n' | |
| 36 '<script src="packages/polymer/boot.js"></script>' | |
| 37 '<script type="application/dart" src="foo.dart">' | 30 '<script type="application/dart" src="foo.dart">' |
| 38 '</script>' | 31 '</script>' |
| 39 '<script src="packages/browser/dart.js"></script>' | 32 '<script src="packages/browser/dart.js"></script>' |
| 40 '</html>', | 33 '</html>', |
| 41 }, [ | 34 }, [ |
| 42 'warning: $USE_POLYMER_HTML', | 35 'warning: $USE_POLYMER_HTML', |
| 43 ]); | 36 ]); |
| 37 |
| 38 _testLinter('missing Dart code', { |
| 39 'a|web/test.html': '<!DOCTYPE html><html>' |
| 40 '<link rel="import" href="packages/polymer/polymer.html">' |
| 41 '<script src="packages/browser/dart.js"></script>' |
| 42 '</html>', |
| 43 }, [ |
| 44 'warning: $USE_INIT_DART', |
| 45 ]); |
| 46 |
| 47 _testLinter('nothing to report, experimental with no Dart code', { |
| 48 'a|web/test.html': '<!DOCTYPE html><html>' |
| 49 '<link rel="import" ' |
| 50 'href="packages/polymer/polymer_experimental.html">' |
| 51 '<script src="packages/browser/dart.js"></script>' |
| 52 '</html>', |
| 53 }, []); |
| 54 |
| 55 _testLinter('experimental cannot have Dart code in main document', { |
| 56 'a|web/test.html': '<!DOCTYPE html><html>' |
| 57 '<link rel="import" ' |
| 58 'href="packages/polymer/polymer_experimental.html">\n' |
| 59 '<script type="application/dart" src="foo.dart">' |
| 60 '</script>' |
| 61 '<script src="packages/browser/dart.js"></script>' |
| 62 '</html>', |
| 63 }, [ |
| 64 'warning: $NO_DART_SCRIPT_AND_EXPERIMENTAL (web/test.html 1 0)', |
| 65 ]); |
| 66 |
| 67 _testLinter('missing Dart code and polymer.html', { |
| 68 'a|web/test.html': '<!DOCTYPE html><html></html>', |
| 69 }, [ |
| 70 'warning: $USE_POLYMER_HTML', |
| 71 'warning: $USE_INIT_DART', |
| 72 ]); |
| 44 }); | 73 }); |
| 45 group('multiple script tag per document allowed', () { | 74 |
| 75 group('single script tag per document', () { |
| 46 _testLinter('two top-level tags', { | 76 _testLinter('two top-level tags', { |
| 47 'a|web/test.html': '<!DOCTYPE html><html>' | 77 'a|web/test.html': '<!DOCTYPE html><html>' |
| 48 '<link rel="import" href="packages/polymer/polymer.html">' | 78 '<link rel="import" href="packages/polymer/polymer.html">' |
| 49 '<script type="application/dart" src="a.dart">' | 79 '<script type="application/dart" src="a.dart">' |
| 50 '</script>\n' | 80 '</script>\n' |
| 51 '<script type="application/dart" src="b.dart">' | 81 '<script type="application/dart" src="b.dart">' |
| 52 '</script>' | 82 '</script>' |
| 83 '<script src="packages/browser/dart.js"></script>', |
| 84 }, [ |
| 85 'warning: Only one "application/dart" script tag per document is' |
| 86 ' allowed. (web/test.html 1 0)', |
| 87 ]); |
| 88 |
| 89 _testLinter('two top-level tags, non entrypoint', { |
| 90 'a|lib/test.html': '<!DOCTYPE html><html>' |
| 91 '<script type="application/dart" src="a.dart">' |
| 92 '</script>\n' |
| 93 '<script type="application/dart" src="b.dart">' |
| 94 '</script>' |
| 53 '<script src="packages/browser/dart.js"></script>' | 95 '<script src="packages/browser/dart.js"></script>' |
| 54 }, []); | 96 }, [ |
| 97 'warning: Only one "application/dart" script tag per document is' |
| 98 ' allowed. (lib/test.html 1 0)', |
| 99 ]); |
| 55 | 100 |
| 56 _testLinter('tags inside elements', { | 101 _testLinter('tags inside elements', { |
| 57 'a|web/test.html': '<!DOCTYPE html><html>' | 102 'a|web/test.html': '<!DOCTYPE html><html>' |
| 58 '<link rel="import" href="packages/polymer/polymer.html">' | 103 '<link rel="import" href="packages/polymer/polymer.html">' |
| 59 '<polymer-element name="x-a">' | 104 '<polymer-element name="x-a">' |
| 60 '<script type="application/dart" src="a.dart">' | 105 '<script type="application/dart" src="a.dart">' |
| 61 '</script>' | 106 '</script>' |
| 62 '</polymer-element>\n' | 107 '</polymer-element>\n' |
| 63 '<script type="application/dart" src="b.dart">' | 108 '<script type="application/dart" src="b.dart">' |
| 64 '</script>' | 109 '</script>' |
| 65 '<script src="packages/browser/dart.js"></script>' | 110 '<script src="packages/browser/dart.js"></script>', |
| 66 }, []); | 111 }, [ |
| 112 'warning: Only one "application/dart" script tag per document is' |
| 113 ' allowed. (web/test.html 1 0)', |
| 114 ]); |
| 67 }); | 115 }); |
| 68 | 116 |
| 69 group('doctype warning', () { | 117 group('doctype warning', () { |
| 70 _testLinter('in web', { | 118 _testLinter('in web', { |
| 71 'a|web/test.html': '<html></html>', | 119 'a|web/test.html': '<html></html>', |
| 72 }, [ | 120 }, [ |
| 73 'warning: Unexpected start tag (html). Expected DOCTYPE. ' | 121 'warning: Unexpected start tag (html). Expected DOCTYPE. ' |
| 74 '(web/test.html 0 0)', | 122 '(web/test.html 0 0)', |
| 75 'warning: $USE_POLYMER_HTML', | 123 'warning: $USE_POLYMER_HTML', |
| 124 'warning: $USE_INIT_DART', |
| 76 ]); | 125 ]); |
| 77 | 126 |
| 78 _testLinter('in lib', { | 127 _testLinter('in lib', { |
| 79 'a|lib/test.html': '<html></html>', | 128 'a|lib/test.html': '<html></html>', |
| 80 }, []); | 129 }, []); |
| 81 }); | 130 }); |
| 82 | 131 |
| 83 group('duplicate polymer-elements,', () { | 132 group('duplicate polymer-elements,', () { |
| 84 _testLinter('same file', { | 133 _testLinter('same file', { |
| 85 'a|lib/test.html': '''<html> | 134 'a|lib/test.html': '''<html> |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 'warning: custom element with name "x-b" not found. (lib/test.html 1 0)' | 252 'warning: custom element with name "x-b" not found. (lib/test.html 1 0)' |
| 204 ]); | 253 ]); |
| 205 | 254 |
| 206 | 255 |
| 207 group('script type matches code', () { | 256 group('script type matches code', () { |
| 208 _testLinter('top-level, .dart url', { | 257 _testLinter('top-level, .dart url', { |
| 209 'a|lib/test.html': '''<html> | 258 'a|lib/test.html': '''<html> |
| 210 <script src="foo.dart"></script> | 259 <script src="foo.dart"></script> |
| 211 </html>'''.replaceAll(' ', ''), | 260 </html>'''.replaceAll(' ', ''), |
| 212 }, [ | 261 }, [ |
| 213 'warning: Wrong script type, expected type="application/dart" or' | 262 'warning: Wrong script type, expected type="application/dart".' |
| 214 ' type="application/dart;component=1". (lib/test.html 1 0)' | 263 ' (lib/test.html 1 0)' |
| 215 ]); | 264 ]); |
| 216 | 265 |
| 217 _testLinter('in polymer-element, .dart url', { | 266 _testLinter('in polymer-element, .dart url', { |
| 218 'a|lib/test.html': '''<html> | 267 'a|lib/test.html': '''<html> |
| 219 <polymer-element name="x-a"> | 268 <polymer-element name="x-a"> |
| 220 <script src="foo.dart"></script> | 269 <script src="foo.dart"></script> |
| 221 </polymer-element> | 270 </polymer-element> |
| 222 </html>'''.replaceAll(' ', ''), | 271 </html>'''.replaceAll(' ', ''), |
| 223 }, [ | 272 }, [ |
| 224 'warning: Wrong script type, expected type="application/dart" or' | 273 'warning: Wrong script type, expected type="application/dart".' |
| 225 ' type="application/dart;component=1". (lib/test.html 2 0)' | 274 ' (lib/test.html 2 0)' |
| 226 ]); | 275 ]); |
| 227 | 276 |
| 228 _testLinter('in polymer-element, .js url', { | 277 _testLinter('in polymer-element, .js url', { |
| 229 'a|lib/test.html': '''<html> | 278 'a|lib/test.html': '''<html> |
| 230 <polymer-element name="x-a"> | 279 <polymer-element name="x-a"> |
| 231 <script src="foo.js"></script> | 280 <script src="foo.js"></script> |
| 232 </polymer-element> | 281 </polymer-element> |
| 233 </html>'''.replaceAll(' ', ''), | 282 </html>'''.replaceAll(' ', ''), |
| 234 }, []); | 283 }, []); |
| 235 | 284 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 491 |
| 443 _testLinter(String name, Map inputFiles, List outputMessages, | 492 _testLinter(String name, Map inputFiles, List outputMessages, |
| 444 [bool solo = false]) { | 493 [bool solo = false]) { |
| 445 var linter = new Linter(new TransformOptions()); | 494 var linter = new Linter(new TransformOptions()); |
| 446 var outputFiles = {}; | 495 var outputFiles = {}; |
| 447 if (outputMessages.every((m) => m.startsWith('warning:'))) { | 496 if (outputMessages.every((m) => m.startsWith('warning:'))) { |
| 448 inputFiles.forEach((k, v) => outputFiles[k] = v); | 497 inputFiles.forEach((k, v) => outputFiles[k] = v); |
| 449 } | 498 } |
| 450 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo); | 499 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo); |
| 451 } | 500 } |
| OLD | NEW |