| 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'); |
| 11 Node makeNodeWithChildren() => | 11 Node makeNodeWithChildren() => |
| 12 new Element.html("<div>Foo<br/><!--baz--></div>"); | 12 new Element.html("<div>Foo<br/><!--baz--></div>"); |
| 13 | 13 |
| 14 main() { | 14 main() { |
| 15 useHtmlConfiguration(); | 15 useHtmlConfiguration(); |
| 16 | 16 |
| 17 test('replaceWith', () { | 17 test('replaceWith', () { |
| 18 final node = makeNodeWithChildren(); | 18 final node = makeNodeWithChildren(); |
| 19 final subnode = node.nodes[1]; | 19 final subnode = node.nodes[1]; |
| 20 final out = subnode.replaceWith(new Text('Bar')); | 20 final out = subnode.replaceWith(new Text('Bar')); |
| 21 Expect.equals(subnode, out, '#replaceWith should be chainable'); | 21 Expect.equals(subnode, out, '#replaceWith should be chainable'); |
| 22 Expect.equals(3, node.nodes.length); | 22 Expect.equals(3, node.nodes.length); |
| 23 Expect.isTrue(node.nodes[0] is Text); | 23 Expect.isTrue(node.nodes[0] is Text); |
| 24 Expect.equals('Foo', node.nodes[0].text); | 24 Expect.equals('Foo', node.nodes[0].text); |
| 25 Expect.isTrue(node.nodes[1] is Text); | 25 Expect.isTrue(node.nodes[1] is Text); |
| 26 Expect.equals('Bar', node.nodes[1].text); | 26 Expect.equals('Bar', node.nodes[1].text); |
| 27 Expect.isTrue(node.nodes[2] is Comment); | 27 Expect.isTrue(node.nodes[2] is Comment); |
| 28 }); | 28 }); |
| 29 | 29 |
| 30 if (false) // TODO(antonm): fix it. | |
| 31 test('remove', () { | 30 test('remove', () { |
| 32 final node = makeNodeWithChildren(); | 31 final node = makeNodeWithChildren(); |
| 33 final subnode = node.nodes[1]; | 32 final subnode = node.nodes[1]; |
| 34 final out = subnode.remove(); | 33 final out = subnode.remove(); |
| 35 Expect.equals(subnode, out, '#remove should be chainable'); | 34 Expect.isNull(out); |
| 36 Expect.equals(2, node.nodes.length); | 35 Expect.equals(2, node.nodes.length); |
| 37 Expect.isTrue(node.nodes[0] is Text); | 36 Expect.isTrue(node.nodes[0] is Text); |
| 38 Expect.isTrue(node.nodes[1] is Comment); | 37 Expect.isTrue(node.nodes[1] is Comment); |
| 39 }); | 38 }); |
| 40 | 39 |
| 41 test('contains', () { | 40 test('contains', () { |
| 42 final Node node = new Element.html("<div>Foo<span>Bar</span></div>"); | 41 final Node node = new Element.html("<div>Foo<span>Bar</span></div>"); |
| 43 Expect.isTrue(node.contains(node.nodes.first)); | 42 Expect.isTrue(node.contains(node.nodes.first)); |
| 44 Expect.isTrue(node.contains(node.nodes[1].nodes.first)); | 43 Expect.isTrue(node.contains(node.nodes[1].nodes.first)); |
| 45 Expect.isFalse(node.contains(new Text('Foo'))); | 44 Expect.isFalse(node.contains(new Text('Foo'))); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 }); | 187 }); |
| 189 | 188 |
| 190 test('getRange', () { | 189 test('getRange', () { |
| 191 var range = makeNodeList().getRange(1, 2); | 190 var range = makeNodeList().getRange(1, 2); |
| 192 Expect.isTrue(range is List<Node>); | 191 Expect.isTrue(range is List<Node>); |
| 193 Expect.isTrue(range[0] is BRElement); | 192 Expect.isTrue(range[0] is BRElement); |
| 194 Expect.isTrue(range[1] is Comment); | 193 Expect.isTrue(range[1] is Comment); |
| 195 }); | 194 }); |
| 196 }); | 195 }); |
| 197 } | 196 } |
| OLD | NEW |