1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
16 * The Original Code is Rhino code, released
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.
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.
41 * ***** END LICENSE BLOCK ***** */
44 START("9.1.1.9 - XML [[Equals]]");
46 x = <alpha>one</alpha>;
47 y = <alpha>one</alpha>;
48 TEST(1, true, (x == y) && (y == x));
50 // Should return false if comparison is not XML
51 y = "<alpha>one</alpha>";
52 TEST(2, false, (x == y) || (y == x));
55 TEST(3, false, (x == y) || (y == x));
58 TEST(4, false, (x == y) || (y == x));
61 TEST(5, false, (x == y) || (y == x));
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));
68 y = <alpha attr1="new value">one<bravo attr2="value2">two</bravo></alpha>;
69 TEST(7, false, (x == y) || (y == x));
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));
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));
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));
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));
96 TEST(12, false, (one == two) || (two == one));
100 TEST(13, true, (one == two) && (two == one));
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));
111 TEST(15, false, (one == two) || (two == one));
115 TEST(16, true, (one == two) && (two == one));
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>;
121 TEST(17, true, (x == y) && (y == x));
123 y = <ns2:alpha xmlns:ns2="http://foo"><ns2:bravo>one</ns2:bravo></ns2:alpha>;
124 TEST(18, false, (x == y) || (y == x));
127 default xml namespace = "http://foo/";
128 x = <alpha xmlns="http://foo/">one</alpha>;
129 y = <alpha>one</alpha>;
131 TEST(19, true, (x == y) && (y == x));
135 y = <a b="1" c="2"/>;
136 TEST(20, false,(x == y));