Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: pkg/csslib/test/compiler_test.dart

Issue 23576012: Added .scss transform (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cleanup Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 compiler_test; 5 library compiler_test;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 import 'package:csslib/parser.dart'; 9 import 'package:csslib/parser.dart';
10 import 'package:csslib/visitor.dart'; 10 import 'package:csslib/visitor.dart';
11 import 'testing.dart'; 11 import 'testing.dart';
12 12
13 /** Test List<int> as input to parser. */
14 void testArrayOfChars() {
15 var errors = [];
16 var input = '<![CDATA[.foo { '
17 'color: red; left: 20px; top: 20px; width: 100px; height:200px'
18 '}'
19 '#div {'
20 'color : #00F578; border-color: #878787;'
21 '}]]>';
22
23 var stylesheet = parse(UTF8.encode(input), errors: errors);
24
25 expect(stylesheet != null, true);
26 expect(errors.isEmpty, true, reason: errors.toString());
27
28 expect(prettyPrint(stylesheet), r'''
29 .foo {
30 color: #f00;
31 left: 20px;
32 top: 20px;
33 width: 100px;
34 height: 200px;
35 }
36 #div {
37 color: #00F578;
38 border-color: #878787;
39 }''');
40 }
41
13 void testClass() { 42 void testClass() {
14 var errors = []; 43 var errors = [];
15 var input = ".foobar {}"; 44 var input = ".foobar {}";
16 var stylesheet = parseCss(input, errors: errors); 45 var stylesheet = parseCss(input, errors: errors);
17 46
18 expect(stylesheet != null, true); 47 expect(stylesheet != null, true);
19 expect(errors.isEmpty, true, reason: errors.toString()); 48 expect(errors.isEmpty, true, reason: errors.toString());
20 49
21 walkTree(stylesheet); 50 walkTree(stylesheet);
22 51
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 expect(elementSelector.isWildcard, true); 533 expect(elementSelector.isWildcard, true);
505 expect("*", elementSelector.name); 534 expect("*", elementSelector.name);
506 535
507 selector1 = simpleSeqs[1]; 536 selector1 = simpleSeqs[1];
508 simpleSelector1 = selector1.simpleSelector; 537 simpleSelector1 = selector1.simpleSelector;
509 expect(simpleSelector1 is ClassSelector, true); 538 expect(simpleSelector1 is ClassSelector, true);
510 expect(selector1.isCombinatorNone, true); 539 expect(selector1.isCombinatorNone, true);
511 expect("foobar", simpleSelector1.name); 540 expect("foobar", simpleSelector1.name);
512 } 541 }
513 542
514 /** Test List<int> as input to parser. */
515 void testArrayOfChars() {
516 var errors = [];
517 var input = '<![CDATA[.foo { '
518 'color: red; left: 20px; top: 20px; width: 100px; height:200px'
519 '}'
520 '#div {'
521 'color : #00F578; border-color: #878787;'
522 '}]]>';
523
524 var stylesheet = parse(UTF8.encode(input), errors: errors);
525
526 expect(stylesheet != null, true);
527 expect(errors.isEmpty, true, reason: errors.toString());
528
529 expect(prettyPrint(stylesheet), r'''
530 .foo {
531 color: #f00;
532 left: 20px;
533 top: 20px;
534 width: 100px;
535 height: 200px;
536 }
537 #div {
538 color: #00F578;
539 border-color: #878787;
540 }''');
541 }
542
543 void testPseudo() {
544 var errors = [];
545
546 final input = r'''
547 html:lang(fr-ca) { quotes: '" ' ' "' }
548 zoom: { }
549
550 a:link { color: red }
551 :link { color: blue }
552
553 a:focus { background: yellow }
554 a:focus:hover { background: white }
555
556 p.special:first-letter {color: #ffd800}
557
558 p:not(#example){
559 background-color: yellow;
560 }
561
562 input:not([DISABLED]){
563 background-color: yellow;
564 }
565
566 html|*:not(:link):not(:visited) {
567 border: 1px solid black;
568 }
569
570 *:not(FOO) {
571 height: 20px;
572 }
573
574 *|*:not(*) {
575 color: orange;
576 }
577
578 *|*:not(:hover) {
579 color: magenta;
580 }
581
582 p:nth-child(3n-3) { }
583
584 div:nth-child(2n) { color : red; }
585 ''';
586
587 var stylesheet = parseCss(input, errors: errors,
588 opts: ['--no-colors', 'memory']);
589
590 expect(stylesheet != null, true);
591 expect(errors.isEmpty, true, reason: errors.toString());
592 expect(prettyPrint(stylesheet), r'''
593 html:lang(fr-ca) {
594 quotes: "\" " " \"";
595 }
596 zoom {
597 }
598 a:link {
599 color: #f00;
600 }
601 :link {
602 color: #00f;
603 }
604 a:focus {
605 background: #ff0;
606 }
607 a:focus:hover {
608 background: #fff;
609 }
610 p.special:first-letter {
611 color: #ffd800;
612 }
613 p:not(#example) {
614 background-color: #ff0;
615 }
616 input:not([DISABLED]) {
617 background-color: #ff0;
618 }
619 html|*:not(:link):not(:visited) {
620 border: 1px solid #000;
621 }
622 *:not(FOO) {
623 height: 20px;
624 }
625 *|*:not(*) {
626 color: #ffa500;
627 }
628 *|*:not(:hover) {
629 color: #f0f;
630 }
631 p:nth-child(3n-3) {
632 }
633 div:nth-child(2n) {
634 color: #f00;
635 }''');
636 }
637
638 void testAttribute() {
639 // TODO(terry): Implement
640 }
641
642 void testNegation() {
643 // TODO(terry): Implement
644 }
645
646 void testHost() {
647 var errors = [];
648 var input = '@host { '
649 ':scope {'
650 'white-space: nowrap;'
651 'overflow-style: marquee-line;'
652 'overflow-x: marquee;'
653 '}'
654 '* { color: red; }'
655 '*:hover { font-weight: bold; }'
656 ':nth-child(odd) { color: blue; }'
657 '}';
658 var stylesheet = parseCss(input, errors: errors,
659 opts: ['--no-colors', 'memory']);
660
661 expect(stylesheet != null, true);
662 expect(errors.isEmpty, true, reason: errors.toString());
663 expect(prettyPrint(stylesheet), r'''
664 @host {
665 :scope {
666 white-space: nowrap;
667 overflow-style: marquee-line;
668 overflow-x: marquee;
669 }
670 * {
671 color: #f00;
672 }
673 *:hover {
674 font-weight: bold;
675 }
676 :nth-child(odd) {
677 color: #00f;
678 }
679 }''');
680 }
681
682 // TODO(terry): Move to emitter_test.dart when real emitter exist.
683 void testEmitter() {
684 var errors = [];
685 var input = '.foo { '
686 'color: red; left: 20px; top: 20px; width: 100px; height:200px'
687 '}'
688 '#div {'
689 'color : #00F578; border-color: #878787;'
690 '}';
691 var stylesheet = parseCss(input, errors: errors);
692
693 expect(stylesheet != null, true);
694 expect(errors.isEmpty, true, reason: errors.toString());
695
696 walkTree(stylesheet);
697
698 expect(prettyPrint(stylesheet), r'''
699 .foo {
700 color: #f00;
701 left: 20px;
702 top: 20px;
703 width: 100px;
704 height: 200px;
705 }
706 #div {
707 color: #00F578;
708 border-color: #878787;
709 }''');
710 }
711
712 main() { 543 main() {
713 test('Classes', testClass); 544 test('Classes', testClass);
714 test('Classes 2', testClass2); 545 test('Classes 2', testClass2);
715 test('Ids', testId); 546 test('Ids', testId);
716 test('Elements', testElement); 547 test('Elements', testElement);
717 test('Namespace', testNamespace); 548 test('Namespace', testNamespace);
718 test('Namespace 2', testNamespace2); 549 test('Namespace 2', testNamespace2);
719 test('Selector Groups', testSelectorGroups); 550 test('Selector Groups', testSelectorGroups);
720 test('Combinator', testCombinator); 551 test('Combinator', testCombinator);
721 test('Wildcards', testWildcard); 552 test('Wildcards', testWildcard);
722 test('Pseudo', testPseudo);
723 test('Attributes', testAttribute);
724 test('Negation', testNegation);
725 test('@host', testHost);
726 test('Parse List<int> as input', testArrayOfChars); 553 test('Parse List<int> as input', testArrayOfChars);
727 test('Simple Emitter', testEmitter);
728 } 554 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698