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

Side by Side Diff: tests/html/element_test.dart

Issue 10600010: Revert "Split classes test from html/element_test" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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
« no previous file with comments | « tests/html/element_classes_test.dart ('k') | tests/html/html.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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('ElementTest'); 5 #library('ElementTest');
6 #import('../../lib/unittest/unittest.dart'); 6 #import('../../lib/unittest/unittest.dart');
7 #import('../../lib/unittest/html_config.dart'); 7 #import('../../lib/unittest/html_config.dart');
8 #import('dart:html'); 8 #import('dart:html');
9 9
10 expectLargeRect(ClientRect rect) { 10 expectLargeRect(ClientRect rect) {
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 Expect.isTrue(filtered is ElementList); 742 Expect.isTrue(filtered is ElementList);
743 }); 743 });
744 744
745 test('getRange', () { 745 test('getRange', () {
746 var range = makeElList().getRange(1, 2); 746 var range = makeElList().getRange(1, 2);
747 Expect.isTrue(range is ElementList); 747 Expect.isTrue(range is ElementList);
748 Expect.isTrue(range[0] is ImageElement); 748 Expect.isTrue(range[0] is ImageElement);
749 Expect.isTrue(range[1] is InputElement); 749 Expect.isTrue(range[1] is InputElement);
750 }); 750 });
751 }); 751 });
752
753 group('classes', () {
754 Element makeElementWithClasses() =>
755 new Element.html('<div class="foo bar baz"></div>');
756
757 Set<String> makeClassSet() => makeElementWithClasses().classes;
758
759 Set<String> extractClasses(Element el) {
760 final match = new RegExp('class="([^"]+)"').firstMatch(el.outerHTML);
761 return new Set.from(match[1].split(' '));
762 }
763
764 test('affects the "class" attribute', () {
765 final el = makeElementWithClasses();
766 el.classes.add('qux');
767 Expect.setEquals(['foo', 'bar', 'baz', 'qux'], extractClasses(el));
768 });
769
770 test('is affected by the "class" attribute', () {
771 final el = makeElementWithClasses();
772 el.attributes['class'] = 'foo qux';
773 Expect.setEquals(['foo', 'qux'], el.classes);
774 });
775
776 test('classes=', () {
777 final el = makeElementWithClasses();
778 el.classes = ['foo', 'qux'];
779 Expect.setEquals(['foo', 'qux'], el.classes);
780 Expect.setEquals(['foo', 'qux'], extractClasses(el));
781 });
782
783 test('toString', () {
784 Expect.setEquals(['foo', 'bar', 'baz'],
785 makeClassSet().toString().split(' '));
786 Expect.equals('', makeElement().classes.toString());
787 });
788
789 test('forEach', () {
790 final classes = <String>[];
791 makeClassSet().forEach(classes.add);
792 Expect.setEquals(['foo', 'bar', 'baz'], classes);
793 });
794
795 test('iterator', () {
796 final classes = <String>[];
797 for (var el in makeClassSet()) {
798 classes.add(el);
799 }
800 Expect.setEquals(['foo', 'bar', 'baz'], classes);
801 });
802
803 test('map', () {
804 Expect.setEquals(['FOO', 'BAR', 'BAZ'],
805 makeClassSet().map((c) => c.toUpperCase()));
806 });
807
808 test('filter', () {
809 Expect.setEquals(['bar', 'baz'],
810 makeClassSet().filter((c) => c.contains('a')));
811 });
812
813 test('every', () {
814 Expect.isTrue(makeClassSet().every((c) => c is String));
815 Expect.isFalse(
816 makeClassSet().every((c) => c.contains('a')));
817 });
818
819 test('some', () {
820 Expect.isTrue(
821 makeClassSet().some((c) => c.contains('a')));
822 Expect.isFalse(makeClassSet().some((c) => c is num));
823 });
824
825 test('isEmpty', () {
826 Expect.isFalse(makeClassSet().isEmpty());
827 Expect.isTrue(makeElement().classes.isEmpty());
828 });
829
830 test('length', () {
831 Expect.equals(3, makeClassSet().length);
832 Expect.equals(0, makeElement().classes.length);
833 });
834
835 test('contains', () {
836 Expect.isTrue(makeClassSet().contains('foo'));
837 Expect.isFalse(makeClassSet().contains('qux'));
838 });
839
840 test('add', () {
841 final classes = makeClassSet();
842 classes.add('qux');
843 Expect.setEquals(['foo', 'bar', 'baz', 'qux'], classes);
844
845 classes.add('qux');
846 final list = new List.from(classes);
847 list.sort((a, b) => a.compareTo(b));
848 Expect.listEquals(['bar', 'baz', 'foo', 'qux'], list,
849 "The class set shouldn't have duplicate elements.");
850 });
851
852 test('remove', () {
853 final classes = makeClassSet();
854 classes.remove('bar');
855 Expect.setEquals(['foo', 'baz'], classes);
856 classes.remove('qux');
857 Expect.setEquals(['foo', 'baz'], classes);
858 });
859
860 test('addAll', () {
861 final classes = makeClassSet();
862 classes.addAll(['bar', 'qux', 'bip']);
863 Expect.setEquals(['foo', 'bar', 'baz', 'qux', 'bip'], classes);
864 });
865
866 test('removeAll', () {
867 final classes = makeClassSet();
868 classes.removeAll(['bar', 'baz', 'qux']);
869 Expect.setEquals(['foo'], classes);
870 });
871
872 test('isSubsetOf', () {
873 final classes = makeClassSet();
874 Expect.isTrue(classes.isSubsetOf(['foo', 'bar', 'baz']));
875 Expect.isTrue(classes.isSubsetOf(['foo', 'bar', 'baz', 'qux']));
876 Expect.isFalse(classes.isSubsetOf(['foo', 'bar', 'qux']));
877 });
878
879 test('containsAll', () {
880 final classes = makeClassSet();
881 Expect.isTrue(classes.containsAll(['foo', 'baz']));
882 Expect.isFalse(classes.containsAll(['foo', 'qux']));
883 });
884
885 test('intersection', () {
886 final classes = makeClassSet();
887 Expect.setEquals(['foo', 'baz'],
888 classes.intersection(['foo', 'qux', 'baz']));
889 });
890
891 test('clear', () {
892 final classes = makeClassSet();
893 classes.clear();
894 Expect.setEquals([], classes);
895 });
896 });
752 } 897 }
OLDNEW
« no previous file with comments | « tests/html/element_classes_test.dart ('k') | tests/html/html.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698