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 proper initialization imports', () { | 18 group('must have proper initialization imports', () { |
19 _testLinter('nothing to report', { | 19 _testLinter('nothing to report (no polymer use)', { |
| 20 'a|web/test.html': '<!DOCTYPE html><html>' |
| 21 '<script type="application/dart" src="foo.dart">' |
| 22 '</script>' |
| 23 '<script src="packages/browser/dart.js"></script>' |
| 24 '</html>', |
| 25 }, []); |
| 26 |
| 27 _testLinter('nothing to report (no polymer use with import)', { |
20 'a|web/test.html': '<!DOCTYPE html><html>' | 28 'a|web/test.html': '<!DOCTYPE html><html>' |
21 '<link rel="import" href="packages/polymer/polymer.html">' | 29 '<link rel="import" href="packages/polymer/polymer.html">' |
22 '<script type="application/dart" src="foo.dart">' | 30 '<script type="application/dart" src="foo.dart">' |
23 '</script>' | 31 '</script>' |
24 '<script src="packages/browser/dart.js"></script>' | 32 '<script src="packages/browser/dart.js"></script>' |
25 '</html>', | 33 '</html>', |
26 }, []); | 34 }, []); |
27 | 35 |
28 _testLinter('missing polymer.html', { | 36 _testLinter('nothing to report (polymer used)', { |
29 'a|web/test.html': '<!DOCTYPE html><html>' | 37 'a|web/test.html': '<!DOCTYPE html><html>' |
| 38 '<link rel="import" href="packages/polymer/polymer.html">' |
| 39 '<polymer-element name="x-a"></polymer-element>' |
| 40 '<script type="application/dart" src="foo.dart">' |
| 41 '</script>' |
| 42 '<script src="packages/browser/dart.js"></script>' |
| 43 '</html>', |
| 44 }, []); |
| 45 |
| 46 _testLinter('nothing to report (polymer imported transitively)', { |
| 47 'a|lib/lib.html': '<!DOCTYPE html><html>' |
| 48 '<link rel="import" href="../../packages/polymer/polymer.html">', |
| 49 'a|web/test.html': '<!DOCTYPE html><html>' |
| 50 '<link rel="import" href="packages/a/lib.html">' |
| 51 '<polymer-element name="x-a"></polymer-element>' |
| 52 '<script type="application/dart" src="foo.dart">' |
| 53 '</script>' |
| 54 '<script src="packages/browser/dart.js"></script>' |
| 55 '</html>', |
| 56 }, []); |
| 57 |
| 58 test('usePolymerHtmlMessage looks right', () { |
| 59 _check(int i, String url) { |
| 60 expect(usePolymerHtmlMessage(i), |
| 61 contains('<link rel="import" href="$url">')); |
| 62 } |
| 63 _check(0, 'packages/polymer/polymer.html'); |
| 64 _check(1, '../packages/polymer/polymer.html'); |
| 65 _check(2, '../../packages/polymer/polymer.html'); |
| 66 _check(3, '../../../packages/polymer/polymer.html'); |
| 67 }); |
| 68 |
| 69 _testLinter('missing polymer.html in web', { |
| 70 'a|web/test.html': '<!DOCTYPE html><html>\n' |
| 71 '<polymer-element name="x-a"></polymer-element>' |
30 '<script type="application/dart" src="foo.dart">' | 72 '<script type="application/dart" src="foo.dart">' |
31 '</script>' | 73 '</script>' |
32 '<script src="packages/browser/dart.js"></script>' | 74 '<script src="packages/browser/dart.js"></script>' |
33 '</html>', | 75 '</html>', |
34 }, [ | 76 }, [ |
35 'warning: $USE_POLYMER_HTML', | 77 'warning: ${usePolymerHtmlMessage(0)} (web/test.html 1 0)', |
| 78 ]); |
| 79 |
| 80 _testLinter('missing polymer.html in web/foo', { |
| 81 'a|web/foo/test.html': '<!DOCTYPE html><html>\n' |
| 82 '<polymer-element name="x-a"></polymer-element>' |
| 83 '<script type="application/dart" src="foo.dart">' |
| 84 '</script>' |
| 85 '<script src="packages/browser/dart.js"></script>' |
| 86 '</html>', |
| 87 }, [ |
| 88 'warning: ${usePolymerHtmlMessage(1)} (web/foo/test.html 1 0)', |
| 89 ]); |
| 90 |
| 91 _testLinter('missing polymer.html in lib', { |
| 92 'a|lib/test.html': '<!DOCTYPE html><html>\n' |
| 93 '<polymer-element name="x-a"></polymer-element>' |
| 94 '<script type="application/dart" src="foo.dart">' |
| 95 '</script>' |
| 96 '<script src="packages/browser/dart.js"></script>' |
| 97 '</html>', |
| 98 }, [ |
| 99 'warning: ${usePolymerHtmlMessage(2)} (lib/test.html 1 0)', |
| 100 ]); |
| 101 |
| 102 _testLinter('missing polymer.html in lib/foo/bar', { |
| 103 'a|lib/foo/bar/test.html': '<!DOCTYPE html><html>\n' |
| 104 '<polymer-element name="x-a"></polymer-element>' |
| 105 '<script type="application/dart" src="foo.dart">' |
| 106 '</script>' |
| 107 '<script src="packages/browser/dart.js"></script>' |
| 108 '</html>', |
| 109 }, [ |
| 110 'warning: ${usePolymerHtmlMessage(4)} (lib/foo/bar/test.html 1 0)', |
36 ]); | 111 ]); |
37 | 112 |
38 _testLinter('missing Dart code', { | 113 _testLinter('missing Dart code', { |
39 'a|web/test.html': '<!DOCTYPE html><html>' | 114 'a|web/test.html': '<!DOCTYPE html><html>' |
40 '<link rel="import" href="packages/polymer/polymer.html">' | 115 '<link rel="import" href="packages/polymer/polymer.html">' |
41 '<script src="packages/browser/dart.js"></script>' | 116 '<script src="packages/browser/dart.js"></script>' |
42 '</html>', | 117 '</html>', |
43 }, [ | 118 }, [ |
44 'warning: $USE_INIT_DART', | 119 'warning: $USE_INIT_DART', |
45 ]); | 120 ]); |
(...skipping 14 matching lines...) Expand all Loading... |
60 '</script>' | 135 '</script>' |
61 '<script src="packages/browser/dart.js"></script>' | 136 '<script src="packages/browser/dart.js"></script>' |
62 '</html>', | 137 '</html>', |
63 }, [ | 138 }, [ |
64 'warning: $NO_DART_SCRIPT_AND_EXPERIMENTAL (web/test.html 1 0)', | 139 'warning: $NO_DART_SCRIPT_AND_EXPERIMENTAL (web/test.html 1 0)', |
65 ]); | 140 ]); |
66 | 141 |
67 _testLinter('missing Dart code and polymer.html', { | 142 _testLinter('missing Dart code and polymer.html', { |
68 'a|web/test.html': '<!DOCTYPE html><html></html>', | 143 'a|web/test.html': '<!DOCTYPE html><html></html>', |
69 }, [ | 144 }, [ |
70 'warning: $USE_POLYMER_HTML', | |
71 'warning: $USE_INIT_DART', | 145 'warning: $USE_INIT_DART', |
72 ]); | 146 ]); |
73 }); | 147 }); |
74 | 148 |
75 group('single script tag per document', () { | 149 group('single script tag per document', () { |
76 _testLinter('two top-level tags', { | 150 _testLinter('two top-level tags', { |
77 'a|web/test.html': '<!DOCTYPE html><html>' | 151 'a|web/test.html': '<!DOCTYPE html><html>' |
78 '<link rel="import" href="packages/polymer/polymer.html">' | 152 '<link rel="import" href="packages/polymer/polymer.html">' |
79 '<script type="application/dart" src="a.dart">' | 153 '<script type="application/dart" src="a.dart">' |
80 '</script>\n' | 154 '</script>\n' |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 ' allowed. (web/test.html 1 0)', | 187 ' allowed. (web/test.html 1 0)', |
114 ]); | 188 ]); |
115 }); | 189 }); |
116 | 190 |
117 group('doctype warning', () { | 191 group('doctype warning', () { |
118 _testLinter('in web', { | 192 _testLinter('in web', { |
119 'a|web/test.html': '<html></html>', | 193 'a|web/test.html': '<html></html>', |
120 }, [ | 194 }, [ |
121 'warning: Unexpected start tag (html). Expected DOCTYPE. ' | 195 'warning: Unexpected start tag (html). Expected DOCTYPE. ' |
122 '(web/test.html 0 0)', | 196 '(web/test.html 0 0)', |
123 'warning: $USE_POLYMER_HTML', | |
124 'warning: $USE_INIT_DART', | 197 'warning: $USE_INIT_DART', |
125 ]); | 198 ]); |
126 | 199 |
127 _testLinter('in lib', { | 200 _testLinter('in lib', { |
128 'a|lib/test.html': '<html></html>', | 201 'a|lib/test.html': '<html></html>', |
129 }, []); | 202 }, []); |
130 }); | 203 }); |
131 | 204 |
132 group('duplicate polymer-elements,', () { | 205 group('duplicate polymer-elements,', () { |
133 _testLinter('same file', { | 206 _testLinter('same file', { |
134 'a|lib/test.html': '''<html> | 207 'a|lib/test.html': '''<html> |
| 208 <link rel="import" href="../../packages/polymer/polymer.html"> |
135 <polymer-element name="x-a"></polymer-element> | 209 <polymer-element name="x-a"></polymer-element> |
136 <polymer-element name="x-a"></polymer-element> | 210 <polymer-element name="x-a"></polymer-element> |
137 </html>'''.replaceAll(' ', ''), | 211 </html>'''.replaceAll(' ', ''), |
138 }, [ | 212 }, [ |
139 'warning: duplicate definition for custom tag "x-a". ' | 213 'warning: duplicate definition for custom tag "x-a". ' |
140 '(lib/test.html 1 0)', | 214 '(lib/test.html 2 0)', |
141 'warning: duplicate definition for custom tag "x-a" ' | 215 'warning: duplicate definition for custom tag "x-a" ' |
142 '(second definition). (lib/test.html 2 0)' | 216 '(second definition). (lib/test.html 3 0)' |
143 ]); | 217 ]); |
144 | 218 |
145 _testLinter('other file', { | 219 _testLinter('other file', { |
146 'a|lib/b.html': '''<html> | 220 'a|lib/b.html': '''<html> |
| 221 <link rel="import" href="../../packages/polymer/polymer.html"> |
147 <polymer-element name="x-a"></polymer-element> | 222 <polymer-element name="x-a"></polymer-element> |
148 </html>'''.replaceAll(' ', ''), | 223 </html>'''.replaceAll(' ', ''), |
149 'a|lib/test.html': '''<html> | 224 'a|lib/test.html': '''<html> |
150 <link rel="import" href="b.html"> | 225 <link rel="import" href="b.html"> |
151 <polymer-element name="x-a"></polymer-element> | 226 <polymer-element name="x-a"></polymer-element> |
152 </html>'''.replaceAll(' ', ''), | 227 </html>'''.replaceAll(' ', ''), |
153 }, [ | 228 }, [ |
154 'warning: duplicate definition for custom tag "x-a". ' | 229 'warning: duplicate definition for custom tag "x-a". ' |
155 '(lib/b.html 1 0)', | 230 '(lib/b.html 2 0)', |
156 'warning: duplicate definition for custom tag "x-a" ' | 231 'warning: duplicate definition for custom tag "x-a" ' |
157 '(second definition). (lib/test.html 2 0)' | 232 '(second definition). (lib/test.html 2 0)' |
158 ]); | 233 ]); |
159 | 234 |
160 _testLinter('non existing file', { | 235 _testLinter('non existing file', { |
161 'a|lib/test.html': '''<html> | 236 'a|lib/test.html': '''<html> |
| 237 <link rel="import" href="../../packages/polymer/polymer.html"> |
162 <link rel="import" href="b.html"> | 238 <link rel="import" href="b.html"> |
163 <polymer-element name="x-a"></polymer-element> | 239 <polymer-element name="x-a"></polymer-element> |
164 </html>'''.replaceAll(' ', ''), | 240 </html>'''.replaceAll(' ', ''), |
165 }, [ | 241 }, [ |
166 'error: couldn\'t find imported asset "lib/b.html" in package ' | 242 'warning: couldn\'t find imported asset "lib/b.html" in package ' |
167 '"a". (lib/test.html 1 0)' | 243 '"a". (lib/test.html 2 0)' |
168 ]); | 244 ]); |
169 | 245 |
170 _testLinter('other package', { | 246 _testLinter('other package', { |
171 'b|lib/b.html': '''<html> | 247 'b|lib/b.html': '''<html> |
| 248 <link rel="import" href="../../packages/polymer/polymer.html"> |
172 <polymer-element name="x-a"></polymer-element> | 249 <polymer-element name="x-a"></polymer-element> |
173 </html>'''.replaceAll(' ', ''), | 250 </html>'''.replaceAll(' ', ''), |
174 'a|lib/test.html': '''<html> | 251 'a|lib/test.html': '''<html> |
175 <link rel="import" href="../../packages/b/b.html"> | 252 <link rel="import" href="../../packages/b/b.html"> |
176 <polymer-element name="x-a"></polymer-element> | 253 <polymer-element name="x-a"></polymer-element> |
177 </html>'''.replaceAll(' ', ''), | 254 </html>'''.replaceAll(' ', ''), |
178 }, [ | 255 }, [ |
179 'warning: duplicate definition for custom tag "x-a". ' | 256 'warning: duplicate definition for custom tag "x-a". ' |
180 '(package:b/b.html 1 0)', | 257 '(package:b/b.html 2 0)', |
181 'warning: duplicate definition for custom tag "x-a" ' | 258 'warning: duplicate definition for custom tag "x-a" ' |
182 '(second definition). (lib/test.html 2 0)' | 259 '(second definition). (lib/test.html 2 0)' |
183 ]); | 260 ]); |
184 }); | 261 }); |
185 | 262 |
186 _testLinter('bad link-rel tag (href missing)', { | 263 _testLinter('bad link-rel tag (href missing)', { |
187 'a|lib/test.html': '''<html> | 264 'a|lib/test.html': '''<html> |
188 <link rel="import"> | 265 <link rel="import"> |
189 <link rel="stylesheet"> | 266 <link rel="stylesheet"> |
190 <link rel="foo"> | 267 <link rel="foo"> |
191 <link rel="import" href=""> | 268 <link rel="import" href=""> |
192 </html>'''.replaceAll(' ', ''), | 269 </html>'''.replaceAll(' ', ''), |
193 }, [ | 270 }, [ |
194 'warning: link rel="import" missing href. (lib/test.html 1 0)', | 271 'warning: link rel="import" missing href. (lib/test.html 1 0)', |
195 'warning: link rel="stylesheet" missing href. (lib/test.html 2 0)', | 272 'warning: link rel="stylesheet" missing href. (lib/test.html 2 0)', |
196 'warning: link rel="import" missing href. (lib/test.html 4 0)' | 273 'warning: link rel="import" missing href. (lib/test.html 4 0)' |
197 ]); | 274 ]); |
198 | 275 |
199 _testLinter('<element> is not supported', { | 276 _testLinter('<element> is not supported', { |
200 'a|lib/test.html': '''<html> | 277 'a|lib/test.html': '''<html> |
201 <element name="x-a"></element> | 278 <element name="x-a"></element> |
202 </html>'''.replaceAll(' ', ''), | 279 </html>'''.replaceAll(' ', ''), |
203 }, [ | 280 }, [ |
204 'warning: <element> elements are not supported, use <polymer-element>' | 281 'warning: <element> elements are not supported, use <polymer-element>' |
205 ' instead (lib/test.html 1 0)' | 282 ' instead (lib/test.html 1 0)' |
206 ]); | 283 ]); |
207 | 284 |
208 _testLinter('do not nest <polymer-element>', { | 285 _testLinter('do not nest <polymer-element>', { |
209 'a|lib/test.html': '''<html> | 286 'a|lib/test.html': '''<html> |
| 287 <link rel="import" href="../../packages/polymer/polymer.html"> |
210 <polymer-element name="x-a"> | 288 <polymer-element name="x-a"> |
211 <template><div> | 289 <template><div> |
212 <polymer-element name="b"></polymer-element> | 290 <polymer-element name="b"></polymer-element> |
213 </div></template> | 291 </div></template> |
214 </polymer-element> | 292 </polymer-element> |
215 </html>'''.replaceAll(' ', ''), | 293 </html>'''.replaceAll(' ', ''), |
216 }, [ | 294 }, [ |
217 'error: Nested polymer element definitions are not allowed.' | 295 'error: Nested polymer element definitions are not allowed.' |
218 ' (lib/test.html 3 4)' | 296 ' (lib/test.html 4 4)' |
| 297 ]); |
| 298 |
| 299 _testLinter('do put import inside <polymer-element>', { |
| 300 'a|lib/b.html': '<html></html>', |
| 301 'a|lib/test.html': '''<html> |
| 302 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 303 <polymer-element name="x-a"> |
| 304 <link rel="import" href="b.html"> |
| 305 <template><div> |
| 306 </div></template> |
| 307 </polymer-element> |
| 308 </html>'''.replaceAll(' ', ''), |
| 309 }, [ |
| 310 'error: $NO_IMPORT_WITHIN_ELEMENT (lib/test.html 3 2)' |
219 ]); | 311 ]); |
220 | 312 |
221 _testLinter('need a name for <polymer-element>', { | 313 _testLinter('need a name for <polymer-element>', { |
222 'a|lib/test.html': '''<html> | 314 'a|lib/test.html': '''<html> |
| 315 <link rel="import" href="../../packages/polymer/polymer.html"> |
223 <polymer-element></polymer-element> | 316 <polymer-element></polymer-element> |
224 </html>'''.replaceAll(' ', ''), | 317 </html>'''.replaceAll(' ', ''), |
225 }, [ | 318 }, [ |
226 'error: Missing tag name of the custom element. Please include an ' | 319 'error: Missing tag name of the custom element. Please include an ' |
227 'attribute like \'name="your-tag-name"\'. (lib/test.html 1 0)' | 320 'attribute like \'name="your-tag-name"\'. (lib/test.html 2 0)' |
228 ]); | 321 ]); |
229 | 322 |
230 _testLinter('name for <polymer-element> should have dashes', { | 323 _testLinter('name for <polymer-element> should have dashes', { |
231 'a|lib/test.html': '''<html> | 324 'a|lib/test.html': '''<html> |
| 325 <link rel="import" href="../../packages/polymer/polymer.html"> |
232 <polymer-element name="a"></polymer-element> | 326 <polymer-element name="a"></polymer-element> |
233 </html>'''.replaceAll(' ', ''), | 327 </html>'''.replaceAll(' ', ''), |
234 }, [ | 328 }, [ |
235 'error: Invalid name "a". Custom element names must have at least one' | 329 'error: Invalid name "a". Custom element names must have at least one' |
236 ' dash and can\'t be any of the following names: annotation-xml, ' | 330 ' dash and can\'t be any of the following names: annotation-xml, ' |
237 'color-profile, font-face, font-face-src, font-face-uri, ' | 331 'color-profile, font-face, font-face-src, font-face-uri, ' |
238 'font-face-format, font-face-name, missing-glyph. (lib/test.html 1 0)' | 332 'font-face-format, font-face-name, missing-glyph. (lib/test.html 2 0)' |
239 ]); | 333 ]); |
240 | 334 |
241 _testLinter('extend is a valid element or existing tag', { | 335 _testLinter('extend is a valid element or existing tag', { |
242 'a|lib/test.html': '''<html> | 336 'a|lib/test.html': '''<html> |
| 337 <link rel="import" href="../../packages/polymer/polymer.html"> |
243 <polymer-element name="x-a" extends="li"></polymer-element> | 338 <polymer-element name="x-a" extends="li"></polymer-element> |
244 </html>'''.replaceAll(' ', ''), | 339 </html>'''.replaceAll(' ', ''), |
245 }, []); | 340 }, []); |
246 | 341 |
247 _testLinter('extend is a valid element or existing tag', { | 342 _testLinter('extend is a valid element or existing tag', { |
248 'a|lib/test.html': '''<html> | 343 'a|lib/test.html': '''<html> |
| 344 <link rel="import" href="../../packages/polymer/polymer.html"> |
249 <polymer-element name="x-a" extends="x-b"></polymer-element> | 345 <polymer-element name="x-a" extends="x-b"></polymer-element> |
250 </html>'''.replaceAll(' ', ''), | 346 </html>'''.replaceAll(' ', ''), |
251 }, [ | 347 }, [ |
252 'warning: custom element with name "x-b" not found. (lib/test.html 1 0)' | 348 'warning: custom element with name "x-b" not found. (lib/test.html 2 0)' |
253 ]); | 349 ]); |
254 | 350 |
255 | 351 |
256 group('script type matches code', () { | 352 group('script type matches code', () { |
257 _testLinter('top-level, .dart url', { | 353 _testLinter('top-level, .dart url', { |
258 'a|lib/test.html': '''<html> | 354 'a|lib/test.html': '''<html> |
259 <script src="foo.dart"></script> | 355 <script src="foo.dart"></script> |
260 </html>'''.replaceAll(' ', ''), | 356 </html>'''.replaceAll(' ', ''), |
261 }, [ | 357 }, [ |
262 'warning: Wrong script type, expected type="application/dart".' | 358 'warning: Wrong script type, expected type="application/dart".' |
263 ' (lib/test.html 1 0)' | 359 ' (lib/test.html 1 0)' |
264 ]); | 360 ]); |
265 | 361 |
266 _testLinter('in polymer-element, .dart url', { | 362 _testLinter('in polymer-element, .dart url', { |
267 'a|lib/test.html': '''<html> | 363 'a|lib/test.html': '''<html> |
| 364 <link rel="import" href="../../packages/polymer/polymer.html"> |
268 <polymer-element name="x-a"> | 365 <polymer-element name="x-a"> |
269 <script src="foo.dart"></script> | 366 <script src="foo.dart"></script> |
270 </polymer-element> | 367 </polymer-element> |
271 </html>'''.replaceAll(' ', ''), | 368 </html>'''.replaceAll(' ', ''), |
272 }, [ | 369 }, [ |
273 'warning: Wrong script type, expected type="application/dart".' | 370 'warning: Wrong script type, expected type="application/dart".' |
274 ' (lib/test.html 2 0)' | 371 ' (lib/test.html 3 0)' |
275 ]); | 372 ]); |
276 | 373 |
277 _testLinter('in polymer-element, .js url', { | 374 _testLinter('in polymer-element, .js url', { |
278 'a|lib/test.html': '''<html> | 375 'a|lib/test.html': '''<html> |
| 376 <link rel="import" href="../../packages/polymer/polymer.html"> |
279 <polymer-element name="x-a"> | 377 <polymer-element name="x-a"> |
280 <script src="foo.js"></script> | 378 <script src="foo.js"></script> |
281 </polymer-element> | 379 </polymer-element> |
282 </html>'''.replaceAll(' ', ''), | 380 </html>'''.replaceAll(' ', ''), |
283 }, []); | 381 }, []); |
284 | 382 |
285 _testLinter('in polymer-element, inlined', { | 383 _testLinter('in polymer-element, inlined', { |
286 'a|lib/test.html': '''<html> | 384 'a|lib/test.html': '''<html> |
| 385 <link rel="import" href="../../packages/polymer/polymer.html"> |
287 <polymer-element name="x-a"> | 386 <polymer-element name="x-a"> |
288 <script>foo...</script> | 387 <script>foo...</script> |
289 </polymer-element> | 388 </polymer-element> |
290 </html>'''.replaceAll(' ', ''), | 389 </html>'''.replaceAll(' ', ''), |
291 }, []); | 390 }, []); |
292 | 391 |
293 _testLinter('top-level, dart type & .dart url', { | 392 _testLinter('top-level, dart type & .dart url', { |
294 'a|lib/test.html': '''<html> | 393 'a|lib/test.html': '''<html> |
295 <script type="application/dart" src="foo.dart"></script> | 394 <script type="application/dart" src="foo.dart"></script> |
296 </html>'''.replaceAll(' ', ''), | 395 </html>'''.replaceAll(' ', ''), |
(...skipping 12 matching lines...) Expand all Loading... |
309 _testLinter('script tags should have only src url or inline code', { | 408 _testLinter('script tags should have only src url or inline code', { |
310 'a|lib/test.html': '''<html> | 409 'a|lib/test.html': '''<html> |
311 <script type="application/dart" src="foo.dart">more</script> | 410 <script type="application/dart" src="foo.dart">more</script> |
312 </html>'''.replaceAll(' ', ''), | 411 </html>'''.replaceAll(' ', ''), |
313 }, [ | 412 }, [ |
314 'warning: script tag has "src" attribute and also has script text. ' | 413 'warning: script tag has "src" attribute and also has script text. ' |
315 '(lib/test.html 1 0)' | 414 '(lib/test.html 1 0)' |
316 ]); | 415 ]); |
317 | 416 |
318 group('event handlers', () { | 417 group('event handlers', () { |
319 _testLinter('onfoo is not polymer', { | 418 _testLinter('no longer warn about inline onfoo (Javascript)', { |
320 'a|lib/test.html': '''<html><body> | 419 'a|lib/test.html': '''<html><body> |
321 <div onfoo="something"></div> | 420 <div onfoo="something"></div> |
322 '''.replaceAll(' ', ''), | 421 '''.replaceAll(' ', ''), |
323 }, [ | 422 }, []); |
324 'warning: Event handler "onfoo" will be interpreted as an inline ' | |
325 'JavaScript event handler. Use the form ' | |
326 'on-event-name="{{handlerName}}" if you want a Dart handler ' | |
327 'that will automatically update the UI based on model changes. ' | |
328 '(lib/test.html 1 5)' | |
329 ]); | |
330 | 423 |
331 _testLinter('on-foo is only supported in polymer elements', { | 424 _testLinter('on-foo is only supported in polymer elements', { |
332 'a|lib/test.html': '''<html><body> | 425 'a|lib/test.html': '''<html><body> |
333 <div on-foo="something"></div> | 426 <div on-foo="something"></div> |
334 '''.replaceAll(' ', ''), | 427 '''.replaceAll(' ', ''), |
335 }, [ | 428 }, [ |
336 'warning: Inline event handlers are only supported inside ' | 429 'warning: Inline event handlers are only supported inside ' |
337 'declarations of <polymer-element>. ' | 430 'declarations of <polymer-element>. ' |
338 '(lib/test.html 1 5)' | 431 '(lib/test.html 1 5)' |
339 ]); | 432 ]); |
340 | 433 |
341 _testLinter('on-foo is not an expression', { | 434 _testLinter('on-foo is not an expression', { |
342 'a|lib/test.html': '''<html><body> | 435 'a|lib/test.html': '''<html><body> |
| 436 <link rel="import" href="../../packages/polymer/polymer.html"> |
343 <polymer-element name="x-a"><div on-foo="{{bar()}}"></div> | 437 <polymer-element name="x-a"><div on-foo="{{bar()}}"></div> |
344 </polymer-element> | 438 </polymer-element> |
345 '''.replaceAll(' ', ''), | 439 '''.replaceAll(' ', ''), |
346 }, [ | 440 }, [ |
347 'warning: Invalid event handler body "{{bar()}}". Declare a method ' | 441 'warning: Invalid event handler body "{{bar()}}". Declare a method ' |
348 'in your custom element "void handlerName(event, detail, target)" ' | 442 'in your custom element "void handlerName(event, detail, target)" ' |
349 'and use the form on-foo="{{handlerName}}". ' | 443 'and use the form on-foo="{{handlerName}}". ' |
350 '(lib/test.html 1 33)' | 444 '(lib/test.html 2 33)' |
351 ]); | 445 ]); |
352 | 446 |
353 _testLinter('on-foo can\'t be empty', { | 447 _testLinter('on-foo can\'t be empty', { |
354 'a|lib/test.html': '''<html><body> | 448 'a|lib/test.html': '''<html><body> |
| 449 <link rel="import" href="../../packages/polymer/polymer.html"> |
355 <polymer-element name="x-a"><div on-foo="{{}}"></div> | 450 <polymer-element name="x-a"><div on-foo="{{}}"></div> |
356 </polymer-element> | 451 </polymer-element> |
357 '''.replaceAll(' ', ''), | 452 '''.replaceAll(' ', ''), |
358 }, [ | 453 }, [ |
359 'warning: Invalid event handler body "{{}}". Declare a method ' | 454 'warning: Invalid event handler body "{{}}". Declare a method ' |
360 'in your custom element "void handlerName(event, detail, target)" ' | 455 'in your custom element "void handlerName(event, detail, target)" ' |
361 'and use the form on-foo="{{handlerName}}". ' | 456 'and use the form on-foo="{{handlerName}}". ' |
362 '(lib/test.html 1 33)' | 457 '(lib/test.html 2 33)' |
363 ]); | 458 ]); |
364 | 459 |
365 _testLinter('on-foo can\'t be empty', { | 460 _testLinter('on-foo can\'t be just space', { |
366 'a|lib/test.html': '''<html><body> | 461 'a|lib/test.html': '''<html><body> |
| 462 <link rel="import" href="../../packages/polymer/polymer.html"> |
367 <polymer-element name="x-a"><div on-foo="{{ }}"></div> | 463 <polymer-element name="x-a"><div on-foo="{{ }}"></div> |
368 </polymer-element> | 464 </polymer-element> |
369 '''.replaceAll(' ', ''), | 465 '''.replaceAll(' ', ''), |
370 }, [ | 466 }, [ |
371 'warning: Invalid event handler body "{{ }}". Declare a method ' | 467 'warning: Invalid event handler body "{{ }}". Declare a method ' |
372 'in your custom element "void handlerName(event, detail, target)" ' | 468 'in your custom element "void handlerName(event, detail, target)" ' |
373 'and use the form on-foo="{{handlerName}}". ' | 469 'and use the form on-foo="{{handlerName}}". ' |
374 '(lib/test.html 1 33)' | 470 '(lib/test.html 2 33)' |
375 ]); | 471 ]); |
376 | 472 |
377 _testLinter('on-foo-bar is supported as a custom event name', { | 473 _testLinter('on-foo-bar is supported as a custom event name', { |
378 'a|lib/test.html': '''<html><body> | 474 'a|lib/test.html': '''<html><body> |
| 475 <link rel="import" href="../../packages/polymer/polymer.html"> |
379 <polymer-element name="x-a"><div on-foo-bar="{{quux}}"></div> | 476 <polymer-element name="x-a"><div on-foo-bar="{{quux}}"></div> |
380 </polymer-element> | 477 </polymer-element> |
381 '''.replaceAll(' ', ''), | 478 '''.replaceAll(' ', ''), |
382 }, []); | 479 }, []); |
383 }); | 480 }); |
384 | 481 |
385 group('using custom tags', () { | 482 group('using custom tags', () { |
386 _testLinter('tag exists (x-tag)', { | 483 _testLinter('tag exists (x-tag)', { |
387 'a|lib/test.html': '<x-foo></x-foo>', | 484 'a|lib/test.html': '<x-foo></x-foo>', |
388 }, [ | 485 }, [ |
389 'warning: definition for Polymer element with tag name "x-foo" not ' | 486 'warning: definition for Polymer element with tag name "x-foo" not ' |
390 'found. (lib/test.html 0 0)' | 487 'found. (lib/test.html 0 0)' |
391 ]); | 488 ]); |
392 | 489 |
393 _testLinter('tag exists (type extension)', { | 490 _testLinter('tag exists (type extension)', { |
394 'a|lib/test.html': '<div is="x-foo"></div>', | 491 'a|lib/test.html': '<div is="x-foo"></div>', |
395 }, [ | 492 }, [ |
396 'warning: definition for Polymer element with tag name "x-foo" not ' | 493 'warning: definition for Polymer element with tag name "x-foo" not ' |
397 'found. (lib/test.html 0 0)' | 494 'found. (lib/test.html 0 0)' |
398 ]); | 495 ]); |
399 | 496 |
400 _testLinter('used correctly (no base tag)', { | 497 _testLinter('used correctly (no base tag)', { |
401 'a|lib/test.html': ''' | 498 'a|lib/test.html': ''' |
| 499 <link rel="import" href="../../packages/polymer/polymer.html"> |
402 <polymer-element name="x-a"></polymer-element> | 500 <polymer-element name="x-a"></polymer-element> |
403 <x-a></x-a> | 501 <x-a></x-a> |
404 '''.replaceAll(' ', ''), | 502 '''.replaceAll(' ', ''), |
405 }, []); | 503 }, []); |
406 | 504 |
407 _testLinter('used incorrectly (no base tag)', { | 505 _testLinter('used incorrectly (no base tag)', { |
408 'a|lib/test.html': ''' | 506 'a|lib/test.html': ''' |
| 507 <link rel="import" href="../../packages/polymer/polymer.html"> |
409 <polymer-element name="x-a"></polymer-element> | 508 <polymer-element name="x-a"></polymer-element> |
410 <div is="x-a"></div> | 509 <div is="x-a"></div> |
411 '''.replaceAll(' ', ''), | 510 '''.replaceAll(' ', ''), |
412 }, [ | 511 }, [ |
413 'warning: custom element "x-a" doesn\'t declare any type ' | 512 'warning: custom element "x-a" doesn\'t declare any type ' |
414 'extensions. To fix this, either rewrite this tag as ' | 513 'extensions. To fix this, either rewrite this tag as ' |
415 '<x-a> or add \'extends="div"\' to ' | 514 '<x-a> or add \'extends="div"\' to ' |
416 'the custom element declaration. (lib/test.html 1 0)' | 515 'the custom element declaration. (lib/test.html 2 0)' |
417 ]); | 516 ]); |
418 | 517 |
419 _testLinter('used incorrectly, imported def (no base tag)', { | 518 _testLinter('used incorrectly, imported def (no base tag)', { |
420 'a|lib/b.html': '<polymer-element name="x-a"></polymer-element>', | 519 'a|lib/b.html': ''' |
| 520 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 521 <polymer-element name="x-a"></polymer-element>''', |
421 'a|lib/test.html': ''' | 522 'a|lib/test.html': ''' |
422 <link rel="import" href="b.html"> | 523 <link rel="import" href="b.html"> |
423 <div is="x-a"></div> | 524 <div is="x-a"></div> |
424 '''.replaceAll(' ', ''), | 525 '''.replaceAll(' ', ''), |
425 }, [ | 526 }, [ |
426 'warning: custom element "x-a" doesn\'t declare any type ' | 527 'warning: custom element "x-a" doesn\'t declare any type ' |
427 'extensions. To fix this, either rewrite this tag as ' | 528 'extensions. To fix this, either rewrite this tag as ' |
428 '<x-a> or add \'extends="div"\' to ' | 529 '<x-a> or add \'extends="div"\' to ' |
429 'the custom element declaration. (lib/test.html 1 0)' | 530 'the custom element declaration. (lib/test.html 1 0)' |
430 ]); | 531 ]); |
431 | 532 |
432 _testLinter('used correctly (base tag)', { | 533 _testLinter('used correctly (base tag)', { |
433 'a|lib/b.html': ''' | 534 'a|lib/b.html': ''' |
| 535 <link rel="import" href="../../packages/polymer/polymer.html"> |
434 <polymer-element name="x-a" extends="div"> | 536 <polymer-element name="x-a" extends="div"> |
435 </polymer-element> | 537 </polymer-element> |
436 '''.replaceAll(' ', ''), | 538 '''.replaceAll(' ', ''), |
437 'a|lib/test.html': ''' | 539 'a|lib/test.html': ''' |
438 <link rel="import" href="b.html"> | 540 <link rel="import" href="b.html"> |
439 <div is="x-a"></div> | 541 <div is="x-a"></div> |
440 '''.replaceAll(' ', ''), | 542 '''.replaceAll(' ', ''), |
441 }, []); | 543 }, []); |
442 | 544 |
443 _testLinter('used incorrectly (missing base tag)', { | 545 _testLinter('used incorrectly (missing base tag)', { |
444 'a|lib/b.html': ''' | 546 'a|lib/b.html': ''' |
| 547 <link rel="import" href="../../packages/polymer/polymer.html"> |
445 <polymer-element name="x-a" extends="div"> | 548 <polymer-element name="x-a" extends="div"> |
446 </polymer-element> | 549 </polymer-element> |
447 '''.replaceAll(' ', ''), | 550 '''.replaceAll(' ', ''), |
448 'a|lib/test.html': ''' | 551 'a|lib/test.html': ''' |
449 <link rel="import" href="b.html"> | 552 <link rel="import" href="b.html"> |
450 <x-a></x-a> | 553 <x-a></x-a> |
451 '''.replaceAll(' ', ''), | 554 '''.replaceAll(' ', ''), |
452 }, [ | 555 }, [ |
453 'warning: custom element "x-a" extends from "div", but this tag ' | 556 'warning: custom element "x-a" extends from "div", but this tag ' |
454 'will not include the default properties of "div". To fix this, ' | 557 'will not include the default properties of "div". To fix this, ' |
455 'either write this tag as <div is="x-a"> or remove the "extends" ' | 558 'either write this tag as <div is="x-a"> or remove the "extends" ' |
456 'attribute from the custom element declaration. (lib/test.html 1 0)' | 559 'attribute from the custom element declaration. (lib/test.html 1 0)' |
457 ]); | 560 ]); |
458 | 561 |
459 _testLinter('used incorrectly (wrong base tag)', { | 562 _testLinter('used incorrectly (wrong base tag)', { |
460 'a|lib/b.html': ''' | 563 'a|lib/b.html': ''' |
| 564 <link rel="import" href="../../packages/polymer/polymer.html"> |
461 <polymer-element name="x-a" extends="div"> | 565 <polymer-element name="x-a" extends="div"> |
462 </polymer-element> | 566 </polymer-element> |
463 '''.replaceAll(' ', ''), | 567 '''.replaceAll(' ', ''), |
464 'a|lib/test.html': ''' | 568 'a|lib/test.html': ''' |
465 <link rel="import" href="b.html"> | 569 <link rel="import" href="b.html"> |
466 <span is="x-a"></span> | 570 <span is="x-a"></span> |
467 '''.replaceAll(' ', ''), | 571 '''.replaceAll(' ', ''), |
468 }, [ | 572 }, [ |
469 'warning: custom element "x-a" extends from "div". Did you mean ' | 573 'warning: custom element "x-a" extends from "div". Did you mean ' |
470 'to write <div is="x-a">? (lib/test.html 1 0)' | 574 'to write <div is="x-a">? (lib/test.html 1 0)' |
471 ]); | 575 ]); |
472 | 576 |
473 _testLinter('used incorrectly (wrong base tag, transitive)', { | 577 _testLinter('used incorrectly (wrong base tag, transitive)', { |
474 'a|lib/c.html': ''' | 578 'a|lib/c.html': ''' |
| 579 <link rel="import" href="../../packages/polymer/polymer.html"> |
475 <polymer-element name="x-c" extends="li"> | 580 <polymer-element name="x-c" extends="li"> |
476 </polymer-element> | 581 </polymer-element> |
477 <polymer-element name="x-b" extends="x-c"> | 582 <polymer-element name="x-b" extends="x-c"> |
478 </polymer-element> | 583 </polymer-element> |
479 '''.replaceAll(' ', ''), | 584 '''.replaceAll(' ', ''), |
480 'a|lib/b.html': ''' | 585 'a|lib/b.html': ''' |
| 586 <link rel="import" href="../../packages/polymer/polymer.html"> |
481 <link rel="import" href="c.html"> | 587 <link rel="import" href="c.html"> |
482 <polymer-element name="x-a" extends="x-b"> | 588 <polymer-element name="x-a" extends="x-b"> |
483 </polymer-element> | 589 </polymer-element> |
484 '''.replaceAll(' ', ''), | 590 '''.replaceAll(' ', ''), |
485 'a|lib/test.html': ''' | 591 'a|lib/test.html': ''' |
| 592 <link rel="import" href="../../packages/polymer/polymer.html"> |
486 <link rel="import" href="b.html"> | 593 <link rel="import" href="b.html"> |
487 <span is="x-a"></span> | 594 <span is="x-a"></span> |
488 '''.replaceAll(' ', ''), | 595 '''.replaceAll(' ', ''), |
489 }, [ | 596 }, [ |
490 'warning: custom element "x-a" extends from "li". Did you mean ' | 597 'warning: custom element "x-a" extends from "li". Did you mean ' |
491 'to write <li is="x-a">? (lib/test.html 1 0)' | 598 'to write <li is="x-a">? (lib/test.html 2 0)' |
492 ]); | 599 ]); |
493 }); | 600 }); |
494 | 601 |
495 group('custom attributes', () { | 602 group('custom attributes', () { |
496 _testLinter('foo-bar is no longer supported in attributes', { | 603 _testLinter('foo-bar is no longer supported in attributes', { |
497 'a|lib/test.html': '''<html><body> | 604 'a|lib/test.html': '''<html><body> |
| 605 <link rel="import" href="../../packages/polymer/polymer.html"> |
498 <polymer-element name="x-a" attributes="foo-bar"> | 606 <polymer-element name="x-a" attributes="foo-bar"> |
499 </polymer-element> | 607 </polymer-element> |
500 '''.replaceAll(' ', ''), | 608 '''.replaceAll(' ', ''), |
501 }, [ | 609 }, [ |
502 'warning: PolymerElement no longer recognizes attribute names with ' | 610 'warning: PolymerElement no longer recognizes attribute names with ' |
503 'dashes such as "foo-bar". Use "fooBar" or "foobar" instead (both ' | 611 'dashes such as "foo-bar". Use "fooBar" or "foobar" instead (both ' |
504 'forms are equivalent in HTML). (lib/test.html 1 28)' | 612 'forms are equivalent in HTML). (lib/test.html 2 28)' |
505 ]); | 613 ]); |
506 }); | 614 }); |
507 | 615 |
508 _testLinter("namespaced attributes don't cause an internal error", { | 616 _testLinter("namespaced attributes don't cause an internal error", { |
509 'a|lib/test.html': '''<html><body> | 617 'a|lib/test.html': '''<html><body> |
510 <svg xmlns="http://www.w3.org/2000/svg" width="520" height="350"> | 618 <svg xmlns="http://www.w3.org/2000/svg" width="520" height="350"> |
511 </svg> | 619 </svg> |
512 '''.replaceAll(' ', ''), | 620 '''.replaceAll(' ', ''), |
513 }, []); | 621 }, []); |
514 } | 622 } |
515 | 623 |
516 _testLinter(String name, Map inputFiles, List outputMessages, | 624 _testLinter(String name, Map inputFiles, List outputMessages, |
517 [bool solo = false]) { | 625 [bool solo = false]) { |
518 var linter = new Linter(new TransformOptions()); | 626 var linter = new Linter(new TransformOptions()); |
519 var outputFiles = {}; | 627 var outputFiles = {}; |
520 if (outputMessages.every((m) => m.startsWith('warning:'))) { | 628 if (outputMessages.every((m) => m.startsWith('warning:'))) { |
521 inputFiles.forEach((k, v) => outputFiles[k] = v); | 629 inputFiles.forEach((k, v) => outputFiles[k] = v); |
522 } | 630 } |
523 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo); | 631 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo); |
524 } | 632 } |
OLD | NEW |