1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
42 ECMA Section: 7.7.4 String Literals
44 Description: A string literal is zero or more characters enclosed in
45 single or double quotes. Each character may be
46 represented by an escape sequence.
49 Author: christine@netscape.com
50 Date: 16 september 1997
53 var SECTION = "7.7.4";
54 var VERSION = "ECMA_1";
56 var TITLE = "String Literals";
58 writeHeaderToLog( SECTION + " "+ TITLE);
60 // StringLiteral:: "" and ''
62 new TestCase( SECTION, "\"\"", "", "" );
63 new TestCase( SECTION, "\'\'", "", '' );
65 // DoubleStringCharacters:: DoubleStringCharacter :: EscapeSequence :: CharacterEscapeSequence
66 new TestCase( SECTION, "\\\"", String.fromCharCode(0x0022), "\"" );
67 new TestCase( SECTION, "\\\'", String.fromCharCode(0x0027), "\'" );
68 new TestCase( SECTION, "\\", String.fromCharCode(0x005C), "\\" );
69 new TestCase( SECTION, "\\b", String.fromCharCode(0x0008), "\b" );
70 new TestCase( SECTION, "\\f", String.fromCharCode(0x000C), "\f" );
71 new TestCase( SECTION, "\\n", String.fromCharCode(0x000A), "\n" );
72 new TestCase( SECTION, "\\r", String.fromCharCode(0x000D), "\r" );
73 new TestCase( SECTION, "\\t", String.fromCharCode(0x0009), "\t" );
74 new TestCase( SECTION, "\\v", String.fromCharCode(0x000B), "\v" );
76 // DoubleStringCharacters:DoubleStringCharacter::EscapeSequence::OctalEscapeSequence
78 new TestCase( SECTION, "\\00", String.fromCharCode(0x0000), "\00" );
79 new TestCase( SECTION, "\\01", String.fromCharCode(0x0001), "\01" );
80 new TestCase( SECTION, "\\02", String.fromCharCode(0x0002), "\02" );
81 new TestCase( SECTION, "\\03", String.fromCharCode(0x0003), "\03" );
82 new TestCase( SECTION, "\\04", String.fromCharCode(0x0004), "\04" );
83 new TestCase( SECTION, "\\05", String.fromCharCode(0x0005), "\05" );
84 new TestCase( SECTION, "\\06", String.fromCharCode(0x0006), "\06" );
85 new TestCase( SECTION, "\\07", String.fromCharCode(0x0007), "\07" );
87 new TestCase( SECTION, "\\010", String.fromCharCode(0x0008), "\010" );
88 new TestCase( SECTION, "\\011", String.fromCharCode(0x0009), "\011" );
89 new TestCase( SECTION, "\\012", String.fromCharCode(0x000A), "\012" );
90 new TestCase( SECTION, "\\013", String.fromCharCode(0x000B), "\013" );
91 new TestCase( SECTION, "\\014", String.fromCharCode(0x000C), "\014" );
92 new TestCase( SECTION, "\\015", String.fromCharCode(0x000D), "\015" );
93 new TestCase( SECTION, "\\016", String.fromCharCode(0x000E), "\016" );
94 new TestCase( SECTION, "\\017", String.fromCharCode(0x000F), "\017" );
95 new TestCase( SECTION, "\\020", String.fromCharCode(0x0010), "\020" );
96 new TestCase( SECTION, "\\042", String.fromCharCode(0x0022), "\042" );
98 new TestCase( SECTION, "\\0", String.fromCharCode(0x0000), "\0" );
99 new TestCase( SECTION, "\\1", String.fromCharCode(0x0001), "\1" );
100 new TestCase( SECTION, "\\2", String.fromCharCode(0x0002), "\2" );
101 new TestCase( SECTION, "\\3", String.fromCharCode(0x0003), "\3" );
102 new TestCase( SECTION, "\\4", String.fromCharCode(0x0004), "\4" );
103 new TestCase( SECTION, "\\5", String.fromCharCode(0x0005), "\5" );
104 new TestCase( SECTION, "\\6", String.fromCharCode(0x0006), "\6" );
105 new TestCase( SECTION, "\\7", String.fromCharCode(0x0007), "\7" );
107 new TestCase( SECTION, "\\10", String.fromCharCode(0x0008), "\10" );
108 new TestCase( SECTION, "\\11", String.fromCharCode(0x0009), "\11" );
109 new TestCase( SECTION, "\\12", String.fromCharCode(0x000A), "\12" );
110 new TestCase( SECTION, "\\13", String.fromCharCode(0x000B), "\13" );
111 new TestCase( SECTION, "\\14", String.fromCharCode(0x000C), "\14" );
112 new TestCase( SECTION, "\\15", String.fromCharCode(0x000D), "\15" );
113 new TestCase( SECTION, "\\16", String.fromCharCode(0x000E), "\16" );
114 new TestCase( SECTION, "\\17", String.fromCharCode(0x000F), "\17" );
115 new TestCase( SECTION, "\\20", String.fromCharCode(0x0010), "\20" );
116 new TestCase( SECTION, "\\42", String.fromCharCode(0x0022), "\42" );
118 new TestCase( SECTION, "\\000", String.fromCharCode(0), "\000" );
119 new TestCase( SECTION, "\\111", String.fromCharCode(73), "\111" );
120 new TestCase( SECTION, "\\222", String.fromCharCode(146), "\222" );
121 new TestCase( SECTION, "\\333", String.fromCharCode(219), "\333" );
123 // following line commented out as it causes a compile time error
124 // new TestCase( SECTION, "\\444", "444", "\444" );
126 // DoubleStringCharacters:DoubleStringCharacter::EscapeSequence::HexEscapeSequence
128 new TestCase( SECTION, "\\x0", String.fromCharCode(0), "\x0" );
129 new TestCase( SECTION, "\\x1", String.fromCharCode(1), "\x1" );
130 new TestCase( SECTION, "\\x2", String.fromCharCode(2), "\x2" );
131 new TestCase( SECTION, "\\x3", String.fromCharCode(3), "\x3" );
132 new TestCase( SECTION, "\\x4", String.fromCharCode(4), "\x4" );
133 new TestCase( SECTION, "\\x5", String.fromCharCode(5), "\x5" );
134 new TestCase( SECTION, "\\x6", String.fromCharCode(6), "\x6" );
135 new TestCase( SECTION, "\\x7", String.fromCharCode(7), "\x7" );
136 new TestCase( SECTION, "\\x8", String.fromCharCode(8), "\x8" );
137 new TestCase( SECTION, "\\x9", String.fromCharCode(9), "\x9" );
138 new TestCase( SECTION, "\\xA", String.fromCharCode(10), "\xA" );
139 new TestCase( SECTION, "\\xB", String.fromCharCode(11), "\xB" );
140 new TestCase( SECTION, "\\xC", String.fromCharCode(12), "\xC" );
141 new TestCase( SECTION, "\\xD", String.fromCharCode(13), "\xD" );
142 new TestCase( SECTION, "\\xE", String.fromCharCode(14), "\xE" );
143 new TestCase( SECTION, "\\xF", String.fromCharCode(15), "\xF" );
146 new TestCase( SECTION, "\\xF0", String.fromCharCode(240), "\xF0" );
147 new TestCase( SECTION, "\\xE1", String.fromCharCode(225), "\xE1" );
148 new TestCase( SECTION, "\\xD2", String.fromCharCode(210), "\xD2" );
149 new TestCase( SECTION, "\\xC3", String.fromCharCode(195), "\xC3" );
150 new TestCase( SECTION, "\\xB4", String.fromCharCode(180), "\xB4" );
151 new TestCase( SECTION, "\\xA5", String.fromCharCode(165), "\xA5" );
152 new TestCase( SECTION, "\\x96", String.fromCharCode(150), "\x96" );
153 new TestCase( SECTION, "\\x87", String.fromCharCode(135), "\x87" );
154 new TestCase( SECTION, "\\x78", String.fromCharCode(120), "\x78" );
155 new TestCase( SECTION, "\\x69", String.fromCharCode(105), "\x69" );
156 new TestCase( SECTION, "\\x5A", String.fromCharCode(90), "\x5A" );
157 new TestCase( SECTION, "\\x4B", String.fromCharCode(75), "\x4B" );
158 new TestCase( SECTION, "\\x3C", String.fromCharCode(60), "\x3C" );
159 new TestCase( SECTION, "\\x2D", String.fromCharCode(45), "\x2D" );
160 new TestCase( SECTION, "\\x1E", String.fromCharCode(30), "\x1E" );
161 new TestCase( SECTION, "\\x0F", String.fromCharCode(15), "\x0F" );
163 // string literals only take up to two hext digits. therefore, the third character in this string
164 // should be interpreted as a StringCharacter and not part of the HextEscapeSequence
166 new TestCase( SECTION, "\\xF0F", String.fromCharCode(240)+"F", "\xF0F" );
167 new TestCase( SECTION, "\\xE1E", String.fromCharCode(225)+"E", "\xE1E" );
168 new TestCase( SECTION, "\\xD2D", String.fromCharCode(210)+"D", "\xD2D" );
169 new TestCase( SECTION, "\\xC3C", String.fromCharCode(195)+"C", "\xC3C" );
170 new TestCase( SECTION, "\\xB4B", String.fromCharCode(180)+"B", "\xB4B" );
171 new TestCase( SECTION, "\\xA5A", String.fromCharCode(165)+"A", "\xA5A" );
172 new TestCase( SECTION, "\\x969", String.fromCharCode(150)+"9", "\x969" );
173 new TestCase( SECTION, "\\x878", String.fromCharCode(135)+"8", "\x878" );
174 new TestCase( SECTION, "\\x787", String.fromCharCode(120)+"7", "\x787" );
175 new TestCase( SECTION, "\\x696", String.fromCharCode(105)+"6", "\x696" );
176 new TestCase( SECTION, "\\x5A5", String.fromCharCode(90)+"5", "\x5A5" );
177 new TestCase( SECTION, "\\x4B4", String.fromCharCode(75)+"4", "\x4B4" );
178 new TestCase( SECTION, "\\x3C3", String.fromCharCode(60)+"3", "\x3C3" );
179 new TestCase( SECTION, "\\x2D2", String.fromCharCode(45)+"2", "\x2D2" );
180 new TestCase( SECTION, "\\x1E1", String.fromCharCode(30)+"1", "\x1E1" );
181 new TestCase( SECTION, "\\x0F0", String.fromCharCode(15)+"0", "\x0F0" );
183 // G is out of hex range
185 new TestCase( SECTION, "\\xG", "xG", "\xG" );
186 new TestCase( SECTION, "\\xCG", "xCG", "\xCG" );
188 // DoubleStringCharacter::EscapeSequence::CharacterEscapeSequence::\ NonEscapeCharacter
189 new TestCase( SECTION, "\\a", "a", "\a" );
190 new TestCase( SECTION, "\\c", "c", "\c" );
191 new TestCase( SECTION, "\\d", "d", "\d" );
192 new TestCase( SECTION, "\\e", "e", "\e" );
193 new TestCase( SECTION, "\\g", "g", "\g" );
194 new TestCase( SECTION, "\\h", "h", "\h" );
195 new TestCase( SECTION, "\\i", "i", "\i" );
196 new TestCase( SECTION, "\\j", "j", "\j" );
197 new TestCase( SECTION, "\\k", "k", "\k" );
198 new TestCase( SECTION, "\\l", "l", "\l" );
199 new TestCase( SECTION, "\\m", "m", "\m" );
200 new TestCase( SECTION, "\\o", "o", "\o" );
201 new TestCase( SECTION, "\\p", "p", "\p" );
202 new TestCase( SECTION, "\\q", "q", "\q" );
203 new TestCase( SECTION, "\\s", "s", "\s" );
204 new TestCase( SECTION, "\\u", "u", "\u" );
206 new TestCase( SECTION, "\\w", "w", "\w" );
207 new TestCase( SECTION, "\\x", "x", "\x" );
208 new TestCase( SECTION, "\\y", "y", "\y" );
209 new TestCase( SECTION, "\\z", "z", "\z" );
210 new TestCase( SECTION, "\\9", "9", "\9" );
212 new TestCase( SECTION, "\\A", "A", "\A" );
213 new TestCase( SECTION, "\\B", "B", "\B" );
214 new TestCase( SECTION, "\\C", "C", "\C" );
215 new TestCase( SECTION, "\\D", "D", "\D" );
216 new TestCase( SECTION, "\\E", "E", "\E" );
217 new TestCase( SECTION, "\\F", "F", "\F" );
218 new TestCase( SECTION, "\\G", "G", "\G" );
219 new TestCase( SECTION, "\\H", "H", "\H" );
220 new TestCase( SECTION, "\\I", "I", "\I" );
221 new TestCase( SECTION, "\\J", "J", "\J" );
222 new TestCase( SECTION, "\\K", "K", "\K" );
223 new TestCase( SECTION, "\\L", "L", "\L" );
224 new TestCase( SECTION, "\\M", "M", "\M" );
225 new TestCase( SECTION, "\\N", "N", "\N" );
226 new TestCase( SECTION, "\\O", "O", "\O" );
227 new TestCase( SECTION, "\\P", "P", "\P" );
228 new TestCase( SECTION, "\\Q", "Q", "\Q" );
229 new TestCase( SECTION, "\\R", "R", "\R" );
230 new TestCase( SECTION, "\\S", "S", "\S" );
231 new TestCase( SECTION, "\\T", "T", "\T" );
232 new TestCase( SECTION, "\\U", "U", "\U" );
233 new TestCase( SECTION, "\\V", "V", "\V" );
234 new TestCase( SECTION, "\\W", "W", "\W" );
235 new TestCase( SECTION, "\\X", "X", "\X" );
236 new TestCase( SECTION, "\\Y", "Y", "\Y" );
237 new TestCase( SECTION, "\\Z", "Z", "\Z" );
239 // DoubleStringCharacter::EscapeSequence::UnicodeEscapeSequence
241 new TestCase( SECTION, "\\u0020", " ", "\u0020" );
242 new TestCase( SECTION, "\\u0021", "!", "\u0021" );
243 new TestCase( SECTION, "\\u0022", "\"", "\u0022" );
244 new TestCase( SECTION, "\\u0023", "#", "\u0023" );
245 new TestCase( SECTION, "\\u0024", "$", "\u0024" );
246 new TestCase( SECTION, "\\u0025", "%", "\u0025" );
247 new TestCase( SECTION, "\\u0026", "&", "\u0026" );
248 new TestCase( SECTION, "\\u0027", "'", "\u0027" );
249 new TestCase( SECTION, "\\u0028", "(", "\u0028" );
250 new TestCase( SECTION, "\\u0029", ")", "\u0029" );
251 new TestCase( SECTION, "\\u002A", "*", "\u002A" );
252 new TestCase( SECTION, "\\u002B", "+", "\u002B" );
253 new TestCase( SECTION, "\\u002C", ",", "\u002C" );
254 new TestCase( SECTION, "\\u002D", "-", "\u002D" );
255 new TestCase( SECTION, "\\u002E", ".", "\u002E" );
256 new TestCase( SECTION, "\\u002F", "/", "\u002F" );
257 new TestCase( SECTION, "\\u0030", "0", "\u0030" );
258 new TestCase( SECTION, "\\u0031", "1", "\u0031" );
259 new TestCase( SECTION, "\\u0032", "2", "\u0032" );
260 new TestCase( SECTION, "\\u0033", "3", "\u0033" );
261 new TestCase( SECTION, "\\u0034", "4", "\u0034" );
262 new TestCase( SECTION, "\\u0035", "5", "\u0035" );
263 new TestCase( SECTION, "\\u0036", "6", "\u0036" );
264 new TestCase( SECTION, "\\u0037", "7", "\u0037" );
265 new TestCase( SECTION, "\\u0038", "8", "\u0038" );
266 new TestCase( SECTION, "\\u0039", "9", "\u0039" );