| 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 mixin_test; | 5 library mixin_test; |
| 6 | 6 |
| 7 import 'package:csslib/src/messages.dart'; |
| 7 import 'package:test/test.dart'; | 8 import 'package:test/test.dart'; |
| 8 | 9 |
| 9 import 'testing.dart'; | 10 import 'testing.dart'; |
| 10 | 11 |
| 11 compileAndValidate(String input, String generated) { | 12 compileAndValidate(String input, String generated) { |
| 12 var errors = []; | 13 var errors = <Message>[]; |
| 13 var stylesheet = compileCss(input, errors: errors, opts: options); | 14 var stylesheet = compileCss(input, errors: errors, opts: options); |
| 14 expect(stylesheet != null, true); | 15 expect(stylesheet != null, true); |
| 15 expect(errors.isEmpty, true, reason: errors.toString()); | 16 expect(errors.isEmpty, true, reason: errors.toString()); |
| 16 expect(prettyPrint(stylesheet), generated); | 17 expect(prettyPrint(stylesheet), generated); |
| 17 } | 18 } |
| 18 | 19 |
| 19 compilePolyfillAndValidate(String input, String generated) { | 20 compilePolyfillAndValidate(String input, String generated) { |
| 20 var errors = []; | 21 var errors = <Message>[]; |
| 21 var stylesheet = polyFillCompileCss(input, errors: errors, opts: options); | 22 var stylesheet = polyFillCompileCss(input, errors: errors, opts: options); |
| 22 expect(stylesheet != null, true); | 23 expect(stylesheet != null, true); |
| 23 expect(errors.isEmpty, true, reason: errors.toString()); | 24 expect(errors.isEmpty, true, reason: errors.toString()); |
| 24 expect(prettyPrint(stylesheet), generated); | 25 expect(prettyPrint(stylesheet), generated); |
| 25 } | 26 } |
| 26 | 27 |
| 27 void topLevelMixin() { | 28 void topLevelMixin() { |
| 28 compileAndValidate(r''' | 29 compileAndValidate(r''' |
| 29 @mixin silly-links { | 30 @mixin silly-links { |
| 30 a { | 31 a { |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 @include colors(@values); | 407 @include colors(@values); |
| 407 } | 408 } |
| 408 ''', r'''.primary { | 409 ''', r'''.primary { |
| 409 color: #f00; | 410 color: #f00; |
| 410 background-color: #0f0; | 411 background-color: #0f0; |
| 411 border-color: #00f; | 412 border-color: #00f; |
| 412 }'''); | 413 }'''); |
| 413 } | 414 } |
| 414 | 415 |
| 415 void badDeclarationInclude() { | 416 void badDeclarationInclude() { |
| 416 final errors = []; | 417 final errors = <Message>[]; |
| 417 final input = r''' | 418 final input = r''' |
| 418 @mixin a { | 419 @mixin a { |
| 419 #foo-id { | 420 #foo-id { |
| 420 color: red; | 421 color: red; |
| 421 } | 422 } |
| 422 } | 423 } |
| 423 @mixin b { | 424 @mixin b { |
| 424 span { | 425 span { |
| 425 border: 2px dashed red; | 426 border: 2px dashed red; |
| 426 @include a; | 427 @include a; |
| 427 } | 428 } |
| 428 } | 429 } |
| 429 @include b; | 430 @include b; |
| 430 '''; | 431 '''; |
| 431 | 432 |
| 432 var stylesheet = compileCss(input, errors: errors, opts: options); | 433 var stylesheet = compileCss(input, errors: errors, opts: options); |
| 433 | 434 |
| 434 expect(stylesheet != null, true); | 435 expect(stylesheet != null, true); |
| 435 expect(errors.isNotEmpty, true); | 436 expect(errors.isNotEmpty, true); |
| 436 expect(errors.length, 1, reason: errors.toString()); | 437 expect(errors.length, 1, reason: errors.toString()); |
| 437 var error = errors[0]; | 438 var error = errors[0]; |
| 438 expect(error.message, 'Using top-level mixin a as a declaration'); | 439 expect(error.message, 'Using top-level mixin a as a declaration'); |
| 439 expect(error.span.start.line, 8); | 440 expect(error.span.start.line, 8); |
| 440 expect(error.span.end.offset, 105); | 441 expect(error.span.end.offset, 105); |
| 441 } | 442 } |
| 442 | 443 |
| 443 void badTopInclude() { | 444 void badTopInclude() { |
| 444 final errors = []; | 445 final errors = <Message>[]; |
| 445 final input = r''' | 446 final input = r''' |
| 446 @mixin b { | 447 @mixin b { |
| 447 color: red; | 448 color: red; |
| 448 } | 449 } |
| 449 | 450 |
| 450 @mixin a { | 451 @mixin a { |
| 451 span { | 452 span { |
| 452 border: 2px dashed red; | 453 border: 2px dashed red; |
| 453 } | 454 } |
| 454 @include b; | 455 @include b; |
| 455 } | 456 } |
| 456 | 457 |
| 457 @include a; | 458 @include a; |
| 458 '''; | 459 '''; |
| 459 | 460 |
| 460 var stylesheet = compileCss(input, errors: errors, opts: options); | 461 var stylesheet = compileCss(input, errors: errors, opts: options); |
| 461 expect(stylesheet != null, true); | 462 expect(stylesheet != null, true); |
| 462 expect(errors.length, 1, reason: errors.toString()); | 463 expect(errors.length, 1, reason: errors.toString()); |
| 463 var error = errors[0]; | 464 var error = errors[0]; |
| 464 expect(error.message, 'Using declaration mixin b as top-level mixin'); | 465 expect(error.message, 'Using declaration mixin b as top-level mixin'); |
| 465 expect(error.span.start.line, 8); | 466 expect(error.span.start.line, 8); |
| 466 expect(error.span.end.offset, 90); | 467 expect(error.span.end.offset, 90); |
| 467 } | 468 } |
| 468 | 469 |
| 469 void emptyMixin() { | 470 void emptyMixin() { |
| 470 final errors = []; | 471 final errors = <Message>[]; |
| 471 final input = r''' | 472 final input = r''' |
| 472 @mixin a { | 473 @mixin a { |
| 473 } | 474 } |
| 474 @mixin b { | 475 @mixin b { |
| 475 border: 2px dashed red; | 476 border: 2px dashed red; |
| 476 @include a; | 477 @include a; |
| 477 } | 478 } |
| 478 div { | 479 div { |
| 479 @include b; | 480 @include b; |
| 480 } | 481 } |
| 481 '''; | 482 '''; |
| 482 | 483 |
| 483 var generated = r'''div { | 484 var generated = r'''div { |
| 484 border: 2px dashed #f00; | 485 border: 2px dashed #f00; |
| 485 }'''; | 486 }'''; |
| 486 | 487 |
| 487 var stylesheet = compileCss(input, errors: errors, opts: options); | 488 var stylesheet = compileCss(input, errors: errors, opts: options); |
| 488 | 489 |
| 489 expect(stylesheet != null, true); | 490 expect(stylesheet != null, true); |
| 490 expect(errors.isEmpty, true, reason: errors.toString()); | 491 expect(errors.isEmpty, true, reason: errors.toString()); |
| 491 expect(prettyPrint(stylesheet), generated); | 492 expect(prettyPrint(stylesheet), generated); |
| 492 } | 493 } |
| 493 | 494 |
| 494 void undefinedTopLevel() { | 495 void undefinedTopLevel() { |
| 495 final errors = []; | 496 final errors = <Message>[]; |
| 496 final input = r''' | 497 final input = r''' |
| 497 @mixin a { | 498 @mixin a { |
| 498 @include b; | 499 @include b; |
| 499 } | 500 } |
| 500 @mixin b { | 501 @mixin b { |
| 501 span { | 502 span { |
| 502 border: 2px dashed red; | 503 border: 2px dashed red; |
| 503 } | 504 } |
| 504 @include a; | 505 @include a; |
| 505 } | 506 } |
| 506 | 507 |
| 507 @include b; | 508 @include b; |
| 508 | 509 |
| 509 '''; | 510 '''; |
| 510 | 511 |
| 511 var stylesheet = compileCss(input, errors: errors, opts: options); | 512 var stylesheet = compileCss(input, errors: errors, opts: options); |
| 512 | 513 |
| 513 expect(stylesheet != null, true); | 514 expect(stylesheet != null, true); |
| 514 expect(errors.isNotEmpty, true); | 515 expect(errors.isNotEmpty, true); |
| 515 expect(errors.length, 1, reason: errors.toString()); | 516 expect(errors.length, 1, reason: errors.toString()); |
| 516 var error = errors[0]; | 517 var error = errors[0]; |
| 517 expect(error.message, 'Undefined mixin b'); | 518 expect(error.message, 'Undefined mixin b'); |
| 518 expect(error.span.start.line, 1); | 519 expect(error.span.start.line, 1); |
| 519 expect(error.span.start.offset, 14); | 520 expect(error.span.start.offset, 14); |
| 520 } | 521 } |
| 521 | 522 |
| 522 void undefinedDeclaration() { | 523 void undefinedDeclaration() { |
| 523 final errors = []; | 524 final errors = <Message>[]; |
| 524 final input = r''' | 525 final input = r''' |
| 525 @mixin a { | 526 @mixin a { |
| 526 @include b; | 527 @include b; |
| 527 } | 528 } |
| 528 @mixin b { | 529 @mixin b { |
| 529 border: 2px dashed red; | 530 border: 2px dashed red; |
| 530 @include a; | 531 @include a; |
| 531 } | 532 } |
| 532 div { | 533 div { |
| 533 @include b; | 534 @include b; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 | 572 |
| 572 foo { | 573 foo { |
| 573 @include a; | 574 @include a; |
| 574 @include a | 575 @include a |
| 575 } | 576 } |
| 576 ''', r'''foo { | 577 ''', r'''foo { |
| 577 color: #f00; | 578 color: #f00; |
| 578 color: #f00; | 579 color: #f00; |
| 579 }'''); | 580 }'''); |
| 580 | 581 |
| 581 var errors = []; | 582 var errors = <Message>[]; |
| 582 var input = r''' | 583 var input = r''' |
| 583 @mixin a { | 584 @mixin a { |
| 584 foo { color: red } | 585 foo { color: red } |
| 585 } | 586 } |
| 586 | 587 |
| 587 @mixin b { | 588 @mixin b { |
| 588 @include a | 589 @include a |
| 589 @include a | 590 @include a |
| 590 } | 591 } |
| 591 | 592 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 test('multiple args and var decls as args', mixinManyArgs); | 651 test('multiple args and var decls as args', mixinManyArgs); |
| 651 }); | 652 }); |
| 652 | 653 |
| 653 group('Mixin warnings', () { | 654 group('Mixin warnings', () { |
| 654 test('undefined top-level', undefinedTopLevel); | 655 test('undefined top-level', undefinedTopLevel); |
| 655 test('undefined declaration', undefinedDeclaration); | 656 test('undefined declaration', undefinedDeclaration); |
| 656 test('detect bad top-level as declaration', badDeclarationInclude); | 657 test('detect bad top-level as declaration', badDeclarationInclude); |
| 657 test('detect bad declaration as top-level', badTopInclude); | 658 test('detect bad declaration as top-level', badTopInclude); |
| 658 }); | 659 }); |
| 659 } | 660 } |
| OLD | NEW |