| 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 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 _testLinter('top-level, dart type & .js url', { | 398 _testLinter('top-level, dart type & .js url', { |
| 399 'a|lib/test.html': '''<html> | 399 'a|lib/test.html': '''<html> |
| 400 <script type="application/dart" src="foo.js"></script> | 400 <script type="application/dart" src="foo.js"></script> |
| 401 </html>'''.replaceAll(' ', ''), | 401 </html>'''.replaceAll(' ', ''), |
| 402 }, [ | 402 }, [ |
| 403 'warning: "application/dart" scripts should use the .dart file ' | 403 'warning: "application/dart" scripts should use the .dart file ' |
| 404 'extension. (lib/test.html 1 0)' | 404 'extension. (lib/test.html 1 0)' |
| 405 ]); | 405 ]); |
| 406 }); | 406 }); |
| 407 | 407 |
| 408 _testLinter('script tags should have at least src url or inline code', { |
| 409 'a|lib/test.html': '''<html> |
| 410 <script type="application/dart"></script> |
| 411 </html>'''.replaceAll(' ', ''), |
| 412 }, [ |
| 413 'warning: script tag seems empty. ' |
| 414 '(lib/test.html 1 0)' |
| 415 ]); |
| 416 |
| 408 _testLinter('script tags should have only src url or inline code', { | 417 _testLinter('script tags should have only src url or inline code', { |
| 409 'a|lib/test.html': '''<html> | 418 'a|lib/test.html': '''<html> |
| 410 <script type="application/dart" src="foo.dart">more</script> | 419 <script type="application/dart" src="foo.dart">more</script> |
| 411 </html>'''.replaceAll(' ', ''), | 420 </html>'''.replaceAll(' ', ''), |
| 412 }, [ | 421 }, [ |
| 413 'warning: script tag has "src" attribute and also has script text. ' | 422 'warning: script tag has "src" attribute and also has script text. ' |
| 414 '(lib/test.html 1 0)' | 423 '(lib/test.html 1 0)' |
| 415 ]); | 424 ]); |
| 416 | 425 |
| 417 group('event handlers', () { | 426 group('event handlers', () { |
| 418 _testLinter('no longer warn about inline onfoo (Javascript)', { | 427 _testLinter('no longer warn about inline onfoo (Javascript)', { |
| 419 'a|lib/test.html': '''<html><body> | 428 'a|lib/test.html': '''<html><body> |
| 420 <div onfoo="something"></div> | 429 <div onfoo="something"></div> |
| 421 '''.replaceAll(' ', ''), | 430 '''.replaceAll(' ', ''), |
| 422 }, []); | 431 }, []); |
| 423 | 432 |
| 424 _testLinter('on-foo is only supported in polymer elements', { | 433 _testLinter('on-foo is only supported in polymer elements', { |
| 425 'a|lib/test.html': '''<html><body> | 434 'a|lib/test.html': '''<html><body> |
| 426 <div on-foo="something"></div> | 435 <div on-foo="something"></div> |
| 427 '''.replaceAll(' ', ''), | 436 '''.replaceAll(' ', ''), |
| 428 }, [ | 437 }, [ |
| 429 'warning: Inline event handlers are only supported inside ' | 438 'warning: Inline event handlers are only supported inside ' |
| 430 'declarations of <polymer-element>. ' | 439 'declarations of <polymer-element>. ' |
| 431 '(lib/test.html 1 5)' | 440 '(lib/test.html 1 5)' |
| 432 ]); | 441 ]); |
| 433 | 442 |
| 443 _testLinter('on-foo uses the {{ binding }} syntax', { |
| 444 'a|lib/test.html': '''<html><body> |
| 445 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 446 <polymer-element name="x-a"><div on-foo="bar"></div> |
| 447 </polymer-element> |
| 448 '''.replaceAll(' ', ''), |
| 449 }, [ |
| 450 'warning: Invalid event handler body "bar". Declare a method ' |
| 451 'in your custom element "void handlerName(event, detail, target)" ' |
| 452 'and use the form on-foo="{{handlerName}}". ' |
| 453 '(lib/test.html 2 33)' |
| 454 ]); |
| 455 |
| 434 _testLinter('on-foo is not an expression', { | 456 _testLinter('on-foo is not an expression', { |
| 435 'a|lib/test.html': '''<html><body> | 457 'a|lib/test.html': '''<html><body> |
| 436 <link rel="import" href="../../packages/polymer/polymer.html"> | 458 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 437 <polymer-element name="x-a"><div on-foo="{{bar()}}"></div> | 459 <polymer-element name="x-a"><div on-foo="{{bar()}}"></div> |
| 438 </polymer-element> | 460 </polymer-element> |
| 439 '''.replaceAll(' ', ''), | 461 '''.replaceAll(' ', ''), |
| 440 }, [ | 462 }, [ |
| 441 'warning: Invalid event handler body "{{bar()}}". Declare a method ' | 463 'warning: Invalid event handler body "{{bar()}}". Declare a method ' |
| 442 'in your custom element "void handlerName(event, detail, target)" ' | 464 'in your custom element "void handlerName(event, detail, target)" ' |
| 443 'and use the form on-foo="{{handlerName}}". ' | 465 'and use the form on-foo="{{handlerName}}". ' |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 | 645 |
| 624 _testLinter(String name, Map inputFiles, List outputMessages, | 646 _testLinter(String name, Map inputFiles, List outputMessages, |
| 625 [bool solo = false]) { | 647 [bool solo = false]) { |
| 626 var linter = new Linter(new TransformOptions()); | 648 var linter = new Linter(new TransformOptions()); |
| 627 var outputFiles = {}; | 649 var outputFiles = {}; |
| 628 if (outputMessages.every((m) => m.startsWith('warning:'))) { | 650 if (outputMessages.every((m) => m.startsWith('warning:'))) { |
| 629 inputFiles.forEach((k, v) => outputFiles[k] = v); | 651 inputFiles.forEach((k, v) => outputFiles[k] = v); |
| 630 } | 652 } |
| 631 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo); | 653 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo); |
| 632 } | 654 } |
| OLD | NEW |