| 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('NodeTest'); | 5 #library('NodeTest'); |
| 6 #import('../../pkg/unittest/unittest.dart'); | 6 #import('../../pkg/unittest/unittest.dart'); |
| 7 #import('../../pkg/unittest/html_config.dart'); | 7 #import('../../pkg/unittest/html_config.dart'); |
| 8 #import('dart:html'); | 8 #import('dart:html'); |
| 9 | 9 |
| 10 Node makeNode() => new Element.tag('div'); | 10 Node makeNode() => new Element.tag('div'); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 test('contains', () { | 41 test('contains', () { |
| 42 final Node node = new Element.html("<div>Foo<span>Bar</span></div>"); | 42 final Node node = new Element.html("<div>Foo<span>Bar</span></div>"); |
| 43 Expect.isTrue(node.contains(node.nodes.first)); | 43 Expect.isTrue(node.contains(node.nodes.first)); |
| 44 Expect.isTrue(node.contains(node.nodes[1].nodes.first)); | 44 Expect.isTrue(node.contains(node.nodes[1].nodes.first)); |
| 45 Expect.isFalse(node.contains(new Text('Foo'))); | 45 Expect.isFalse(node.contains(new Text('Foo'))); |
| 46 }); | 46 }); |
| 47 | 47 |
| 48 group('nodes', () { | 48 group('nodes', () { |
| 49 test('is a NodeList', () { | 49 test('is a NodeList', () { |
| 50 Expect.isTrue(makeNodeWithChildren().nodes is NodeList); | 50 Expect.isTrue(makeNodeWithChildren().nodes is List<Node>); |
| 51 }); | 51 }); |
| 52 | 52 |
| 53 test('first', () { | 53 test('first', () { |
| 54 var node = makeNodeWithChildren(); | 54 var node = makeNodeWithChildren(); |
| 55 Expect.isTrue(node.nodes.first is Text); | 55 Expect.isTrue(node.nodes.first is Text); |
| 56 }); | 56 }); |
| 57 | 57 |
| 58 test('last', () { | 58 test('last', () { |
| 59 var node = makeNodeWithChildren(); | 59 var node = makeNodeWithChildren(); |
| 60 Expect.isTrue(node.nodes.last() is Comment); | 60 Expect.isTrue(node.nodes.last() is Comment); |
| 61 }); | 61 }); |
| 62 | 62 |
| 63 test('forEach', () { | 63 test('forEach', () { |
| 64 var nodes = []; | 64 var nodes = []; |
| 65 var node = makeNodeWithChildren(); | 65 var node = makeNodeWithChildren(); |
| 66 node.nodes.forEach((n) => nodes.add(n)); | 66 node.nodes.forEach((n) => nodes.add(n)); |
| 67 Expect.isTrue(nodes[0] is Text); | 67 Expect.isTrue(nodes[0] is Text); |
| 68 Expect.isTrue(nodes[1] is BRElement); | 68 Expect.isTrue(nodes[1] is BRElement); |
| 69 Expect.isTrue(nodes[2] is Comment); | 69 Expect.isTrue(nodes[2] is Comment); |
| 70 }); | 70 }); |
| 71 | 71 |
| 72 test('filter', () { | 72 test('filter', () { |
| 73 var filtered = makeNodeWithChildren().nodes.filter((n) => n is BRElement); | 73 var filtered = makeNodeWithChildren().nodes.filter((n) => n is BRElement); |
| 74 Expect.equals(1, filtered.length); | 74 Expect.equals(1, filtered.length); |
| 75 Expect.isTrue(filtered[0] is BRElement); | 75 Expect.isTrue(filtered[0] is BRElement); |
| 76 Expect.isTrue(filtered is NodeList); | 76 Expect.isTrue(filtered is List<Node>); |
| 77 }); | 77 }); |
| 78 | 78 |
| 79 test('every', () { | 79 test('every', () { |
| 80 var node = makeNodeWithChildren(); | 80 var node = makeNodeWithChildren(); |
| 81 Expect.isTrue(node.nodes.every((n) => n is Node)); | 81 Expect.isTrue(node.nodes.every((n) => n is Node)); |
| 82 Expect.isFalse(node.nodes.every((n) => n is Comment)); | 82 Expect.isFalse(node.nodes.every((n) => n is Comment)); |
| 83 }); | 83 }); |
| 84 | 84 |
| 85 test('some', () { | 85 test('some', () { |
| 86 var node = makeNodeWithChildren(); | 86 var node = makeNodeWithChildren(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 test('removeLast', () { | 160 test('removeLast', () { |
| 161 var node = makeNodeWithChildren(); | 161 var node = makeNodeWithChildren(); |
| 162 Expect.isTrue(node.nodes.removeLast() is Comment); | 162 Expect.isTrue(node.nodes.removeLast() is Comment); |
| 163 Expect.equals(2, node.nodes.length); | 163 Expect.equals(2, node.nodes.length); |
| 164 Expect.isTrue(node.nodes.removeLast() is BRElement); | 164 Expect.isTrue(node.nodes.removeLast() is BRElement); |
| 165 Expect.equals(1, node.nodes.length); | 165 Expect.equals(1, node.nodes.length); |
| 166 }); | 166 }); |
| 167 | 167 |
| 168 test('getRange', () { | 168 test('getRange', () { |
| 169 var node = makeNodeWithChildren(); | 169 var node = makeNodeWithChildren(); |
| 170 Expect.isTrue(node.nodes.getRange(1, 2) is NodeList); | 170 Expect.isTrue(node.nodes.getRange(1, 2) is List<Node>); |
| 171 }); | 171 }); |
| 172 }); | 172 }); |
| 173 | 173 |
| 174 group('_NodeList', () { | 174 group('_NodeList', () { |
| 175 List<Node> makeNodeList() => | 175 List<Node> makeNodeList() => |
| 176 makeNodeWithChildren().nodes.filter((_) => true); | 176 makeNodeWithChildren().nodes.filter((_) => true); |
| 177 | 177 |
| 178 test('first', () { | 178 test('first', () { |
| 179 var nodes = makeNodeList(); | 179 var nodes = makeNodeList(); |
| 180 Expect.isTrue(nodes.first is Text); | 180 Expect.isTrue(nodes.first is Text); |
| 181 }); | 181 }); |
| 182 | 182 |
| 183 test('filter', () { | 183 test('filter', () { |
| 184 var filtered = makeNodeList().filter((n) => n is BRElement); | 184 var filtered = makeNodeList().filter((n) => n is BRElement); |
| 185 Expect.equals(1, filtered.length); | 185 Expect.equals(1, filtered.length); |
| 186 Expect.isTrue(filtered[0] is BRElement); | 186 Expect.isTrue(filtered[0] is BRElement); |
| 187 Expect.isTrue(filtered is NodeList); | 187 Expect.isTrue(filtered is List<Node>); |
| 188 }); | 188 }); |
| 189 | 189 |
| 190 test('getRange', () { | 190 test('getRange', () { |
| 191 var range = makeNodeList().getRange(1, 2); | 191 var range = makeNodeList().getRange(1, 2); |
| 192 Expect.isTrue(range is NodeList); | 192 Expect.isTrue(range is List<Node>); |
| 193 Expect.isTrue(range[0] is BRElement); | 193 Expect.isTrue(range[0] is BRElement); |
| 194 Expect.isTrue(range[1] is Comment); | 194 Expect.isTrue(range[1] is Comment); |
| 195 }); | 195 }); |
| 196 }); | 196 }); |
| 197 } | 197 } |
| OLD | NEW |