]> git.saurik.com Git - apple/javascriptcore.git/blame_incremental - API/tests/minidom.js
JavaScriptCore-521.tar.gz
[apple/javascriptcore.git] / API / tests / minidom.js
... / ...
CommitLineData
1/*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26function shouldBe(a, b)
27{
28 var evalA;
29 try {
30 evalA = eval(a);
31 } catch(e) {
32 evalA = e;
33 }
34
35 if (evalA == b || isNaN(evalA) && typeof evalA == 'number' && isNaN(b) && typeof b == 'number')
36 print("PASS: " + a + " should be " + b + " and is.", "green");
37 else
38 print("__FAIL__: " + a + " should be " + b + " but instead is " + evalA + ".", "red");
39}
40
41function test()
42{
43 print("Node is " + Node);
44 for (var p in Node)
45 print(p + ": " + Node[p]);
46
47 node = new Node();
48 print("node is " + node);
49 for (var p in node)
50 print(p + ": " + node[p]);
51
52 child1 = new Node();
53 child2 = new Node();
54 child3 = new Node();
55
56 node.appendChild(child1);
57 node.appendChild(child2);
58
59 var childNodes = node.childNodes;
60
61 for (var i = 0; i < childNodes.length + 1; i++) {
62 print("item " + i + ": " + childNodes.item(i));
63 }
64
65 for (var i = 0; i < childNodes.length + 1; i++) {
66 print(i + ": " + childNodes[i]);
67 }
68
69 node.removeChild(child1);
70 node.replaceChild(child3, child2);
71
72 for (var i = 0; i < childNodes.length + 1; i++) {
73 print("item " + i + ": " + childNodes.item(i));
74 }
75
76 for (var i = 0; i < childNodes.length + 1; i++) {
77 print(i + ": " + childNodes[i]);
78 }
79
80 try {
81 node.appendChild(null);
82 } catch(e) {
83 print("caught: " + e);
84 }
85
86 try {
87 var o = new Object();
88 o.appendChild = node.appendChild;
89 o.appendChild(node);
90 } catch(e) {
91 print("caught: " + e);
92 }
93
94 try {
95 node.appendChild();
96 } catch(e) {
97 print("caught: " + e);
98 }
99
100 oldNodeType = node.nodeType;
101 node.nodeType = 1;
102 shouldBe("node.nodeType", oldNodeType);
103
104 shouldBe("node instanceof Node", true);
105 shouldBe("new Object() instanceof Node", false);
106
107 print(Node);
108}
109
110test();