Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / e4x / Expressions / 11.6.2.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.6.2 - XMLList Assignment");
45
46 // Set the name of the only customer in the order to Fred Jones
47 order =
48 <order>
49     <customer>
50         <name>John Smith</name>
51     </customer>
52     <item id="1">
53         <description>Big Screen Television</description>
54         <price>1299.99</price>
55     </item>
56     <item id="2">
57         <description>DVD Player</description>
58         <price>399.99</price>
59     </item>
60 </order>;
61    
62 correct =
63 <order>
64     <customer>
65         <name>Fred Jones</name>
66     </customer>
67     <item id="1">
68         <description>Big Screen Television</description>
69         <price>1299.99</price>
70     </item>
71     <item id="2">
72         <description>DVD Player</description>
73         <price>399.99</price>
74     </item>
75 </order>;
76
77 order.customer.name = "Fred Jones";
78 TEST(1, correct, order);
79
80 // Replace all the hobbies for the only customer in the order
81 order =
82 <order>
83     <customer>
84         <name>John Smith</name>
85         <hobby>Biking</hobby>
86     </customer>
87     <item id="1">
88         <description>Big Screen Television</description>
89         <price>1299.99</price>
90     </item>
91     <item id="2">
92         <description>DVD Player</description>
93         <price>399.99</price>
94     </item>
95 </order>;
96
97 correct =
98 <order>
99     <customer>
100         <name>John Smith</name>
101         <hobby>shopping</hobby>
102     </customer>
103     <item id="1">
104         <description>Big Screen Television</description>
105         <price>1299.99</price>
106     </item>
107     <item id="2">
108         <description>DVD Player</description>
109         <price>399.99</price>
110     </item>
111 </order>;
112
113 order.customer.hobby = "shopping"
114 TEST(2, correct, order);
115
116 // Attempt to set the sale date of the item.  Throw an exception if more than 1 item exists.
117 order =
118 <order>
119     <customer>
120         <name>John Smith</name>
121     </customer>
122     <item id="1">
123         <description>Big Screen Television</description>
124         <price>1299.99</price>
125         <saledate>01-05-2002</saledate>
126     </item>
127 </order>;
128
129 correct =
130 <order>
131     <customer>
132         <name>John Smith</name>
133     </customer>
134     <item id="1">
135         <description>Big Screen Television</description>
136         <price>1299.99</price>
137         <saledate>05-07-2002</saledate>
138     </item>
139 </order>;
140
141 order.item.saledate = "05-07-2002"
142 TEST(3, correct, order);
143
144 order =
145 <order>
146     <customer>
147         <name>John Smith</name>
148         <hobby>Biking</hobby>
149     </customer>
150     <item id="1">
151         <description>Big Screen Television</description>
152         <price>1299.99</price>
153     </item>
154     <item id="2">
155         <description>DVD Player</description>
156         <price>399.99</price>
157     </item>
158 </order>;
159
160 try {
161     order.item.saledate = "05-07-2002";
162     SHOULD_THROW(4);
163 } catch (ex) {
164     TEST(4, "TypeError", ex.name);
165 }
166
167 // Replace all the employee's hobbies with their new favorite pastime
168 emps =
169 <employees>
170     <employee id = "1">
171         <name>John</name>
172         <age>20</age>
173         <hobby>skiing</hobby>
174     </employee>
175     <employee id = "2">
176         <name>Sue</name>
177         <age>30</age>
178         <hobby>running</hobby>
179     </employee>
180     <employee id = "3">
181         <name>Ted</name>
182         <age>35</age>
183         <hobby>Biking</hobby>
184     </employee>
185 </employees>;
186
187 correct =
188 <employees>
189     <employee id = "1">
190         <name>John</name>
191         <age>20</age>
192         <hobby>skiing</hobby>
193     </employee>
194     <employee id = "2">
195         <name>Sue</name>
196         <age>30</age>
197         <hobby>running</hobby>
198     </employee>
199     <employee id = "3">
200         <name>Ted</name>
201         <age>35</age>
202         <hobby>working</hobby>
203     </employee>
204 </employees>;
205
206 emps.employee.(@id == 3).hobby = "working";
207 TEST(5, correct, emps);
208
209 // Replace the first employee with George
210 emps =
211 <employees>
212     <employee id = "1">
213         <name>John</name>
214         <age>20</age>
215     </employee>
216     <employee id = "2">
217         <name>Sue</name>
218         <age>30</age>
219     </employee>
220     <employee id = "3">
221         <name>Ted</name>
222         <age>35</age>
223     </employee>
224 </employees>;
225
226 correct =
227 <employees>
228     <employee id = "4">
229         <name>George</name>
230         <age>27</age>
231     </employee>
232     <employee id = "2">
233         <name>Sue</name>
234         <age>30</age>
235     </employee>
236     <employee id = "3">
237         <name>Ted</name>
238         <age>35</age>
239     </employee>
240 </employees>;
241
242 emps.employee[0] = <employee id="4"><name>George</name><age>27</age></employee>;
243 TEST(6, emps, correct);
244
245 // Add a new employee to the end of the employee list
246 emps =
247 <employees>
248     <employee id = "1">
249         <name>John</name>
250         <age>20</age>
251     </employee>
252     <employee id = "2">
253         <name>Sue</name>
254         <age>30</age>
255     </employee>
256     <employee id = "3">
257         <name>Ted</name>
258         <age>35</age>
259     </employee>
260 </employees>;
261
262 correct =
263 <employees>
264     <employee id = "1">
265         <name>John</name>
266         <age>20</age>
267     </employee>
268     <employee id = "2">
269         <name>Sue</name>
270         <age>30</age>
271     </employee>
272     <employee id = "3">
273         <name>Ted</name>
274         <age>35</age>
275     </employee>
276     <employee id="4">
277         <name>Frank</name>
278         <age>39</age>
279     </employee>
280 </employees>;
281
282 emps.employee += <employee id="4"><name>Frank</name><age>39</age></employee>;
283 TEST(7, correct, emps);
284
285 // Add a new employee to the end of the employee list
286 emps =
287 <employees>
288     <employee id = "1">
289         <name>John</name>
290         <age>20</age>
291     </employee>
292     <employee id = "2">
293         <name>Sue</name>
294         <age>30</age>
295     </employee>
296     <employee id = "3">
297         <name>Ted</name>
298         <age>35</age>
299     </employee>
300 </employees>;
301
302 correct =
303 <employees>
304     <employee id = "1">
305         <name>John</name>
306         <age>20</age>
307     </employee>
308     <employee id = "2">
309         <name>Sue</name>
310         <age>30</age>
311     </employee>
312     <employee id = "3">
313         <name>Ted</name>
314         <age>35</age>
315     </employee>
316     <employee id="4">
317         <name>Frank</name>
318         <age>39</age>
319     </employee>
320 </employees>;
321
322 emps.employee[emps.employee.length()] = <employee id="4"><name>Frank</name><age>39</age></employee>;
323 TEST(7, correct, emps);
324
325 END();