Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / e4x / Expressions / 11.6.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.6.1 - XML Assignment");
45
46 // Change the value of the id attribute on the second item
47 order =
48 <order>
49     <item id="1">
50         <description>Big Screen Television</description>
51         <price>1299.99</price>
52     </item>
53     <item id="2">
54         <description>DVD Player</description>
55         <price>399.99</price>
56     </item>
57     <item id="3">
58         <description>CD Player</description>
59         <price>199.99</price>
60     </item>
61     <item id="4">
62         <description>8-Track Player</description>
63         <price>69.99</price>
64     </item>
65 </order>;
66
67 correct =
68 <order>
69     <item id="1">
70         <description>Big Screen Television</description>
71         <price>1299.99</price>
72     </item>
73     <item id="1.23">
74         <description>DVD Player</description>
75         <price>399.99</price>
76     </item>
77     <item id="3">
78         <description>CD Player</description>
79         <price>199.99</price>
80     </item>
81     <item id="4">
82         <description>8-Track Player</description>
83         <price>69.99</price>
84     </item>
85 </order>;
86
87 order.item[1].@id = 1.23;
88 TEST(1, correct, order);
89
90 // Add a new attribute to the second item
91 order =
92 <order>
93     <item id="1">
94         <description>Big Screen Television</description>
95         <price>1299.99</price>
96     </item>
97     <item id="2">
98         <description>DVD Player</description>
99         <price>399.99</price>
100     </item>
101     <item id="3">
102         <description>CD Player</description>
103         <price>199.99</price>
104     </item>
105     <item id="4">
106         <description>8-Track Player</description>
107         <price>69.99</price>
108     </item>
109 </order>;
110
111 correct =
112 <order>
113     <item id="1">
114         <description>Big Screen Television</description>
115         <price>1299.99</price>
116     </item>
117     <item id="2" newattr="new value">
118         <description>DVD Player</description>
119         <price>399.99</price>
120     </item>
121     <item id="3">
122         <description>CD Player</description>
123         <price>199.99</price>
124     </item>
125     <item id="4">
126         <description>8-Track Player</description>
127         <price>69.99</price>
128     </item>
129 </order>;
130
131 order.item[1].@newattr = "new value";
132 TEST(2, correct, order);
133
134 // Construct an attribute list containing all the ids in this order
135 order =
136 <order>
137     <item id="1">
138         <description>Big Screen Television</description>
139         <price>1299.99</price>
140     </item>
141     <item id="2">
142         <description>DVD Player</description>
143         <price>399.99</price>
144     </item>
145     <item id="3">
146         <description>CD Player</description>
147         <price>199.99</price>
148     </item>
149     <item id="4">
150         <description>8-Track Player</description>
151         <price>69.99</price>
152     </item>
153 </order>;
154
155 order.@allids = order.item.@id;   
156 TEST_XML(3, "1 2 3 4", order.@allids);
157
158 // Replace first child of the order element with an XML value
159 order =
160 <order>
161     <customer>
162         <name>John</name>
163         <address>948 Ranier Ave.</address>
164         <city>Portland</city>
165         <state>OR</state>
166     </customer>
167     <item id="1">
168         <description>Big Screen Television</description>
169         <price>1299.99</price>
170     </item>
171     <item id="2">
172         <description>DVD Player</description>
173         <price>399.99</price>
174     </item>
175     <item id="3">
176         <description>CD Player</description>
177         <price>199.99</price>
178     </item>
179     <item id="4">
180         <description>8-Track Player</description>
181         <price>69.99</price>
182     </item>
183 </order>;
184
185
186 order.*[0] =
187 <customer>
188     <name>Fred</name>
189     <address>123 Foobar Ave.</address>
190     <city>Bellevue</city>
191     <state>WA</state>
192 </customer>;
193
194 correct =
195 <order>
196     <customer>
197        <name>Fred</name>
198        <address>123 Foobar Ave.</address>
199        <city>Bellevue</city>
200        <state>WA</state>
201     </customer>
202     <item id="1">
203         <description>Big Screen Television</description>
204         <price>1299.99</price>
205     </item>
206     <item id="2">
207         <description>DVD Player</description>
208         <price>399.99</price>
209     </item>
210     <item id="3">
211         <description>CD Player</description>
212         <price>199.99</price>
213     </item>
214     <item id="4">
215         <description>8-Track Player</description>
216         <price>69.99</price>
217     </item>
218 </order>;
219
220 TEST(4, correct, order);
221
222 // Replace the second child of the order element with a list of items
223
224 order =
225 <order>
226     <customer>
227         <name>John</name>
228         <address>948 Ranier Ave.</address>
229         <city>Portland</city>
230         <state>OR</state>
231     </customer>
232     <item id="1">
233         <description>Big Screen Television</description>
234         <price>1299.99</price>
235     </item>
236     <item id="2">
237         <description>DVD Player</description>
238         <price>399.99</price>
239     </item>
240     <item id="3">
241         <description>CD Player</description>
242         <price>199.99</price>
243     </item>
244     <item id="4">
245         <description>8-Track Player</description>
246         <price>69.99</price>
247     </item>
248 </order>;
249
250 correct =
251 <order>
252     <customer>
253         <name>John</name>
254         <address>948 Ranier Ave.</address>
255         <city>Portland</city>
256         <state>OR</state>
257     </customer>
258     <item>item one</item>
259     <item>item two</item>
260     <item>item three</item>
261     <item id="2">
262         <description>DVD Player</description>
263         <price>399.99</price>
264     </item>
265     <item id="3">
266         <description>CD Player</description>
267         <price>199.99</price>
268     </item>
269     <item id="4">
270         <description>8-Track Player</description>
271         <price>69.99</price>
272     </item>
273 </order>;
274
275 order.item[0] = <item>item one</item> +
276            <item>item two</item> +
277            <item>item three</item>;
278
279 TEST(5, correct, order);
280
281 // Replace the third child of the order with a text node
282 order =
283 <order>
284     <customer>
285         <name>John</name>
286         <address>948 Ranier Ave.</address>
287         <city>Portland</city>
288         <state>OR</state>
289     </customer>
290     <item id="1">
291         <description>Big Screen Television</description>
292         <price>1299.99</price>
293     </item>
294     <item id="2">
295         <description>DVD Player</description>
296         <price>399.99</price>
297     </item>
298     <item id="3">
299         <description>CD Player</description>
300         <price>199.99</price>
301     </item>
302     <item id="4">
303         <description>8-Track Player</description>
304         <price>69.99</price>
305     </item>
306 </order>;
307
308 correct =
309 <order>
310     <customer>
311         <name>John</name>
312         <address>948 Ranier Ave.</address>
313         <city>Portland</city>
314         <state>OR</state>
315     </customer>
316     <item id="1">
317         <description>Big Screen Television</description>
318         <price>1299.99</price>
319     </item>
320     <item id="2">A Text Node</item>
321     <item id="3">
322         <description>CD Player</description>
323         <price>199.99</price>
324     </item>
325     <item id="4">
326         <description>8-Track Player</description>
327         <price>69.99</price>
328     </item>
329 </order>;
330
331 order.item[1] = "A Text Node";
332
333 TEST(6, correct, order);
334
335 // append a new item to the end of the order
336
337 order =
338 <order>
339     <customer>
340         <name>John</name>
341         <address>948 Ranier Ave.</address>
342         <city>Portland</city>
343         <state>OR</state>
344     </customer>
345     <item id="1">
346         <description>Big Screen Television</description>
347         <price>1299.99</price>
348     </item>
349     <item id="2">
350         <description>DVD Player</description>
351         <price>399.99</price>
352     </item>
353     <item id="3">
354         <description>CD Player</description>
355         <price>199.99</price>
356     </item>
357     <item id="4">
358         <description>8-Track Player</description>
359         <price>69.99</price>
360     </item>
361 </order>;
362
363 correct =
364 <order>
365     <customer>
366         <name>John</name>
367         <address>948 Ranier Ave.</address>
368         <city>Portland</city>
369         <state>OR</state>
370     </customer>
371     <item id="1">
372         <description>Big Screen Television</description>
373         <price>1299.99</price>
374     </item>
375     <item id="2">
376         <description>DVD Player</description>
377         <price>399.99</price>
378     </item>
379     <item id="3">
380         <description>CD Player</description>
381         <price>199.99</price>
382     </item>
383     <item id="4">
384         <description>8-Track Player</description>
385         <price>69.99</price>
386     </item>
387     <item>new item</item>
388 </order>;
389
390 order.*[order.*.length()] = <item>new item</item>;
391
392 TEST(7, correct, order);
393
394 // Change the price of the item
395 item =
396 <item>
397     <description>Big Screen Television</description>
398     <price>1299.99</price>
399 </item>
400
401 correct =
402 <item>
403     <description>Big Screen Television</description>
404     <price>99.95</price>
405 </item>
406
407 item.price = 99.95;
408
409 TEST(8, item, correct);
410
411 // Change the description of the item
412 item =
413 <item>
414     <description>Big Screen Television</description>
415     <price>1299.99</price>
416 </item>
417
418 correct =
419 <item>
420     <description>Mobile Phone</description>
421     <price>1299.99</price>
422 </item>
423
424 item.description = "Mobile Phone";
425
426 TEST(9, item, correct);
427
428 END();