Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / e4x / XML / 13.4.3.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("13.4.3 - XML Properties");
45
46 // Test defaults
47 TEST(1, true, XML.ignoreComments);   
48 TEST(2, true, XML.ignoreProcessingInstructions);   
49 TEST(3, true, XML.ignoreWhitespace);   
50 TEST(4, true, XML.prettyPrinting);   
51 TEST(5, 2, XML.prettyIndent);
52
53 // ignoreComments
54 x = <alpha><!-- comment --><bravo>one</bravo></alpha>;
55
56 correct = <alpha><bravo>one</bravo></alpha>;
57
58 TEST(6, correct, x);
59
60 XML.ignoreComments = false;
61
62 x = <alpha><!-- comment --><bravo>one</bravo></alpha>;
63
64 correct =
65 "<alpha>\n" +  
66 "  <!-- comment -->\n" +
67 "  <bravo>one</bravo>\n" +
68 "</alpha>";
69
70 TEST_XML(7, correct, x);
71
72
73 // ignoreProcessingInstructions
74 XML.setSettings();
75 x =
76 <>
77     <alpha>
78         <?foo version="1.0" encoding="utf-8"?>
79         <bravo>one</bravo>
80     </alpha>
81 </>;
82
83 correct =
84 <alpha>
85     <bravo>one</bravo>
86 </alpha>;
87
88 TEST(8, correct, x);
89
90 XML.ignoreProcessingInstructions = false;
91
92 x =
93 <>
94     <alpha>
95         <?foo version="1.0" encoding="utf-8"?>
96         <bravo>one</bravo>
97     </alpha>
98 </>;
99
100 correct =
101 "<alpha>\n" +  
102 "  <?foo version=\"1.0\" encoding=\"utf-8\"?>\n" +
103 "  <bravo>one</bravo>\n" +
104 "</alpha>";
105
106 TEST_XML(9, correct, x);
107
108 // ignoreWhitespace
109 XML.setSettings();
110 x = new XML("<alpha> \t\r\n\r\n<bravo> \t\r\n\r\none</bravo> \t\r\n\r\n</alpha>");
111
112 correct =
113 "<alpha>\n" +
114 "  <bravo>one</bravo>\n" +
115 "</alpha>";
116
117 TEST_XML(10, correct, x);
118
119 XML.ignoreWhitespace = false;
120 XML.prettyPrinting = false;
121
122 correct = "<alpha> \n\n<bravo> \n\none</bravo> \n\n</alpha>";
123 x = new XML(correct);
124
125 TEST_XML(11, correct, x);
126
127 // prettyPrinting
128 XML.setSettings();
129
130 x =
131 <alpha>
132     one
133     <bravo>two</bravo>
134     <charlie/>
135     <delta>
136       three
137       <echo>four</echo>
138     </delta>
139 </alpha>;
140
141 correct = "<alpha>\n" +
142     "  one\n" +
143     "  <bravo>two</bravo>\n" +
144     "  <charlie/>\n" +
145     "  <delta>\n" +
146     "    three\n" +
147     "    <echo>four</echo>\n" +
148     "  </delta>\n" +
149     "</alpha>";
150    
151 TEST(12, correct, x.toString());
152 TEST(13, correct, x.toXMLString());
153
154 XML.prettyPrinting = false;
155
156 correct = "<alpha>one<bravo>two</bravo><charlie/><delta>three<echo>four</echo></delta></alpha>";
157 TEST(14, correct, x.toString());
158 TEST(15, correct, x.toXMLString());
159
160 // prettyIndent
161 XML.prettyPrinting = true;
162 XML.prettyIndent = 3;
163
164 correct = "<alpha>\n" +
165     "   one\n" +
166     "   <bravo>two</bravo>\n" +
167     "   <charlie/>\n" +
168     "   <delta>\n" +
169     "      three\n" +
170     "      <echo>four</echo>\n" +
171     "   </delta>\n" +
172     "</alpha>";
173
174 TEST(16, correct, x.toString());
175 TEST(17, correct, x.toXMLString());
176
177 XML.prettyIndent = 0;
178
179 correct = "<alpha>\n" +
180     "one\n" +
181     "<bravo>two</bravo>\n" +
182     "<charlie/>\n" +
183     "<delta>\n" +
184     "three\n" +
185     "<echo>four</echo>\n" +
186     "</delta>\n" +
187     "</alpha>";
188
189 TEST(18, correct, x.toString());
190 TEST(19, correct, x.toXMLString());
191
192 // settings()
193 XML.setSettings();
194 o = XML.settings();
195 TEST(20, true, o.ignoreComments);
196 TEST(21, true, o.ignoreProcessingInstructions);
197 TEST(22, true, o.ignoreWhitespace);
198 TEST(23, true, o.prettyPrinting);
199 TEST(24, 2, o.prettyIndent);
200
201 // setSettings()
202 o = XML.settings();
203 o.ignoreComments = false;
204 o.ignoreProcessingInstructions = false;
205 o.ignoreWhitespace = false;
206 o.prettyPrinting = false;
207 o.prettyIndent = 7;
208
209 XML.setSettings(o);
210 o = XML.settings();
211 TEST(25, false, o.ignoreComments);
212 TEST(26, false, o.ignoreProcessingInstructions);
213 TEST(27, false, o.ignoreWhitespace);
214 TEST(28, false, o.prettyPrinting);
215 TEST(29, 7, o.prettyIndent);
216
217 // setSettings()
218 XML.setSettings();
219 o = XML.settings();
220 TEST(30, true, o.ignoreComments);
221 TEST(31, true, o.ignoreProcessingInstructions);
222 TEST(32, true, o.ignoreWhitespace);
223 TEST(33, true, o.prettyPrinting);
224 TEST(34, 2, o.prettyIndent);
225
226 correct = new XML('');
227
228 // ignoreComments
229 XML.ignoreComments = true;
230 x = <!-- comment -->;
231 TEST(35, correct, x);
232
233 // ignoreProcessingInstructions
234 XML.ignoreProcessingInstructions = true;
235 x = <?pi?>;
236 TEST(36, correct, x);
237
238 END();