Debian Codegraph @

rhino/testsrc/tests/e4x/TypeConversion/10.1.2.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 = '10.1.2.js';
8
9 START("10.1.2 - XMLList.toString");
10
11 var n = 0;
12 var expect;
13 var actual;
14 var xmllist;
15 var xml;
16
17 // Example from ECMA 357 10.1.1
18
19 var order =
20 <order>
21 <customer>
22 <firstname>John</firstname>
23 <lastname>Doe</lastname>
24 </customer>
25 <item>
26 <description>Big Screen Television</description>
27 <price>1299.99</price>
28 <quantity>1</quantity>
29 </item>
30 </order>;
31
32 // Semantics
33
34 printStatus("test empty.toString()");
35
36 xmllist = new XMLList();
37 expect = '';
38 actual = xmllist.toString();
39 TEST(++n, expect, actual);
40
41 printStatus("test [attribute].toString()");
42
43 xmllist = new XMLList();
44 xml = <foo bar="baz"/>;
45 var attr = xml.@bar;
46 xmllist[0] = attr;
47 expect = "baz";
48 actual = xmllist.toString();
49 TEST(++n, expect, actual);
50
51 printStatus("test [text].toString()");
52
53 xmllist = new XMLList();
54 xml = new XML("this is text");
55 xmllist[0] = xml;
56 expect = "this is text";
57 actual = xmllist.toString();
58 TEST(++n, expect, actual);
59
60 printStatus("test [simpleContent].toString()");
61
62 xmllist = new XMLList();
63 xml = <foo>bar</foo>;
64 xmllist[0] = xml;
65 expect = "bar";
66 actual = xmllist.toString();
67 TEST(++n, expect, actual);
68
69 var truefalse = [true, false];
70
71 for (var ic = 0; ic < truefalse.length; ic++)
72 {
73 for (var ip = 0; ip < truefalse.length; ip++)
74 {
75 XML.ignoreComments = truefalse[ic];
76 XML.ignoreProcessingInstructions = truefalse[ip];
77
78 xmllist = new XMLList();
79 xml = <foo><!-- comment1 --><?pi1 ?>ba<!-- comment2 -->r<?pi2 ?></foo>;
80 xmllist[0] = xml;
81 expect = "bar";
82 actual = xmllist.toString();
83 TEST(++n, expect, actual);
84 }
85 }
86
87 printStatus("test nonSimpleContent.toString() == " +
88 "nonSimpleContent.toXMLString()");
89
90 var indents = [0, 4];
91
92 for (var pp = 0; pp < truefalse.length; pp++)
93 {
94 XML.prettyPrinting = truefalse[pp];
95 for (var pi = 0; pi < indents.length; pi++)
96 {
97 XML.prettyIndent = indents[pi];
98
99 xmllist = new XMLList(order);
100 expect = order.toXMLString();
101 actual = order.toString();
102 TEST(++n, expect, actual);
103
104 xmllist = order..*;
105 expect = order.toXMLString();
106 actual = order.toString();
107 TEST(++n, expect, actual);
108
109 }
110 }
111
112 END();