Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / e4x / TypeConversion / 10.2.1.js
1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is Rhino code, released
18  * May 6, 1999.
19  *
20  * The Initial Developer of the Original Code is
21  * Netscape Communications Corporation.
22  * Portions created by the Initial Developer are Copyright (C) 1997-2000
23  * the Initial Developer. All Rights Reserved.
24  *
25  * Contributor(s): Martin Honnen
26  *                 Brendan Eich
27  *
28  * Alternatively, the contents of this file may be used under the terms of
29  * either the GNU General Public License Version 2 or later (the "GPL"), or
30  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31  * in which case the provisions of the GPL or the LGPL are applicable instead
32  * of those above. If you wish to allow use of your version of this file only
33  * under the terms of either the GPL or the LGPL, and not to allow others to
34  * use your version of this file under the terms of the MPL, indicate your
35  * decision by deleting the provisions above and replace them with the notice
36  * and other provisions required by the GPL or the LGPL. If you do not delete
37  * the provisions above, a recipient may use your version of this file under
38  * the terms of any one of the MPL, the GPL or the LGPL.
39  *
40  * ***** END LICENSE BLOCK ***** */
41
42
43 START("10.2.1 - XML.toXMLString");
44
45 var BUGNUMBER = 297025;
46
47 printBugNumber(BUGNUMBER);
48
49 var n = 1;
50 var actual;
51 var expect;
52
53
54 // Semantics
55
56 var xml;
57
58 // text 10.2.1 - Step 4
59
60 printStatus(inSection(n++) + ' testing text');
61
62 var text = 'this is text';
63
64
65 printStatus(inSection(n++) + ' testing text with pretty printing');
66 XML.prettyPrinting = true;
67 XML.prettyIndent   = 10;
68 xml = new XML(text);
69 expect = text;
70 actual = xml.toXMLString();
71 TEST(n, expect, actual);
72
73 printStatus(inSection(n++) + ' testing text with whitespace with pretty printing');
74 XML.prettyPrinting = true;
75 XML.prettyIndent   = 10;
76 xml = new XML(' \t\r\n' + text + ' \t\r\n');
77 expect = text;
78 actual = xml.toXMLString();
79 TEST(n, expect, actual);
80
81 printStatus(inSection(n++) + ' testing text with whitespace without pretty printing');
82 XML.prettyPrinting = false;
83 xml = new XML(' \t\r\n' + text + ' \t\r\n');
84 expect = ' \t\r\n' + text + ' \t\r\n';
85 actual = xml.toXMLString();
86 TEST(n, expect, actual);
87
88 // EscapeElementValue - 10.2.1 Step 4.a.ii
89
90 printStatus(inSection(n++) + ' testing text EscapeElementValue');
91 var alpha = 'abcdefghijklmnopqrstuvwxyz';
92 xml = <a>{"< > &"}{alpha}</a>;
93 xml = xml.text();
94 expect = '&lt; &gt; &amp;' + alpha
95 actual = xml.toXMLString();
96 TEST(n, expect, actual);
97
98 // attribute, EscapeAttributeValue - 10.2.1 Step 5
99
100 printStatus(inSection(n++) + ' testing attribute EscapeAttributeValue');
101 xml = <foo/>;
102 xml.@bar = '"<&\u000A\u000D\u0009' + alpha;
103 expect = '<foo bar="&quot;&lt;&amp;&#xA;&#xD;&#x9;' + alpha + '"/>';
104 actual = xml.toXMLString();
105 TEST(n, expect, actual);
106
107 // Comment - 10.2.1 Step 6
108
109 printStatus(inSection(n++) + ' testing Comment');
110 XML.ignoreComments = false;
111 xml = <!-- Comment -->;
112 expect = '<!-- Comment -->';
113 actual = xml.toXMLString();
114 TEST(n, expect, actual);
115
116
117 // Processing Instruction - 10.2.1 Step 7
118
119 printStatus(inSection(n++) + ' testing Processing Instruction');
120 XML.ignoreProcessingInstructions = false;
121 xml = <?pi value?>;
122 expect = '<?pi value?>';
123 actual = xml.toXMLString();
124 TEST(n, expect, actual);
125
126 // 10.2.1 Step 8+
127
128 // From Martin and Brendan
129 var link;
130 var xlinkNamespace;
131
132 printStatus(inSection(n++));
133 expect = '<link xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink"/>';
134
135 link = <link type="simple" />;
136 xlinkNamespace = new Namespace('xlink', 'http://www.w3.org/1999/xlink');
137 link.addNamespace(xlinkNamespace);
138 printStatus('In scope namespace: ' + link.inScopeNamespaces());
139 printStatus('XML markup: ' + link.toXMLString());
140 link.@type.setName(new QName(xlinkNamespace, 'type'));
141 printStatus('name(): ' + link.@*::*[0].name());
142 actual = link.toXMLString();
143 printStatus(actual);
144
145 TEST(n, expect, actual);
146
147 printStatus(inSection(n++));
148 link = <link type="simple" />;
149 xlinkNamespace = new Namespace('xlink', 'http://www.w3.org/1999/xlink');
150 printStatus('XML markup: ' + link.toXMLString());
151 link.@type.setNamespace(xlinkNamespace);
152 printStatus('name(): ' + link.@*::*[0].name());
153 actual = link.toXMLString();
154 printStatus(actual);
155
156 TEST(n, expect, actual);
157
158 END();