| 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 16 matching lines...) Expand all Loading... |
| 27 '</script>' | 27 '</script>' |
| 28 '<script src="packages/browser/dart.js"></script>' | 28 '<script src="packages/browser/dart.js"></script>' |
| 29 '</html>', | 29 '</html>', |
| 30 }, { | 30 }, { |
| 31 'a|web/test.html.messages': '', | 31 'a|web/test.html.messages': '', |
| 32 }); | 32 }); |
| 33 | 33 |
| 34 _testLinter('missing Dart code and dart.js', { | 34 _testLinter('missing Dart code and dart.js', { |
| 35 'a|web/test.html': '<!DOCTYPE html><html></html>', | 35 'a|web/test.html': '<!DOCTYPE html><html></html>', |
| 36 }, { | 36 }, { |
| 37 'a|web/test.html.messages': 'error: $USE_INIT_DART', | 37 'a|web/test.html.messages': 'error: $USE_INIT_DART\n' |
| 38 'error: $USE_DART_JS', |
| 38 }); | 39 }); |
| 39 | 40 |
| 40 _testLinter('using deprecated boot.js', { | 41 _testLinter('using deprecated boot.js', { |
| 41 'a|web/test.html': '<!DOCTYPE html><html>\n' | 42 'a|web/test.html': '<!DOCTYPE html><html>\n' |
| 42 '<script src="packages/polymer/boot.js"></script>' | 43 '<script src="packages/polymer/boot.js"></script>' |
| 43 '<script type="application/dart" src="foo.dart">' | 44 '<script type="application/dart" src="foo.dart">' |
| 44 '</script>' | 45 '</script>' |
| 45 '<script src="packages/browser/dart.js"></script>' | 46 '<script src="packages/browser/dart.js"></script>' |
| 46 '</html>', | 47 '</html>', |
| 47 }, { | 48 }, { |
| 48 'a|web/test.html.messages': 'warning: $BOOT_JS_DEPRECATED ' | 49 'a|web/test.html.messages': 'warning: $BOOT_JS_DEPRECATED ' |
| 49 '(web/test.html 1 0)', | 50 '(web/test.html 1 0)', |
| 50 }); | 51 }); |
| 51 }); | 52 }); |
| 52 group('single script tag per document', () { | 53 group('single script tag per document', () { |
| 53 _testLinter('two top-level tags', { | 54 _testLinter('two top-level tags', { |
| 54 'a|web/test.html': '<!DOCTYPE html><html>' | 55 'a|web/test.html': '<!DOCTYPE html><html>' |
| 55 '<script type="application/dart" src="a.dart">' | 56 '<script type="application/dart" src="a.dart">' |
| 56 '</script>\n' | 57 '</script>\n' |
| 57 '<script type="application/dart" src="b.dart">' | 58 '<script type="application/dart" src="b.dart">' |
| 58 '</script>' | 59 '</script>' |
| 59 '<script src="packages/browser/dart.js"></script>' | 60 '<script src="packages/browser/dart.js"></script>' |
| 60 }, { | 61 }, { |
| 61 'a|web/test.html.messages': | 62 'a|web/test.html.messages': |
| 62 'warning: Only one "application/dart" script tag per document is' | 63 'warning: Only one "application/dart" script tag per document is' |
| 63 ' allowed. (web/test.html 1 0)', | 64 ' allowed. (web/test.html 1 0)', |
| 64 }); | 65 }); |
| 65 | 66 |
| 66 _testLinter('two top-level tags, non entrypoint', { | 67 _testLinter('two top-level tags, non entrypoint', { |
| 67 'a|lib/test.html': '<!DOCTYPE html><html>' | 68 'a|lib/test.html': '<!DOCTYPE html><html>' |
| 68 '<script type="application/dart" src="a.dart">' | 69 '<script type="application/dart" src="a.dart">' |
| 69 '</script>\n' | 70 '</script>\n' |
| 70 '<script type="application/dart" src="b.dart">' | 71 '<script type="application/dart" src="b.dart">' |
| 71 '</script>' | 72 '</script>' |
| 72 '<script src="packages/browser/dart.js"></script>' | 73 '<script src="packages/browser/dart.js"></script>' |
| 73 }, { | 74 }, { |
| 74 'a|lib/test.html.messages': | 75 'a|lib/test.html.messages': |
| 75 'warning: Only one "application/dart" script tag per document is' | 76 'warning: Only one "application/dart" script tag per document is' |
| 76 ' allowed. (lib/test.html 1 0)', | 77 ' allowed. (lib/test.html 1 0)', |
| 77 }); | 78 }); |
| 78 | 79 |
| 79 _testLinter('tags inside elements', { | 80 _testLinter('tags inside elements', { |
| 80 'a|web/test.html': '<!DOCTYPE html><html>' | 81 'a|web/test.html': '<!DOCTYPE html><html>' |
| 81 '<polymer-element name="x-a">' | 82 '<polymer-element name="x-a">' |
| 82 '<script type="application/dart" src="a.dart">' | 83 '<script type="application/dart" src="a.dart">' |
| 83 '</script>' | 84 '</script>' |
| 84 '</polymer-element>\n' | 85 '</polymer-element>\n' |
| 85 '<script type="application/dart" src="b.dart">' | 86 '<script type="application/dart" src="b.dart">' |
| 86 '</script>' | 87 '</script>' |
| 87 '<script src="packages/browser/dart.js"></script>' | 88 '<script src="packages/browser/dart.js"></script>' |
| 88 }, { | 89 }, { |
| 89 'a|web/test.html.messages': | 90 'a|web/test.html.messages': |
| 90 'warning: Only one "application/dart" script tag per document is' | 91 'warning: Only one "application/dart" script tag per document is' |
| 91 ' allowed. (web/test.html 1 0)', | 92 ' allowed. (web/test.html 1 0)', |
| 92 }); | 93 }); |
| 93 }); | 94 }); |
| 94 | 95 |
| 95 group('doctype warning', () { | 96 group('doctype warning', () { |
| 96 _testLinter('in web', { | 97 _testLinter('in web', { |
| 97 'a|web/test.html': '<html></html>', | 98 'a|web/test.html': '<html></html>', |
| 98 }, { | 99 }, { |
| 99 'a|web/test.html.messages': | 100 'a|web/test.html.messages': |
| 100 'warning: Unexpected start tag (html). Expected DOCTYPE. ' | 101 'warning: Unexpected start tag (html). Expected DOCTYPE. ' |
| 101 '(web/test.html 0 0)\n' | 102 '(web/test.html 0 0)\n' |
| 102 'error: $USE_INIT_DART', | 103 'error: $USE_INIT_DART\n' |
| 104 'error: $USE_DART_JS', |
| 103 }); | 105 }); |
| 104 | 106 |
| 105 _testLinter('in lib', { | 107 _testLinter('in lib', { |
| 106 'a|lib/test.html': '<html></html>', | 108 'a|lib/test.html': '<html></html>', |
| 107 }, { | 109 }, { |
| 108 'a|lib/test.html.messages': '', | 110 'a|lib/test.html.messages': '', |
| 109 }); | 111 }); |
| 110 }); | 112 }); |
| 111 | 113 |
| 112 group('duplicate polymer-elements,', () { | 114 group('duplicate polymer-elements,', () { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 </polymer-element> | 354 </polymer-element> |
| 353 '''.replaceAll(' ', ''), | 355 '''.replaceAll(' ', ''), |
| 354 }, { | 356 }, { |
| 355 'a|lib/test.html.messages': | 357 'a|lib/test.html.messages': |
| 356 'warning: Invalid event handler body "bar()". Declare a method ' | 358 'warning: Invalid event handler body "bar()". Declare a method ' |
| 357 'in your custom element "void handlerName(event, detail, target)" ' | 359 'in your custom element "void handlerName(event, detail, target)" ' |
| 358 'and use the form on-foo="handlerName". ' | 360 'and use the form on-foo="handlerName". ' |
| 359 '(lib/test.html 1 33)' | 361 '(lib/test.html 1 33)' |
| 360 }); | 362 }); |
| 361 | 363 |
| 362 _testLinter('on-foo-bar is supported as a custom event name', { | 364 _testLinter('on-foo-bar is no longer supported', { |
| 363 'a|lib/test.html': '''<html><body> | 365 'a|lib/test.html': '''<html><body> |
| 364 <polymer-element name="x-a"><div on-foo-bar="quux"></div> | 366 <polymer-element name="x-a"><div on-foo-bar="quux"></div> |
| 365 </polymer-element> | 367 </polymer-element> |
| 366 '''.replaceAll(' ', ''), | 368 '''.replaceAll(' ', ''), |
| 367 }, {}); | 369 }, { |
| 370 'a|lib/test.html.messages': |
| 371 'warning: Invalid event name "on-foo-bar". After the "on-" the ' |
| 372 'event name should not use dashes. For example use "on-fooBar" or ' |
| 373 '"on-foobar" (both forms are equivalent in HTML). ' |
| 374 '(lib/test.html 1 33)' |
| 375 }); |
| 368 }); | 376 }); |
| 369 | 377 |
| 370 group('using custom tags', () { | 378 group('using custom tags', () { |
| 371 _testLinter('tag exists (x-tag)', { | 379 _testLinter('tag exists (x-tag)', { |
| 372 'a|lib/test.html': '<x-foo></x-foo>', | 380 'a|lib/test.html': '<x-foo></x-foo>', |
| 373 }, { | 381 }, { |
| 374 'a|lib/test.html.messages': | 382 'a|lib/test.html.messages': |
| 375 'warning: definition for Polymer element with tag name "x-foo" not ' | 383 'warning: definition for Polymer element with tag name "x-foo" not ' |
| 376 'found. (lib/test.html 0 0)' | 384 'found. (lib/test.html 0 0)' |
| 377 }); | 385 }); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 | 524 |
| 517 | 525 |
| 518 _testFormatter(String kind, String message, Span span) { | 526 _testFormatter(String kind, String message, Span span) { |
| 519 var formattedMessage = '$kind: $message'; | 527 var formattedMessage = '$kind: $message'; |
| 520 if (span != null) { | 528 if (span != null) { |
| 521 formattedMessage = '$formattedMessage ' | 529 formattedMessage = '$formattedMessage ' |
| 522 '(${span.sourceUrl} ${span.start.line} ${span.start.column})'; | 530 '(${span.sourceUrl} ${span.start.line} ${span.start.column})'; |
| 523 } | 531 } |
| 524 return formattedMessage; | 532 return formattedMessage; |
| 525 } | 533 } |
| OLD | NEW |