Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / e4x / Types / 9.1.1.9.js
1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * ***** BEGIN LICENSE BLOCK *****
4  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is Rhino code, released
17  * May 6, 1999.
18  *
19  * The Initial Developer of the Original Code is
20  * Netscape Communications Corporation.
21  * Portions created by the Initial Developer are Copyright (C) 1997-2000
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *   Igor Bukanov
26  *   Ethan Hugg
27  *   Milen Nankov
28  *
29  * Alternatively, the contents of this file may be used under the terms of
30  * either the GNU General Public License Version 2 or later (the "GPL"), or
31  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
32  * in which case the provisions of the GPL or the LGPL are applicable instead
33  * of those above. If you wish to allow use of your version of this file only
34  * under the terms of either the GPL or the LGPL, and not to allow others to
35  * use your version of this file under the terms of the MPL, indicate your
36  * decision by deleting the provisions above and replace them with the notice
37  * and other provisions required by the GPL or the LGPL. If you do not delete
38  * the provisions above, a recipient may use your version of this file under
39  * the terms of any one of the MPL, the GPL or the LGPL.
40  *
41  * ***** END LICENSE BLOCK ***** */
42
43
44 START("9.1.1.9 - XML [[Equals]]");
45
46 x = <alpha>one</alpha>;
47 y = <alpha>one</alpha>;
48 TEST(1, true, (x == y) && (y == x));
49
50 // Should return false if comparison is not XML
51 y = "<alpha>one</alpha>";
52 TEST(2, false, (x == y) || (y == x));
53
54 y = undefined
55 TEST(3, false, (x == y) || (y == x));
56
57 y = null
58 TEST(4, false, (x == y) || (y == x));
59
60 y = new Object();
61 TEST(5, false, (x == y) || (y == x));
62
63 // Check with attributes
64 x = <alpha attr1="value1">one<bravo attr2="value2">two</bravo></alpha>;
65 y = <alpha attr1="value1">one<bravo attr2="value2">two</bravo></alpha>;
66 TEST(6, true, (x == y) && (y == x));
67
68 y = <alpha attr1="new value">one<bravo attr2="value2">two</bravo></alpha>;
69 TEST(7, false, (x == y) || (y == x));
70
71 // Logical equality
72 // Attribute order.
73 x = <alpha attr1="value1" attr2="value2">one<bravo attr3="value3" attr4="value4">two</bravo></alpha>;
74 y = <alpha attr2="value2" attr1="value1">one<bravo attr4="value4" attr3="value3">two</bravo></alpha>;
75 TEST(8, true, (x == y) && (y == x));
76
77 // Skips empty text nodes if ignoring whitespace
78 // XML.ignoreWhitespace = false;
79 x = <alpha> <bravo>one</bravo> </alpha>;
80 y = <alpha><bravo>one</bravo></alpha>;
81 TEST(9, true, (x == y) && (y == x));
82
83 // Doesn't trim text nodes.
84 x = <alpha><bravo> one </bravo></alpha>;
85 y = <alpha><bravo>one</bravo></alpha>;
86 TEST(10, false, (x == y) || (y == x));
87
88 // Compare comments
89 XML.ignoreComments = false;
90 x = <alpha><!-- comment1 --><bravo><!-- comment2 -->one</bravo></alpha>;
91 y = <alpha><!-- comment2 --><bravo><!-- comment1 -->one</bravo></alpha>;
92 TEST(11, false, (x == y) || (y == x));
93
94 one = x.*[0];
95 two = y.*[0];
96 TEST(12, false, (one == two) || (two == one));
97
98 one = x.*[0];
99 two = y.bravo.*[0];
100 TEST(13, true, (one == two) && (two == one));
101
102
103 // Compare processing instructions
104 XML.ignoreProcessingInstructions = false;
105 x = <alpha><?one foo="bar" ?><bravo><?two bar="foo" ?>one</bravo></alpha>;
106 y = <alpha><?two bar="foo" ?><bravo><?one foo="bar" ?>one</bravo></alpha>;
107 TEST(14, false, (x == y) || (y == x));
108
109 one = x.*[0];
110 two = y.*[0];
111 TEST(15, false, (one == two) || (two == one));
112
113 one = x.*[0];
114 two = y.bravo.*[0];
115 TEST(16, true, (one == two) && (two == one));
116
117 // Namepaces
118 x = <ns1:alpha xmlns:ns1="http://foo/"><ns1:bravo>one</ns1:bravo></ns1:alpha>;
119 y = <ns2:alpha xmlns:ns2="http://foo/"><ns2:bravo>one</ns2:bravo></ns2:alpha>;
120
121 TEST(17, true, (x == y) && (y == x));
122
123 y = <ns2:alpha xmlns:ns2="http://foo"><ns2:bravo>one</ns2:bravo></ns2:alpha>;
124 TEST(18, false, (x == y) || (y == x));
125
126 // Default namespace
127 default xml namespace = "http://foo/";
128 x = <alpha xmlns="http://foo/">one</alpha>;
129 y = <alpha>one</alpha>;
130
131 TEST(19, true, (x == y) && (y == x));
132
133 // bug 358183
134 x = <a b="1"/>;
135 y = <a b="1" c="2"/>;
136 TEST(20, false,(x == y));
137
138 END();