Debian Codegraph @

rhino/testsrc/tests/e4x/Expressions/11.1.4.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.1.4.js';
8
9 START("11.1.4 - XML Initializer");
10
11 person = <person><name>John</name><age>25</age></person>;
12 TEST(1, <person><name>John</name><age>25</age></person>, person);
13
14 e = <employees>
15 <employee id = "1"><name>Joe</name><age>20</age></employee>
16 <employee id = "2"><name>Sue</name><age>30</age></employee>
17 </employees>;
18
19 TEST_XML(2, 1, e.employee[0].@id);
20
21 correct = <name>Sue</name>;
22 TEST(3, correct, e.employee[1].name);
23
24 names = new Array();
25 names[0] = "Alpha";
26 names[1] = "Bravo";
27 names[2] = "Charlie";
28 names[3] = "Delta";
29 names[4] = "Echo";
30 names[5] = "Golf";
31 names[6] = "Hotel";
32 names[7] = "India";
33 names[8] = "Juliet";
34 names[9] = "Kilo";
35
36 ages = new Array();
37 ages[0] = "20";
38 ages[1] = "21";
39 ages[2] = "22";
40 ages[3] = "23";
41 ages[4] = "24";
42 ages[5] = "25";
43 ages[6] = "26";
44 ages[7] = "27";
45 ages[8] = "28";
46 ages[9] = "29";
47
48 for (i = 0; i < 10; i++)
49 {
50 e.*[i] = <employee id={i}>
51 <name>{names[i].toUpperCase()}</name>
52 <age>{ages[i]}</age>
53 </employee>;
54
55 correct = new XML("<employee id=\"" + i + "\"><name>" + names[i].toUpperCase() + "</name><age>" + ages[i] + "</age></employee>");
56 TEST(4 + i, correct, e.*[i]);
57 }
58
59 tagName = "name";
60 attributeName = "id";
61 attributeValue = 5;
62 content = "Fred";
63
64 x = <{tagName} {attributeName}={attributeValue}>{content}</{tagName}>;
65 TEST(14, "<name id=\"5\">Fred</name>", x.toXMLString());
66
67 // Test {} on XML and XMLList types
68 x =
69 <rectangle>
70 <length>30</length>
71 <width>50</width>
72 </rectangle>;
73
74 correct =
75 <rectangle>
76 <width>50</width>
77 <length>30</length>
78 </rectangle>;
79
80 x = <rectangle>{x.width}{x.length}</rectangle>;
81
82 TEST(15, correct, x);
83
84 var content = "<foo name=\"value\">bar</foo>";
85 x = <x><a>{content}</a></x>;
86 correct = <x/>;
87 correct.a = content;
88 TEST(16, correct, x);
89
90 x = <x a={content}/>;
91 correct = <x/>;
92 correct.@a = content;
93 TEST(17, correct, x);
94
95 a = 5;
96 b = 3;
97 c = "x";
98 x = <{c} a={a + " < " + b + " is " + (a < b)}>{a + " < " + b + " is " + (a < b)}</{c}>;
99 TEST(18, "<x a=\"5 &lt; 3 is false\">5 &lt; 3 is false</x>", x.toXMLString());
100
101 x = <{c} a={a + " > " + b + " is " + (a > b)}>{a + " > " + b + " is " + (a > b)}</{c}>;
102 TEST(19, "<x a=\"5 > 3 is true\">5 &gt; 3 is true</x>", x.toXMLString());
103
104 END();