Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / e4x / Expressions / 11.2.1.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("11.2.1 - Property Accessors");
45
46 order =
47 <order id="123456" timestamp="Mon Mar 10 2003 16:03:25 GMT-0800 (PST)">
48     <customer>
49         <firstname>John</firstname>
50         <lastname>Doe</lastname>
51     </customer>
52     <item>
53         <description>Big Screen Television</description>
54         <price>1299.99</price>
55         <quantity>1</quantity>
56     </item>
57 </order>;   
58
59 correct =
60 <customer>
61     <firstname>John</firstname>
62     <lastname>Doe</lastname>
63 </customer>;
64
65 TEST(1, correct, order.customer);
66 TEST_XML(2, 123456, order.@id);
67
68 correct =
69 <item>
70     <description>Big Screen Television</description>
71     <price>1299.99</price>
72     <quantity>1</quantity>
73 </item>
74
75 TEST(3, correct, order.children()[1]);
76
77 correct =
78 <customer>
79     <firstname>John</firstname>
80     <lastname>Doe</lastname>
81 </customer> +
82 <item>
83     <description>Big Screen Television</description>
84     <price>1299.99</price>
85     <quantity>1</quantity>
86 </item>;
87
88
89 TEST(4, correct, order.*);
90
91 correct = new XMLList();
92 correct += new XML("123456");
93 correct += new XML("Mon Mar 10 2003 16:03:25 GMT-0800 (PST)");
94 TEST(5, correct, order.@*);
95
96 order = <order>
97         <customer>
98             <firstname>John</firstname>
99             <lastname>Doe</lastname>
100         </customer>
101         <item id="3456">
102             <description>Big Screen Television</description>
103             <price>1299.99</price>
104             <quantity>1</quantity>
105         </item>
106         <item id="56789">
107             <description>DVD Player</description>
108             <price>399.99</price>
109             <quantity>1</quantity>
110         </item>
111         </order>;
112
113 correct =
114 <description>Big Screen Television</description> +
115 <description>DVD Player</description>;
116
117 TEST(6, correct, order.item.description);
118
119 correct = new XMLList();
120 correct += new XML("3456");
121 correct += new XML("56789");
122 TEST(7, correct, order.item.@id);
123
124 correct =
125 <item id="56789">
126     <description>DVD Player</description>
127     <price>399.99</price>
128     <quantity>1</quantity>
129 </item>
130
131 TEST(8, correct, order.item[1]);
132
133 correct =
134 <description>Big Screen Television</description> +
135 <price>1299.99</price> +
136 <quantity>1</quantity> +
137 <description>DVD Player</description> +
138 <price>399.99</price> +
139 <quantity>1</quantity>;
140
141 TEST(9, correct, order.item.*);
142
143 correct=
144 <price>1299.99</price>;
145
146 TEST(10, correct, order.item.*[1]);
147
148 // The spec requires that we get the first (and only) order [treating single element as a list].
149 // We ignore this for xml objects that can have children and always return children for numeric
150 // property names.
151 // order = <order>
152 //        <customer>
153 //            <firstname>John</firstname>
154 //            <lastname>Doe</lastname>
155 //        </customer>
156 //        <item id="3456">
157 //            <description>Big Screen Television</description>
158 //            <price>1299.99</price>
159 //            <quantity>1</quantity>
160 //        </item>
161 //        <item id="56789">
162 //            <description>DVD Player</description>
163 //            <price>399.99</price>
164 //            <quantity>1</quantity>
165 //        </item>
166 //        </order>;
167
168 // TEST(11, order, order[0]);
169
170 // Any other index should return undefined, but we return the other child.
171 // TEST(12, undefined, order[1]);
172
173 END();