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 var_test; | 5 library var_test; |
6 | 6 |
7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 import 'testing.dart'; | 8 import 'testing.dart'; |
9 | 9 |
10 List options = ['--no-colors', '--warnings_as_errors', 'memory']; | 10 List options = ['--no-colors', '--warnings_as_errors', 'memory']; |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 .test-1 { | 386 .test-1 { |
387 color: #0f0; | 387 color: #0f0; |
388 } | 388 } |
389 .test-2 { | 389 .test-2 { |
390 color: ; | 390 color: ; |
391 background: ; | 391 background: ; |
392 }'''; | 392 }'''; |
393 | 393 |
394 var errorStrings = [ | 394 var errorStrings = [ |
395 'error on line 5, column 14: Variable is not defined.\n' | 395 'error on line 5, column 14: Variable is not defined.\n' |
396 ' var-a: var(b);\n' | 396 ' var-a: var(b);\n' |
397 ' ^^', | 397 ' ^^', |
398 'error on line 6, column 14: Variable is not defined.\n' | 398 'error on line 6, column 14: Variable is not defined.\n' |
399 ' var-b: var(c);\n' | 399 ' var-b: var(c);\n' |
400 ' ^^', | 400 ' ^^', |
401 'error on line 9, column 16: Variable is not defined.\n' | 401 'error on line 9, column 16: Variable is not defined.\n' |
402 ' var-one: var(two);\n' | 402 ' var-one: var(two);\n' |
403 ' ^^^^', | 403 ' ^^^^', |
404 'error on line 12, column 17: Variable is not defined.\n' | 404 'error on line 12, column 17: Variable is not defined.\n' |
405 ' var-four: var(five);\n' | 405 ' var-four: var(five);\n' |
406 ' ^^^^^', | 406 ' ^^^^^', |
407 'error on line 13, column 17: Variable is not defined.\n' | 407 'error on line 13, column 17: Variable is not defined.\n' |
408 ' var-five: var(six);\n' | 408 ' var-five: var(six);\n' |
409 ' ^^^^', | 409 ' ^^^^', |
410 'error on line 16, column 18: Variable is not defined.\n' | 410 'error on line 16, column 18: Variable is not defined.\n' |
411 ' var-def-1: var(def-2);\n' | 411 ' var-def-1: var(def-2);\n' |
412 ' ^^^^^^', | 412 ' ^^^^^^', |
413 'error on line 17, column 18: Variable is not defined.\n' | 413 'error on line 17, column 18: Variable is not defined.\n' |
414 ' var-def-2: var(def-3);\n' | 414 ' var-def-2: var(def-3);\n' |
415 ' ^^^^^^', | 415 ' ^^^^^^', |
416 ]; | 416 ]; |
417 | 417 |
418 var generated = r''':root { | 418 var generated = r''':root { |
419 var-color-background: #f00; | 419 var-color-background: #f00; |
420 var-color-foreground: #00f; | 420 var-color-foreground: #00f; |
421 var-a: var(b); | 421 var-a: var(b); |
422 var-b: var(c); | 422 var-b: var(c); |
423 var-c: #0f0; | 423 var-c: #0f0; |
424 var-one: var(two); | 424 var-one: var(two); |
425 var-two: var(one); | 425 var-two: var(one); |
426 var-four: var(five); | 426 var-four: var(five); |
(...skipping 11 matching lines...) Expand all Loading... |
438 color: var(c); | 438 color: var(c); |
439 } | 439 } |
440 .test-2 { | 440 .test-2 { |
441 color: var(one); | 441 color: var(one); |
442 background: var(six); | 442 background: var(six); |
443 }'''; | 443 }'''; |
444 int testBitMap = 0; | 444 int testBitMap = 0; |
445 | 445 |
446 compileAndValidate(input, generated); | 446 compileAndValidate(input, generated); |
447 | 447 |
448 var stylesheet = polyFillCompileCss(input, errors: errors..clear(), | 448 var stylesheet = |
449 opts: options); | 449 polyFillCompileCss(input, errors: errors..clear(), opts: options); |
450 | 450 |
451 expect(stylesheet != null, true); | 451 expect(stylesheet != null, true); |
452 | 452 |
453 expect(errors.length, errorStrings.length, reason: errors.toString()); | 453 expect(errors.length, errorStrings.length, reason: errors.toString()); |
454 testBitMap = 0; | 454 testBitMap = 0; |
455 | 455 |
456 outer: for (var error in errors) { | 456 outer: for (var error in errors) { |
457 var errorString = error.toString(); | 457 var errorString = error.toString(); |
458 for (int i = 0; i < errorStrings.length; i++) { | 458 for (int i = 0; i < errorStrings.length; i++) { |
459 if (errorString == errorStrings[i]) { | 459 if (errorString == errorStrings[i]) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 '''; | 637 '''; |
638 final generated = ''' | 638 final generated = ''' |
639 var-color-background: #f00; | 639 var-color-background: #f00; |
640 var-color-foreground: #00f; | 640 var-color-foreground: #00f; |
641 | 641 |
642 .test { | 642 .test { |
643 background-color: var(color-background); | 643 background-color: var(color-background); |
644 color: var(color-foreground); | 644 color: var(color-foreground); |
645 }'''; | 645 }'''; |
646 | 646 |
647 var stylesheet = parseCss(input, errors: errors, | 647 var stylesheet = |
648 opts: ['--no-colors', 'memory']); | 648 parseCss(input, errors: errors, opts: ['--no-colors', 'memory']); |
649 | 649 |
650 expect(stylesheet != null, true); | 650 expect(stylesheet != null, true); |
651 expect(errors.isEmpty, true, reason: errors.toString()); | 651 expect(errors.isEmpty, true, reason: errors.toString()); |
652 expect(prettyPrint(stylesheet), generated); | 652 expect(prettyPrint(stylesheet), generated); |
653 | 653 |
654 compileAndValidate(input, generated); | 654 compileAndValidate(input, generated); |
655 | 655 |
656 final input2 = ''' | 656 final input2 = ''' |
657 @color-background: red; | 657 @color-background: red; |
658 @color-foreground: blue; | 658 @color-foreground: blue; |
659 | 659 |
660 .test { | 660 .test { |
661 background-color: @color-background; | 661 background-color: @color-background; |
662 color: @color-foreground; | 662 color: @color-foreground; |
663 } | 663 } |
664 '''; | 664 '''; |
665 final generated2 = '''var-color-background: #f00; | 665 final generated2 = '''var-color-background: #f00; |
666 var-color-foreground: #00f; | 666 var-color-foreground: #00f; |
667 | 667 |
668 .test { | 668 .test { |
669 background-color: var(color-background); | 669 background-color: var(color-background); |
670 color: var(color-foreground); | 670 color: var(color-foreground); |
671 }'''; | 671 }'''; |
672 | 672 |
673 stylesheet = parseCss(input, errors: errors..clear(), | 673 stylesheet = |
674 opts: ['--no-colors', 'memory']); | 674 parseCss(input, errors: errors..clear(), opts: ['--no-colors', 'memory']); |
675 | 675 |
676 expect(stylesheet != null, true); | 676 expect(stylesheet != null, true); |
677 expect(errors.isEmpty, true, reason: errors.toString()); | 677 expect(errors.isEmpty, true, reason: errors.toString()); |
678 expect(prettyPrint(stylesheet), generated2); | 678 expect(prettyPrint(stylesheet), generated2); |
679 | 679 |
680 compileAndValidate(input2, generated2); | 680 compileAndValidate(input2, generated2); |
681 } | 681 } |
682 | 682 |
683 testLess() { | 683 testLess() { |
684 final errors = []; | 684 final errors = []; |
685 final input = ''' | 685 final input = ''' |
686 @color-background: red; | 686 @color-background: red; |
687 @color-foreground: blue; | 687 @color-foreground: blue; |
688 | 688 |
689 .test { | 689 .test { |
690 background-color: var(color-background); | 690 background-color: var(color-background); |
691 color: var(color-foreground); | 691 color: var(color-foreground); |
692 } | 692 } |
693 '''; | 693 '''; |
694 final generated = '''var-color-background: #f00; | 694 final generated = '''var-color-background: #f00; |
695 var-color-foreground: #00f; | 695 var-color-foreground: #00f; |
696 | 696 |
697 .test { | 697 .test { |
698 background-color: var(color-background); | 698 background-color: var(color-background); |
699 color: var(color-foreground); | 699 color: var(color-foreground); |
700 }'''; | 700 }'''; |
701 | 701 |
702 var stylesheet = parseCss(input, errors: errors, | 702 var stylesheet = |
703 opts: ['--no-colors', 'memory']); | 703 parseCss(input, errors: errors, opts: ['--no-colors', 'memory']); |
704 | 704 |
705 expect(stylesheet != null, true); | 705 expect(stylesheet != null, true); |
706 expect(errors.isEmpty, true, reason: errors.toString()); | 706 expect(errors.isEmpty, true, reason: errors.toString()); |
707 expect(prettyPrint(stylesheet), generated); | 707 expect(prettyPrint(stylesheet), generated); |
708 | 708 |
709 compileAndValidate(input, generated); | 709 compileAndValidate(input, generated); |
710 | 710 |
711 final input2 = ''' | 711 final input2 = ''' |
712 @color-background: red; | 712 @color-background: red; |
713 @color-foreground: blue; | 713 @color-foreground: blue; |
714 | 714 |
715 .test { | 715 .test { |
716 background-color: @color-background; | 716 background-color: @color-background; |
717 color: @color-foreground; | 717 color: @color-foreground; |
718 } | 718 } |
719 '''; | 719 '''; |
720 final generated2 = '''var-color-background: #f00; | 720 final generated2 = '''var-color-background: #f00; |
721 var-color-foreground: #00f; | 721 var-color-foreground: #00f; |
722 | 722 |
723 .test { | 723 .test { |
724 background-color: var(color-background); | 724 background-color: var(color-background); |
725 color: var(color-foreground); | 725 color: var(color-foreground); |
726 }'''; | 726 }'''; |
727 | 727 |
728 stylesheet = parseCss(input, errors: errors..clear(), | 728 stylesheet = |
729 opts: ['--no-colors', 'memory']); | 729 parseCss(input, errors: errors..clear(), opts: ['--no-colors', 'memory']); |
730 | 730 |
731 expect(stylesheet != null, true); | 731 expect(stylesheet != null, true); |
732 expect(errors.isEmpty, true, reason: errors.toString()); | 732 expect(errors.isEmpty, true, reason: errors.toString()); |
733 expect(prettyPrint(stylesheet), generated2); | 733 expect(prettyPrint(stylesheet), generated2); |
734 | 734 |
735 compileAndValidate(input2, generated2); | 735 compileAndValidate(input2, generated2); |
736 } | 736 } |
737 | 737 |
738 void polyfill() { | 738 void polyfill() { |
739 compilePolyfillAndValidate(r''' | 739 compilePolyfillAndValidate(r''' |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 var generated2 = r''':root { | 847 var generated2 = r''':root { |
848 var-redef: #0b0; | 848 var-redef: #0b0; |
849 var-b3: var(a3); | 849 var-b3: var(a3); |
850 } | 850 } |
851 .test-2 { | 851 .test-2 { |
852 color: var(b3); | 852 color: var(b3); |
853 background-color: var(redef); | 853 background-color: var(redef); |
854 border-color: var(a3); | 854 border-color: var(a3); |
855 }'''; | 855 }'''; |
856 | 856 |
857 var stylesheet2 = compileCss(file2Input, includes: [stylesheet1], | 857 var stylesheet2 = compileCss(file2Input, |
858 errors: errors..clear(), opts: options); | 858 includes: [stylesheet1], errors: errors..clear(), opts: options); |
859 expect(stylesheet2 != null, true); | 859 expect(stylesheet2 != null, true); |
860 expect(errors.isEmpty, true, reason: errors.toString()); | 860 expect(errors.isEmpty, true, reason: errors.toString()); |
861 expect(prettyPrint(stylesheet2), generated2); | 861 expect(prettyPrint(stylesheet2), generated2); |
862 | 862 |
863 var generatedPolyfill1 = r''':root { | 863 var generatedPolyfill1 = r''':root { |
864 } | 864 } |
865 .test-1 { | 865 .test-1 { |
866 background-color: #fff; | 866 background-color: #fff; |
867 color: #fff; | 867 color: #fff; |
868 border-color: #fff; | 868 border-color: #fff; |
869 } | 869 } |
870 .test-1a { | 870 .test-1a { |
871 color: #000; | 871 color: #000; |
872 }'''; | 872 }'''; |
873 var styleSheet1Polyfill = compileCss(file1Input, errors: errors..clear(), | 873 var styleSheet1Polyfill = compileCss(file1Input, |
874 polyfill: true, opts: options); | 874 errors: errors..clear(), polyfill: true, opts: options); |
875 expect(styleSheet1Polyfill != null, true); | 875 expect(styleSheet1Polyfill != null, true); |
876 expect(errors.isEmpty, true, reason: errors.toString()); | 876 expect(errors.isEmpty, true, reason: errors.toString()); |
877 expect(prettyPrint(styleSheet1Polyfill), generatedPolyfill1); | 877 expect(prettyPrint(styleSheet1Polyfill), generatedPolyfill1); |
878 | 878 |
879 var generatedPolyfill2 = r''':root { | 879 var generatedPolyfill2 = r''':root { |
880 } | 880 } |
881 .test-2 { | 881 .test-2 { |
882 color: #fff; | 882 color: #fff; |
883 background-color: #0b0; | 883 background-color: #0b0; |
884 border-color: #fff; | 884 border-color: #fff; |
885 }'''; | 885 }'''; |
886 var styleSheet2Polyfill = compileCss(file2Input, includes: [stylesheet1], | 886 var styleSheet2Polyfill = compileCss(file2Input, |
887 errors: errors..clear(), polyfill: true, opts: options); | 887 includes: [stylesheet1], |
| 888 errors: errors..clear(), |
| 889 polyfill: true, |
| 890 opts: options); |
888 expect(styleSheet2Polyfill != null, true); | 891 expect(styleSheet2Polyfill != null, true); |
889 expect(errors.isEmpty, true, reason: errors.toString()); | 892 expect(errors.isEmpty, true, reason: errors.toString()); |
890 expect(prettyPrint(styleSheet2Polyfill), generatedPolyfill2); | 893 expect(prettyPrint(styleSheet2Polyfill), generatedPolyfill2); |
891 | 894 |
892 // Make sure includes didn't change. | 895 // Make sure includes didn't change. |
893 expect(prettyPrint(stylesheet1), generated1); | 896 expect(prettyPrint(stylesheet1), generated1); |
894 | 897 |
895 var generatedPolyfill = r''':root { | 898 var generatedPolyfill = r''':root { |
896 } | 899 } |
897 .test-main { | 900 .test-main { |
898 color: #fff; | 901 color: #fff; |
899 background-color: #0c0; | 902 background-color: #0c0; |
900 border-color: #fff; | 903 border-color: #fff; |
901 }'''; | 904 }'''; |
902 var stylesheetPolyfill = compileCss(input, | 905 var stylesheetPolyfill = compileCss(input, |
903 includes: [stylesheet1, stylesheet2], errors: errors..clear(), | 906 includes: [stylesheet1, stylesheet2], |
904 polyfill: true, opts: options); | 907 errors: errors..clear(), |
| 908 polyfill: true, |
| 909 opts: options); |
905 | 910 |
906 expect(stylesheetPolyfill != null, true); | 911 expect(stylesheetPolyfill != null, true); |
907 expect(errors.isEmpty, true, reason: errors.toString()); | 912 expect(errors.isEmpty, true, reason: errors.toString()); |
908 expect(prettyPrint(stylesheetPolyfill), generatedPolyfill); | 913 expect(prettyPrint(stylesheetPolyfill), generatedPolyfill); |
909 | 914 |
910 // Make sure includes didn't change. | 915 // Make sure includes didn't change. |
911 expect(prettyPrint(stylesheet1), generated1); | 916 expect(prettyPrint(stylesheet1), generated1); |
912 expect(prettyPrint(stylesheet2), generated2); | 917 expect(prettyPrint(stylesheet2), generated2); |
913 } | 918 } |
914 | 919 |
915 main() { | 920 main() { |
916 test('Simple var', simpleVar); | 921 test('Simple var', simpleVar); |
917 test('Expressions var', expressionsVar); | 922 test('Expressions var', expressionsVar); |
918 test('Default value in var()', defaultVar); | 923 test('Default value in var()', defaultVar); |
919 test('CSS Parser only var', parserVar); | 924 test('CSS Parser only var', parserVar); |
920 test('Var syntax', testVar); | 925 test('Var syntax', testVar); |
921 test('Indirects', testIndirects); | 926 test('Indirects', testIndirects); |
922 test('Forward Refs', undefinedVars); | 927 test('Forward Refs', undefinedVars); |
923 test('Less syntax', testLess); | 928 test('Less syntax', testLess); |
924 test('Polyfill', polyfill); | 929 test('Polyfill', polyfill); |
925 test('Multi-file', includes); | 930 test('Multi-file', includes); |
926 } | 931 } |
OLD | NEW |