Debian Codegraph @

rhino/testsrc/tests/e4x/Expressions/11.6.1.js

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 gTestfile = '11.6.1.js';
8
9 START("11.6.1 - XML Assignment");
10
11 // Change the value of the id attribute on the second item
12 order =
13 <order>
14 <item id="1">
15 <description>Big Screen Television</description>
16 <price>1299.99</price>
17 </item>
18 <item id="2">
19 <description>DVD Player</description>
20 <price>399.99</price>
21 </item>
22 <item id="3">
23 <description>CD Player</description>
24 <price>199.99</price>
25 </item>
26 <item id="4">
27 <description>8-Track Player</description>
28 <price>69.99</price>
29 </item>
30 </order>;
31
32 correct =
33 <order>
34 <item id="1">
35 <description>Big Screen Television</description>
36 <price>1299.99</price>
37 </item>
38 <item id="1.23">
39 <description>DVD Player</description>
40 <price>399.99</price>
41 </item>
42 <item id="3">
43 <description>CD Player</description>
44 <price>199.99</price>
45 </item>
46 <item id="4">
47 <description>8-Track Player</description>
48 <price>69.99</price>
49 </item>
50 </order>;
51
52 order.item[1].@id = 1.23;
53 TEST(1, correct, order);
54
55 // Add a new attribute to the second item
56 order =
57 <order>
58 <item id="1">
59 <description>Big Screen Television</description>
60 <price>1299.99</price>
61 </item>
62 <item id="2">
63 <description>DVD Player</description>
64 <price>399.99</price>
65 </item>
66 <item id="3">
67 <description>CD Player</description>
68 <price>199.99</price>
69 </item>
70 <item id="4">
71 <description>8-Track Player</description>
72 <price>69.99</price>
73 </item>
74 </order>;
75
76 correct =
77 <order>
78 <item id="1">
79 <description>Big Screen Television</description>
80 <price>1299.99</price>
81 </item>
82 <item id="2" newattr="new value">
83 <description>DVD Player</description>
84 <price>399.99</price>
85 </item>
86 <item id="3">
87 <description>CD Player</description>
88 <price>199.99</price>
89 </item>
90 <item id="4">
91 <description>8-Track Player</description>
92 <price>69.99</price>
93 </item>
94 </order>;
95
96 order.item[1].@newattr = "new value";
97 TEST(2, correct, order);
98
99 // Construct an attribute list containing all the ids in this order
100 order =
101 <order>
102 <item id="1">
103 <description>Big Screen Television</description>
104 <price>1299.99</price>
105 </item>
106 <item id="2">
107 <description>DVD Player</description>
108 <price>399.99</price>
109 </item>
110 <item id="3">
111 <description>CD Player</description>
112 <price>199.99</price>
113 </item>
114 <item id="4">
115 <description>8-Track Player</description>
116 <price>69.99</price>
117 </item>
118 </order>;
119
120 order.@allids = order.item.@id;
121 TEST_XML(3, "1 2 3 4", order.@allids);
122
123 // Replace first child of the order element with an XML value
124 order =
125 <order>
126 <customer>
127 <name>John</name>
128 <address>948 Ranier Ave.</address>
129 <city>Portland</city>
130 <state>OR</state>
131 </customer>
132 <item id="1">
133 <description>Big Screen Television</description>
134 <price>1299.99</price>
135 </item>
136 <item id="2">
137 <description>DVD Player</description>
138 <price>399.99</price>
139 </item>
140 <item id="3">
141 <description>CD Player</description>
142 <price>199.99</price>
143 </item>
144 <item id="4">
145 <description>8-Track Player</description>
146 <price>69.99</price>
147 </item>
148 </order>;
149
150
151 order.*[0] =
152 <customer>
153 <name>Fred</name>
154 <address>123 Foobar Ave.</address>
155 <city>Bellevue</city>
156 <state>WA</state>
157 </customer>;
158
159 correct =
160 <order>
161 <customer>
162 <name>Fred</name>
163 <address>123 Foobar Ave.</address>
164 <city>Bellevue</city>
165 <state>WA</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 TEST(4, correct, order);
186
187 // Replace the second child of the order element with a list of items
188
189 order =
190 <order>
191 <customer>
192 <name>John</name>
193 <address>948 Ranier Ave.</address>
194 <city>Portland</city>
195 <state>OR</state>
196 </customer>
197 <item id="1">
198 <description>Big Screen Television</description>
199 <price>1299.99</price>
200 </item>
201 <item id="2">
202 <description>DVD Player</description>
203 <price>399.99</price>
204 </item>
205 <item id="3">
206 <description>CD Player</description>
207 <price>199.99</price>
208 </item>
209 <item id="4">
210 <description>8-Track Player</description>
211 <price>69.99</price>
212 </item>
213 </order>;
214
215 correct =
216 <order>
217 <customer>
218 <name>John</name>
219 <address>948 Ranier Ave.</address>
220 <city>Portland</city>
221 <state>OR</state>
222 </customer>
223 <item>item one</item>
224 <item>item two</item>
225 <item>item three</item>
226 <item id="2">
227 <description>DVD Player</description>
228 <price>399.99</price>
229 </item>
230 <item id="3">
231 <description>CD Player</description>
232 <price>199.99</price>
233 </item>
234 <item id="4">
235 <description>8-Track Player</description>
236 <price>69.99</price>
237 </item>
238 </order>;
239
240 order.item[0] = <item>item one</item> +
241 <item>item two</item> +
242 <item>item three</item>;
243
244 TEST(5, correct, order);
245
246 // Replace the third child of the order with a text node
247 order =
248 <order>
249 <customer>
250 <name>John</name>
251 <address>948 Ranier Ave.</address>
252 <city>Portland</city>
253 <state>OR</state>
254 </customer>
255 <item id="1">
256 <description>Big Screen Television</description>
257 <price>1299.99</price>
258 </item>
259 <item id="2">
260 <description>DVD Player</description>
261 <price>399.99</price>
262 </item>
263 <item id="3">
264 <description>CD Player</description>
265 <price>199.99</price>
266 </item>
267 <item id="4">
268 <description>8-Track Player</description>
269 <price>69.99</price>
270 </item>
271 </order>;
272
273 correct =
274 <order>
275 <customer>
276 <name>John</name>
277 <address>948 Ranier Ave.</address>
278 <city>Portland</city>
279 <state>OR</state>
280 </customer>
281 <item id="1">
282 <description>Big Screen Television</description>
283 <price>1299.99</price>
284 </item>
285 <item id="2">A Text Node</item>
286 <item id="3">
287 <description>CD Player</description>
288 <price>199.99</price>
289 </item>
290 <item id="4">
291 <description>8-Track Player</description>
292 <price>69.99</price>
293 </item>
294 </order>;
295
296 order.item[1] = "A Text Node";
297
298 TEST(6, correct, order);
299
300 // append a new item to the end of the order
301
302 order =
303 <order>
304 <customer>
305 <name>John</name>
306 <address>948 Ranier Ave.</address>
307 <city>Portland</city>
308 <state>OR</state>
309 </customer>
310 <item id="1">
311 <description>Big Screen Television</description>
312 <price>1299.99</price>
313 </item>
314 <item id="2">
315 <description>DVD Player</description>
316 <price>399.99</price>
317 </item>
318 <item id="3">
319 <description>CD Player</description>
320 <price>199.99</price>
321 </item>
322 <item id="4">
323 <description>8-Track Player</description>
324 <price>69.99</price>
325 </item>
326 </order>;
327
328 correct =
329 <order>
330 <customer>
331 <name>John</name>
332 <address>948 Ranier Ave.</address>
333 <city>Portland</city>
334 <state>OR</state>
335 </customer>
336 <item id="1">
337 <description>Big Screen Television</description>
338 <price>1299.99</price>
339 </item>
340 <item id="2">
341 <description>DVD Player</description>
342 <price>399.99</price>
343 </item>
344 <item id="3">
345 <description>CD Player</description>
346 <price>199.99</price>
347 </item>
348 <item id="4">
349 <description>8-Track Player</description>
350 <price>69.99</price>
351 </item>
352 <item>new item</item>
353 </order>;
354
355 order.*[order.*.length()] = <item>new item</item>;
356
357 TEST(7, correct, order);
358
359 // Change the price of the item
360 item =
361 <item>
362 <description>Big Screen Television</description>
363 <price>1299.99</price>
364 </item>
365
366 correct =
367 <item>
368 <description>Big Screen Television</description>
369 <price>99.95</price>
370 </item>
371
372 item.price = 99.95;
373
374 TEST(8, item, correct);
375
376 // Change the description of the item
377 item =
378 <item>
379 <description>Big Screen Television</description>
380 <price>1299.99</price>
381 </item>
382
383 correct =
384 <item>
385 <description>Mobile Phone</description>
386 <price>1299.99</price>
387 </item>
388
389 item.description = "Mobile Phone";
390
391 TEST(9, item, correct);
392
393 END();