1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
17 * The Original Code is Rhino code, released
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.
25 * Contributor(s): Martin Honnen
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.
40 * ***** END LICENSE BLOCK ***** */
43 START("10.2.1 - XML.toXMLString");
45 var BUGNUMBER = 297025;
47 printBugNumber(BUGNUMBER);
58 // text 10.2.1 - Step 4
60 printStatus(inSection(n++) + ' testing text');
62 var text = 'this is text';
65 printStatus(inSection(n++) + ' testing text with pretty printing');
66 XML.prettyPrinting = true;
67 XML.prettyIndent = 10;
70 actual = xml.toXMLString();
71 TEST(n, expect, actual);
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');
78 actual = xml.toXMLString();
79 TEST(n, expect, actual);
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);
88 // EscapeElementValue - 10.2.1 Step 4.a.ii
90 printStatus(inSection(n++) + ' testing text EscapeElementValue');
91 var alpha = 'abcdefghijklmnopqrstuvwxyz';
92 xml = <a>{"< > &"}{alpha}</a>;
94 expect = '< > &' + alpha
95 actual = xml.toXMLString();
96 TEST(n, expect, actual);
98 // attribute, EscapeAttributeValue - 10.2.1 Step 5
100 printStatus(inSection(n++) + ' testing attribute EscapeAttributeValue');
102 xml.@bar = '"<&\u000A\u000D\u0009' + alpha;
103 expect = '<foo bar=""<&

	' + alpha + '"/>';
104 actual = xml.toXMLString();
105 TEST(n, expect, actual);
107 // Comment - 10.2.1 Step 6
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);
117 // Processing Instruction - 10.2.1 Step 7
119 printStatus(inSection(n++) + ' testing Processing Instruction');
120 XML.ignoreProcessingInstructions = false;
122 expect = '<?pi value?>';
123 actual = xml.toXMLString();
124 TEST(n, expect, actual);
128 // From Martin and Brendan
132 printStatus(inSection(n++));
133 expect = '<link xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink"/>';
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();
145 TEST(n, expect, actual);
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();
156 TEST(n, expect, actual);