Chromium Code Reviews| 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 'dart:convert'; | |
| 8 | |
| 7 import 'package:polymer/src/build/common.dart'; | 9 import 'package:polymer/src/build/common.dart'; |
| 8 import 'package:polymer/src/build/linter.dart'; | 10 import 'package:polymer/src/build/linter.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 10 | 12 |
| 11 import 'common.dart'; | 13 import 'common.dart'; |
| 12 | 14 |
| 13 void main() { | 15 void main() { |
| 14 _testLinter('nothing to report', { | 16 _testLinter('nothing to report', { |
| 15 'a|lib/test.html': '<!DOCTYPE html><html></html>', | 17 'a|lib/test.html': '<!DOCTYPE html><html></html>', |
| 16 }, []); | 18 }, []); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 _testLinter('do not nest <polymer-element>', { | 287 _testLinter('do not nest <polymer-element>', { |
| 286 'a|lib/test.html': '''<html> | 288 'a|lib/test.html': '''<html> |
| 287 <link rel="import" href="../../packages/polymer/polymer.html"> | 289 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 288 <polymer-element name="x-a"> | 290 <polymer-element name="x-a"> |
| 289 <template><div> | 291 <template><div> |
| 290 <polymer-element name="b"></polymer-element> | 292 <polymer-element name="b"></polymer-element> |
| 291 </div></template> | 293 </div></template> |
| 292 </polymer-element> | 294 </polymer-element> |
| 293 </html>'''.replaceAll(' ', ''), | 295 </html>'''.replaceAll(' ', ''), |
| 294 }, [ | 296 }, [ |
| 295 'error: Nested polymer element definitions are not allowed.' | 297 // We are wrapping this and converting to a warning. |
|
Siggi Cherem (dart-lang)
2014/08/05 19:37:21
yeah, same here - I'm inclined to do that for all
jakemac
2014/08/05 22:58:23
Done.
| |
| 298 'warning: Nested polymer element definitions are not allowed.' | |
| 296 ' (lib/test.html 4 4)' | 299 ' (lib/test.html 4 4)' |
| 297 ]); | 300 ]); |
| 298 | 301 |
| 299 _testLinter('do put import inside <polymer-element>', { | 302 _testLinter('do put import inside <polymer-element>', { |
| 300 'a|lib/b.html': '<html></html>', | 303 'a|lib/b.html': '<html></html>', |
| 301 'a|lib/test.html': '''<html> | 304 'a|lib/test.html': '''<html> |
| 302 <link rel="import" href="../../packages/polymer/polymer.html"> | 305 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 303 <polymer-element name="x-a"> | 306 <polymer-element name="x-a"> |
| 304 <link rel="import" href="b.html"> | 307 <link rel="import" href="b.html"> |
| 305 <template><div> | 308 <template><div> |
| 306 </div></template> | 309 </div></template> |
| 307 </polymer-element> | 310 </polymer-element> |
| 308 </html>'''.replaceAll(' ', ''), | 311 </html>'''.replaceAll(' ', ''), |
| 309 }, [ | 312 }, [ |
| 310 'error: $NO_IMPORT_WITHIN_ELEMENT (lib/test.html 3 2)' | 313 // We are wrapping this and converting to a warning. |
| 314 'warning: $NO_IMPORT_WITHIN_ELEMENT (lib/test.html 3 2)' | |
| 311 ]); | 315 ]); |
| 312 | 316 |
| 313 _testLinter('need a name for <polymer-element>', { | 317 _testLinter('need a name for <polymer-element>', { |
| 314 'a|lib/test.html': '''<html> | 318 'a|lib/test.html': '''<html> |
| 315 <link rel="import" href="../../packages/polymer/polymer.html"> | 319 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 316 <polymer-element></polymer-element> | 320 <polymer-element></polymer-element> |
| 317 </html>'''.replaceAll(' ', ''), | 321 </html>'''.replaceAll(' ', ''), |
| 318 }, [ | 322 }, [ |
| 319 'error: Missing tag name of the custom element. Please include an ' | 323 // We are wrapping this and converting to a warning. |
| 324 'warning: Missing tag name of the custom element. Please include an ' | |
| 320 'attribute like \'name="your-tag-name"\'. (lib/test.html 2 0)' | 325 'attribute like \'name="your-tag-name"\'. (lib/test.html 2 0)' |
| 321 ]); | 326 ]); |
| 322 | 327 |
| 323 _testLinter('name for <polymer-element> should have dashes', { | 328 _testLinter('name for <polymer-element> should have dashes', { |
| 324 'a|lib/test.html': '''<html> | 329 'a|lib/test.html': '''<html> |
| 325 <link rel="import" href="../../packages/polymer/polymer.html"> | 330 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 326 <polymer-element name="a"></polymer-element> | 331 <polymer-element name="a"></polymer-element> |
| 327 </html>'''.replaceAll(' ', ''), | 332 </html>'''.replaceAll(' ', ''), |
| 328 }, [ | 333 }, [ |
| 329 'error: Invalid name "a". Custom element names must have at least one' | 334 // We are wrapping this and converting to a warning. |
| 335 'warning: Invalid name "a". Custom element names must have at least one' | |
| 330 ' dash and can\'t be any of the following names: annotation-xml, ' | 336 ' dash and can\'t be any of the following names: annotation-xml, ' |
| 331 'color-profile, font-face, font-face-src, font-face-uri, ' | 337 'color-profile, font-face, font-face-src, font-face-uri, ' |
| 332 'font-face-format, font-face-name, missing-glyph. (lib/test.html 2 0)' | 338 'font-face-format, font-face-name, missing-glyph. (lib/test.html 2 0)' |
| 333 ]); | 339 ]); |
| 334 | 340 |
| 335 _testLinter('extend is a valid element or existing tag', { | 341 _testLinter('extend is a valid element or existing tag', { |
| 336 'a|lib/test.html': '''<html> | 342 'a|lib/test.html': '''<html> |
| 337 <link rel="import" href="../../packages/polymer/polymer.html"> | 343 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 338 <polymer-element name="x-a" extends="li"></polymer-element> | 344 <polymer-element name="x-a" extends="li"></polymer-element> |
| 339 </html>'''.replaceAll(' ', ''), | 345 </html>'''.replaceAll(' ', ''), |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 'forms are equivalent in HTML). (lib/test.html 2 28)' | 644 'forms are equivalent in HTML). (lib/test.html 2 28)' |
| 639 ]); | 645 ]); |
| 640 }); | 646 }); |
| 641 | 647 |
| 642 _testLinter("namespaced attributes don't cause an internal error", { | 648 _testLinter("namespaced attributes don't cause an internal error", { |
| 643 'a|lib/test.html': '''<html><body> | 649 'a|lib/test.html': '''<html><body> |
| 644 <svg xmlns="http://www.w3.org/2000/svg" width="520" height="350"> | 650 <svg xmlns="http://www.w3.org/2000/svg" width="520" height="350"> |
| 645 </svg> | 651 </svg> |
| 646 '''.replaceAll(' ', ''), | 652 '''.replaceAll(' ', ''), |
| 647 }, []); | 653 }, []); |
| 654 | |
| 655 group('output logs to file', () { | |
| 656 final outputLogsPhases = [[new Linter( | |
| 657 new TransformOptions(injectBuildLogsInOutput: true))]]; | |
| 658 | |
| 659 testPhases("logs are output to file", outputLogsPhases, { | |
| 660 'a|web/test.html': '<!DOCTYPE html><html>\n' | |
| 661 '<polymer-element name="x-a"></polymer-element>' | |
| 662 '<script type="application/dart" src="foo.dart">' | |
| 663 '</script>' | |
| 664 '<script src="packages/browser/dart.js"></script>' | |
| 665 '</html>', | |
| 666 }, { | |
| 667 'a|web/test.html._buildLogs.1': | |
| 668 '[{' | |
| 669 '"level":"Warning",' | |
| 670 '"message":${JSON.encode(usePolymerHtmlMessage(0))},' | |
| 671 '"span":{' | |
| 672 '"location":"web/test.html:2:1",' | |
| 673 '"text":' | |
| 674 '"${new HtmlEscape().convert('<polymer-element name="x-a">')}"' | |
| 675 '}' | |
| 676 '}]', | |
| 677 }, [ | |
| 678 // Logs should still make it to barback too. | |
| 679 'warning: ${usePolymerHtmlMessage(0)} (web/test.html 1 0)', | |
| 680 ]); | |
| 681 }); | |
| 648 } | 682 } |
| 649 | 683 |
| 650 _testLinter(String name, Map inputFiles, List outputMessages, | 684 _testLinter(String name, Map inputFiles, List outputMessages, |
| 651 [bool solo = false]) { | 685 [bool solo = false]) { |
| 652 var linter = new Linter(new TransformOptions()); | 686 var linter = new Linter(new TransformOptions()); |
| 653 var outputFiles = {}; | 687 var outputFiles = {}; |
| 654 if (outputMessages.every((m) => m.startsWith('warning:'))) { | 688 if (outputMessages.every((m) => m.startsWith('warning:'))) { |
| 655 inputFiles.forEach((k, v) => outputFiles[k] = v); | 689 inputFiles.forEach((k, v) => outputFiles[k] = v); |
| 656 } | 690 } |
| 657 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo); | 691 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo); |
| 658 } | 692 } |
| OLD | NEW |