OLD | NEW |
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 XMLDocumentTest; | 5 library XMLDocumentTest; |
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() { |
(...skipping 23 matching lines...) Expand all Loading... |
34 test('with a PARSERERROR tag', () { | 34 test('with a PARSERERROR tag', () { |
35 final doc = new XMLDocument.xml("<xml><parsererror /></xml>"); | 35 final doc = new XMLDocument.xml("<xml><parsererror /></xml>"); |
36 expect(doc.children[0].tagName, 'parsererror'); | 36 expect(doc.children[0].tagName, 'parsererror'); |
37 }); | 37 }); |
38 }); | 38 }); |
39 | 39 |
40 // FilteredElementList is tested more thoroughly in DocumentFragmentTests. | 40 // FilteredElementList is tested more thoroughly in DocumentFragmentTests. |
41 group('children', () { | 41 group('children', () { |
42 test('filters out non-element nodes', () { | 42 test('filters out non-element nodes', () { |
43 final doc = new XMLDocument.xml("<xml>1<a/><b/>2<c/>3<d/></xml>"); | 43 final doc = new XMLDocument.xml("<xml>1<a/><b/>2<c/>3<d/></xml>"); |
44 expect(doc.children.map((e) => e.tagName), ["a", "b", "c", "d"]); | 44 expect(doc.children.mappedBy((e) => e.tagName).toList(), |
| 45 ["a", "b", "c", "d"]); |
45 }); | 46 }); |
46 | 47 |
47 test('overwrites nodes when set', () { | 48 test('overwrites nodes when set', () { |
48 final doc = new XMLDocument.xml("<xml>1<a/><b/>2<c/>3<d/></xml>"); | 49 final doc = new XMLDocument.xml("<xml>1<a/><b/>2<c/>3<d/></xml>"); |
49 doc.children = [new XMLElement.tag('x'), new XMLElement.tag('y')]; | 50 doc.children = [new XMLElement.tag('x'), new XMLElement.tag('y')]; |
50 expect(doc.outerHtml, "<xml><x></x><y></y></xml>"); | 51 expect(doc.outerHtml, "<xml><x></x><y></y></xml>"); |
51 }); | 52 }); |
52 }); | 53 }); |
53 | 54 |
54 group('classes', () { | 55 group('classes', () { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 }); | 95 }); |
95 | 96 |
96 test('iterator', () { | 97 test('iterator', () { |
97 final classes = <String>[]; | 98 final classes = <String>[]; |
98 for (var doc in makeClassSet()) { | 99 for (var doc in makeClassSet()) { |
99 classes.add(doc); | 100 classes.add(doc); |
100 } | 101 } |
101 expect(classes, unorderedEquals(['foo', 'bar', 'baz'])); | 102 expect(classes, unorderedEquals(['foo', 'bar', 'baz'])); |
102 }); | 103 }); |
103 | 104 |
104 test('map', () { | 105 test('mappedBy', () { |
105 expect(makeClassSet().map((c) => c.toUpperCase()), | 106 expect(makeClassSet().mappedBy((c) => c.toUpperCase()).toList(), |
106 unorderedEquals(['FOO', 'BAR', 'BAZ'])); | 107 unorderedEquals(['FOO', 'BAR', 'BAZ'])); |
107 }); | 108 }); |
108 | 109 |
109 test('filter', () { | 110 test('where', () { |
110 expect(makeClassSet().filter((c) => c.contains('a')), | 111 expect(makeClassSet().where((c) => c.contains('a')).toSet(), |
111 unorderedEquals(['bar', 'baz'])); | 112 unorderedEquals(['bar', 'baz'])); |
112 }); | 113 }); |
113 | 114 |
114 test('every', () { | 115 test('every', () { |
115 expect(makeClassSet().every((c) => c is String), isTrue); | 116 expect(makeClassSet().every((c) => c is String), isTrue); |
116 expect(makeClassSet().every((c) => c.contains('a')), isFalse); | 117 expect(makeClassSet().every((c) => c.contains('a')), isFalse); |
117 }); | 118 }); |
118 | 119 |
119 test('some', () { | 120 test('any', () { |
120 expect(makeClassSet().some((c) => c.contains('a')), isTrue); | 121 expect(makeClassSet().any((c) => c.contains('a')), isTrue); |
121 expect(makeClassSet().some((c) => c is num), isFalse); | 122 expect(makeClassSet().any((c) => c is num), isFalse); |
122 }); | 123 }); |
123 | 124 |
124 test('isEmpty', () { | 125 test('isEmpty', () { |
125 expect(makeClassSet().isEmpty, isFalse); | 126 expect(makeClassSet().isEmpty, isFalse); |
126 expect(makeDocument().classes.isEmpty, isTrue); | 127 expect(makeDocument().classes.isEmpty, isTrue); |
127 }); | 128 }); |
128 | 129 |
129 test('length', () { | 130 test('length', () { |
130 expect(makeClassSet().length, 3); | 131 expect(makeClassSet().length, 3); |
131 expect(makeDocument().classes.length, 0); | 132 expect(makeDocument().classes.length, 0); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 421 |
421 test('query', () { | 422 test('query', () { |
422 final doc = makeDocument(); | 423 final doc = makeDocument(); |
423 expect(doc.query('foo').tagName, 'foo'); | 424 expect(doc.query('foo').tagName, 'foo'); |
424 expect(doc.query('baz'), isNull); | 425 expect(doc.query('baz'), isNull); |
425 }); | 426 }); |
426 | 427 |
427 test('queryAll', () { | 428 test('queryAll', () { |
428 final doc = new XMLDocument.xml( | 429 final doc = new XMLDocument.xml( |
429 "<xml><foo id='f1' /><bar><foo id='f2' /></bar></xml>"); | 430 "<xml><foo id='f1' /><bar><foo id='f2' /></bar></xml>"); |
430 expect(doc.queryAll('foo').map((e) => e.id), ['f1', 'f2']); | 431 expect(doc.queryAll('foo').mappedBy((e) => e.id).toList(), ['f1', 'f2']); |
431 expect(doc.queryAll('baz'), []); | 432 expect(doc.queryAll('baz'), []); |
432 }); | 433 }); |
433 | 434 |
434 // TODO(nweiz): re-enable this when matchesSelector works cross-browser. | 435 // TODO(nweiz): re-enable this when matchesSelector works cross-browser. |
435 // | 436 // |
436 // test('matchesSelector', () { | 437 // test('matchesSelector', () { |
437 // final doc = makeDocument(); | 438 // final doc = makeDocument(); |
438 // expect(doc.matchesSelector('*'), isTrue); | 439 // expect(doc.matchesSelector('*'), isTrue); |
439 // expect(doc.matchesSelector('xml'), isTrue); | 440 // expect(doc.matchesSelector('xml'), isTrue); |
440 // expect(doc.matchesSelector('html'), isFalse); | 441 // expect(doc.matchesSelector('html'), isFalse); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 test('manifest', () => expect(makeDocument().manifest), ''); | 612 test('manifest', () => expect(makeDocument().manifest), ''); |
612 }); | 613 }); |
613 | 614 |
614 test('unsupported operations', () { | 615 test('unsupported operations', () { |
615 expectUnsupported(() { makeDocument().body = new XMLElement.tag('xml'); }); | 616 expectUnsupported(() { makeDocument().body = new XMLElement.tag('xml'); }); |
616 expectUnsupported(() => makeDocument().cookie); | 617 expectUnsupported(() => makeDocument().cookie); |
617 expectUnsupported(() { makeDocument().cookie = 'foo'; }); | 618 expectUnsupported(() { makeDocument().cookie = 'foo'; }); |
618 expectUnsupported(() { makeDocument().manifest = 'foo'; }); | 619 expectUnsupported(() { makeDocument().manifest = 'foo'; }); |
619 }); | 620 }); |
620 } | 621 } |
OLD | NEW |