| OLD | NEW |
| 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 '../../pkg/unittest/lib/unittest.dart'; | 6 import '../../pkg/unittest/lib/unittest.dart'; |
| 7 import '../../pkg/unittest/lib/html_config.dart'; | 7 import '../../pkg/unittest/lib/html_config.dart'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 | 9 |
| 10 main() { | 10 main() { |
| 11 useHtmlConfiguration(); | 11 useHtmlConfiguration(); |
| 12 | 12 |
| 13 Element makeElement() => new Element.tag('div'); | 13 Element makeElement() => new Element.tag('div'); |
| 14 | 14 |
| 15 Element makeElementWithChildren() => | 15 Element makeElementWithChildren() => |
| 16 new Element.html("<div><br/><img/><input/></div>"); | 16 new Element.html("<div><br/><img/><input/></div>"); |
| 17 | 17 |
| 18 Element makeElementWithClasses() => | 18 Element makeElementWithClasses() => |
| 19 new Element.html('<div class="foo bar baz"></div>'); | 19 new Element.html('<div class="foo bar baz"></div>'); |
| 20 | 20 |
| 21 Set<String> makeClassSet() => makeElementWithClasses().classes; | 21 Set<String> makeClassSet() => makeElementWithClasses().classes; |
| 22 | 22 |
| 23 Set<String> extractClasses(Element el) { | 23 Set<String> extractClasses(Element el) { |
| 24 final match = new RegExp('class="([^"]+)"').firstMatch(el.outerHTML); | 24 final match = new RegExp('class="([^"]+)"').firstMatch(el.outerHtml); |
| 25 return new Set.from(match[1].split(' ')); | 25 return new Set.from(match[1].split(' ')); |
| 26 } | 26 } |
| 27 | 27 |
| 28 test('affects the "class" attribute', () { | 28 test('affects the "class" attribute', () { |
| 29 final el = makeElementWithClasses(); | 29 final el = makeElementWithClasses(); |
| 30 el.classes.add('qux'); | 30 el.classes.add('qux'); |
| 31 expect(extractClasses(el), unorderedEquals(['foo', 'bar', 'baz', 'qux'])); | 31 expect(extractClasses(el), unorderedEquals(['foo', 'bar', 'baz', 'qux'])); |
| 32 }); | 32 }); |
| 33 | 33 |
| 34 test('is affected by the "class" attribute', () { | 34 test('is affected by the "class" attribute', () { |
| 35 final el = makeElementWithClasses(); | 35 final el = makeElementWithClasses(); |
| 36 el.attributes['class'] = 'foo qux'; | 36 el.attributes['class'] = 'foo qux'; |
| 37 expect(el.classes, unorderedEquals(['foo', 'qux'])); | 37 expect(el.classes, unorderedEquals(['foo', 'qux'])); |
| 38 }); | 38 }); |
| 39 | 39 |
| 40 test('classes=', () { | 40 test('classes=', () { |
| 41 final el = makeElementWithClasses(); | 41 final el = makeElementWithClasses(); |
| 42 el.classes = ['foo', 'qux']; | 42 el.classes = ['foo', 'qux']; |
| 43 expect(el.classes, unorderedEquals(['foo', 'qux'])); | 43 expect(el.classes, unorderedEquals(['foo', 'qux'])); |
| 44 expect(extractClasses(el), unorderedEquals(['foo', 'qux'])); | 44 expect(extractClasses(el), unorderedEquals(['foo', 'qux'])); |
| 45 }); | 45 }); |
| 46 | 46 |
| 47 test('toString', () { | 47 test('toString', () { |
| 48 expect(makeClassSet().toString().split(' '), | 48 expect(makeClassSet().toString().split(' '), |
| 49 unorderedEquals(['foo', 'bar', 'baz'])); | 49 unorderedEquals(['foo', 'bar', 'baz'])); |
| 50 expect(makeElement().classes.toString(), ''); | 50 expect(makeElement().classes.toString(), ''); |
| 51 }); | 51 }); |
| 52 | 52 |
| 53 test('forEach', () { | 53 test('forEach', () { |
| 54 final classes = <String>[]; | 54 final classes = <String>[]; |
| 55 // TODO: Change to this when Issue 3484 is fixed. | 55 // TODO: Change to this when Issue 3484 is fixed. |
| 56 // makeClassSet().forEach(classes.add); | 56 // makeClassSet().forEach(classes.add); |
| 57 makeClassSet().forEach((c) => classes.add(c)); | 57 makeClassSet().forEach((c) => classes.add(c)); |
| 58 expect(classes, unorderedEquals(['foo', 'bar', 'baz'])); | 58 expect(classes, unorderedEquals(['foo', 'bar', 'baz'])); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 expect(classes.intersection(['foo', 'qux', 'baz']), | 159 expect(classes.intersection(['foo', 'qux', 'baz']), |
| 160 unorderedEquals(['foo', 'baz'])); | 160 unorderedEquals(['foo', 'baz'])); |
| 161 }); | 161 }); |
| 162 | 162 |
| 163 test('clear', () { | 163 test('clear', () { |
| 164 final classes = makeClassSet(); | 164 final classes = makeClassSet(); |
| 165 classes.clear(); | 165 classes.clear(); |
| 166 expect(classes, equals([])); | 166 expect(classes, equals([])); |
| 167 }); | 167 }); |
| 168 } | 168 } |
| OLD | NEW |