| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 _testLinter('onfoo is not polymer', { | 254 _testLinter('onfoo is not polymer', { |
| 255 'a|lib/test.html': '''<html><body> | 255 'a|lib/test.html': '''<html><body> |
| 256 <div onfoo="something"></div> | 256 <div onfoo="something"></div> |
| 257 '''.replaceAll(' ', ''), | 257 '''.replaceAll(' ', ''), |
| 258 }, { | 258 }, { |
| 259 'a|lib/test.html.messages': | 259 'a|lib/test.html.messages': |
| 260 'warning: Event handler "onfoo" will be interpreted as an inline ' | 260 'warning: Event handler "onfoo" will be interpreted as an inline ' |
| 261 'JavaScript event handler. Use the form ' | 261 'JavaScript event handler. Use the form ' |
| 262 'on-event-name="handlerName" if you want a Dart handler ' | 262 'on-event-name="handlerName" if you want a Dart handler ' |
| 263 'that will automatically update the UI based on model changes. ' | 263 'that will automatically update the UI based on model changes. ' |
| 264 '(lib/test.html 1 0)' | 264 '(lib/test.html 1 5)' |
| 265 }); | 265 }); |
| 266 | 266 |
| 267 _testLinter('on-foo is only supported in polymer elements', { | 267 _testLinter('on-foo is only supported in polymer elements', { |
| 268 'a|lib/test.html': '''<html><body> | 268 'a|lib/test.html': '''<html><body> |
| 269 <div on-foo="something"></div> | 269 <div on-foo="something"></div> |
| 270 '''.replaceAll(' ', ''), | 270 '''.replaceAll(' ', ''), |
| 271 }, { | 271 }, { |
| 272 'a|lib/test.html.messages': | 272 'a|lib/test.html.messages': |
| 273 'warning: Inline event handlers are only supported inside ' | 273 'warning: Inline event handlers are only supported inside ' |
| 274 'declarations of <polymer-element>. ' | 274 'declarations of <polymer-element>. ' |
| 275 '(lib/test.html 1 0)' | 275 '(lib/test.html 1 5)' |
| 276 }); | 276 }); |
| 277 | 277 |
| 278 _testLinter('on-foo is not an expression', { | 278 _testLinter('on-foo is not an expression', { |
| 279 'a|lib/test.html': '''<html><body> | 279 'a|lib/test.html': '''<html><body> |
| 280 <polymer-element name="x-a"><div on-foo="bar()"></div> | 280 <polymer-element name="x-a"><div on-foo="bar()"></div> |
| 281 </polymer-element> | 281 </polymer-element> |
| 282 '''.replaceAll(' ', ''), | 282 '''.replaceAll(' ', ''), |
| 283 }, { | 283 }, { |
| 284 'a|lib/test.html.messages': | 284 'a|lib/test.html.messages': |
| 285 'warning: Invalid event handler body "bar()". Declare a method ' | 285 'warning: Invalid event handler body "bar()". Declare a method ' |
| 286 'in your custom element "void handlerName(event, detail, target)" ' | 286 'in your custom element "void handlerName(event, detail, target)" ' |
| 287 'and use the form on-foo="handlerName". ' | 287 'and use the form on-foo="handlerName". ' |
| 288 '(lib/test.html 1 28)' | 288 '(lib/test.html 1 33)' |
| 289 }); |
| 290 |
| 291 _testLinter('on-foo-bar is no longer supported', { |
| 292 'a|lib/test.html': '''<html><body> |
| 293 <polymer-element name="x-a"><div on-foo-bar="quux"></div> |
| 294 </polymer-element> |
| 295 '''.replaceAll(' ', ''), |
| 296 }, { |
| 297 'a|lib/test.html.messages': |
| 298 'warning: Invalid event name "on-foo-bar". After the "on-" the ' |
| 299 'event name should not use dashes. For example use "on-fooBar" or ' |
| 300 '"on-foobar" (both forms are equivalent in HTML). ' |
| 301 '(lib/test.html 1 33)' |
| 289 }); | 302 }); |
| 290 }); | 303 }); |
| 291 | 304 |
| 292 group('using custom tags', () { | 305 group('using custom tags', () { |
| 293 _testLinter('tag exists (x-tag)', { | 306 _testLinter('tag exists (x-tag)', { |
| 294 'a|lib/test.html': '<x-foo></x-foo>', | 307 'a|lib/test.html': '<x-foo></x-foo>', |
| 295 }, { | 308 }, { |
| 296 'a|lib/test.html.messages': | 309 'a|lib/test.html.messages': |
| 297 'warning: definition for custom element with tag name "x-foo" not ' | 310 'warning: definition for Polymer element with tag name "x-foo" not ' |
| 298 'found. (lib/test.html 0 0)' | 311 'found. (lib/test.html 0 0)' |
| 299 }); | 312 }); |
| 300 | 313 |
| 301 _testLinter('tag exists (type extension)', { | 314 _testLinter('tag exists (type extension)', { |
| 302 'a|lib/test.html': '<div is="x-foo"></div>', | 315 'a|lib/test.html': '<div is="x-foo"></div>', |
| 303 }, { | 316 }, { |
| 304 'a|lib/test.html.messages': | 317 'a|lib/test.html.messages': |
| 305 'warning: definition for custom element with tag name "x-foo" not ' | 318 'warning: definition for Polymer element with tag name "x-foo" not ' |
| 306 'found. (lib/test.html 0 0)' | 319 'found. (lib/test.html 0 0)' |
| 307 }); | 320 }); |
| 308 | 321 |
| 309 _testLinter('used correctly (no base tag)', { | 322 _testLinter('used correctly (no base tag)', { |
| 310 'a|lib/test.html': ''' | 323 'a|lib/test.html': ''' |
| 311 <polymer-element name="x-a"></polymer-element> | 324 <polymer-element name="x-a"></polymer-element> |
| 312 <x-a></x-a> | 325 <x-a></x-a> |
| 313 '''.replaceAll(' ', ''), | 326 '''.replaceAll(' ', ''), |
| 314 }, { | 327 }, { |
| 315 'a|lib/test.html.messages': '' | 328 'a|lib/test.html.messages': '' |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 'a|lib/test.html': ''' | 415 'a|lib/test.html': ''' |
| 403 <link rel="import" href="b.html"> | 416 <link rel="import" href="b.html"> |
| 404 <span is="x-a"></span> | 417 <span is="x-a"></span> |
| 405 '''.replaceAll(' ', ''), | 418 '''.replaceAll(' ', ''), |
| 406 }, { | 419 }, { |
| 407 'a|lib/test.html.messages': '' | 420 'a|lib/test.html.messages': '' |
| 408 'warning: custom element "x-a" extends from "li". Did you mean ' | 421 'warning: custom element "x-a" extends from "li". Did you mean ' |
| 409 'to write <li is="x-a">? (lib/test.html 1 0)' | 422 'to write <li is="x-a">? (lib/test.html 1 0)' |
| 410 }); | 423 }); |
| 411 }); | 424 }); |
| 425 |
| 426 group('custom attributes', () { |
| 427 _testLinter('foo-bar is no longer supported in attributes', { |
| 428 'a|lib/test.html': '''<html><body> |
| 429 <polymer-element name="x-a" attributes="foo-bar"> |
| 430 </polymer-element> |
| 431 '''.replaceAll(' ', ''), |
| 432 }, { |
| 433 'a|lib/test.html.messages': |
| 434 'warning: PolymerElement no longer recognizes attribute names with ' |
| 435 'dashes such as "foo-bar". Use "fooBar" or "foobar" instead (both ' |
| 436 'forms are equivalent in HTML). (lib/test.html 1 28)' |
| 437 }); |
| 438 }); |
| 412 } | 439 } |
| 413 | 440 |
| 414 _testLinter(String name, Map inputFiles, Map outputMessages) { | 441 _testLinter(String name, Map inputFiles, Map outputMessages) { |
| 415 var linter = new Linter(new TransformOptions(), _testFormatter); | 442 var linter = new Linter(new TransformOptions(), _testFormatter); |
| 416 var outputFiles = {}; | 443 var outputFiles = {}; |
| 417 inputFiles.forEach((k, v) => outputFiles[k] = v); | 444 inputFiles.forEach((k, v) => outputFiles[k] = v); |
| 418 outputMessages.forEach((k, v) => outputFiles[k] = v); | 445 outputMessages.forEach((k, v) => outputFiles[k] = v); |
| 419 var keys = inputFiles.keys.toSet(); | 446 var keys = inputFiles.keys.toSet(); |
| 420 keys.retainAll(outputMessages.keys); | 447 keys.retainAll(outputMessages.keys); |
| 421 expect(keys, isEmpty); | 448 expect(keys, isEmpty); |
| 422 testPhases(name, [[linter]], inputFiles, outputFiles); | 449 testPhases(name, [[linter]], inputFiles, outputFiles); |
| 423 } | 450 } |
| 424 | 451 |
| 425 | 452 |
| 426 _testFormatter(String kind, String message, Span span) { | 453 _testFormatter(String kind, String message, Span span) { |
| 427 var formattedMessage = '$kind: $message'; | 454 var formattedMessage = '$kind: $message'; |
| 428 if (span != null) { | 455 if (span != null) { |
| 429 formattedMessage = '$formattedMessage ' | 456 formattedMessage = '$formattedMessage ' |
| 430 '(${span.sourceUrl} ${span.start.line} ${span.start.column})'; | 457 '(${span.sourceUrl} ${span.start.line} ${span.start.column})'; |
| 431 } | 458 } |
| 432 return formattedMessage; | 459 return formattedMessage; |
| 433 } | 460 } |
| OLD | NEW |