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