1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/LexicalConventions/7.7.4.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,208 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + File Name: 7.7.4.js 1.12 + ECMA Section: 7.7.4 String Literals 1.13 + 1.14 + Description: A string literal is zero or more characters enclosed in 1.15 + single or double quotes. Each character may be 1.16 + represented by an escape sequence. 1.17 + 1.18 + 1.19 + Author: christine@netscape.com 1.20 + Date: 16 september 1997 1.21 +*/ 1.22 + 1.23 +var SECTION = "7.7.4"; 1.24 +var VERSION = "ECMA_1"; 1.25 +startTest(); 1.26 +var TITLE = "String Literals"; 1.27 + 1.28 +writeHeaderToLog( SECTION + " "+ TITLE); 1.29 + 1.30 +// StringLiteral:: "" and '' 1.31 + 1.32 +new TestCase( SECTION, "\"\"", "", "" ); 1.33 +new TestCase( SECTION, "\'\'", "", '' ); 1.34 + 1.35 +// DoubleStringCharacters:: DoubleStringCharacter :: EscapeSequence :: CharacterEscapeSequence 1.36 +new TestCase( SECTION, "\\\"", String.fromCharCode(0x0022), "\"" ); 1.37 +new TestCase( SECTION, "\\\'", String.fromCharCode(0x0027), "\'" ); 1.38 +new TestCase( SECTION, "\\", String.fromCharCode(0x005C), "\\" ); 1.39 +new TestCase( SECTION, "\\b", String.fromCharCode(0x0008), "\b" ); 1.40 +new TestCase( SECTION, "\\f", String.fromCharCode(0x000C), "\f" ); 1.41 +new TestCase( SECTION, "\\n", String.fromCharCode(0x000A), "\n" ); 1.42 +new TestCase( SECTION, "\\r", String.fromCharCode(0x000D), "\r" ); 1.43 +new TestCase( SECTION, "\\t", String.fromCharCode(0x0009), "\t" ); 1.44 +new TestCase( SECTION, "\\v", String.fromCharCode(0x000B), "\v" ); 1.45 + 1.46 +// DoubleStringCharacters:DoubleStringCharacter::EscapeSequence::OctalEscapeSequence 1.47 + 1.48 +new TestCase( SECTION, "\\00", String.fromCharCode(0x0000), "\00" ); 1.49 +new TestCase( SECTION, "\\01", String.fromCharCode(0x0001), "\01" ); 1.50 +new TestCase( SECTION, "\\02", String.fromCharCode(0x0002), "\02" ); 1.51 +new TestCase( SECTION, "\\03", String.fromCharCode(0x0003), "\03" ); 1.52 +new TestCase( SECTION, "\\04", String.fromCharCode(0x0004), "\04" ); 1.53 +new TestCase( SECTION, "\\05", String.fromCharCode(0x0005), "\05" ); 1.54 +new TestCase( SECTION, "\\06", String.fromCharCode(0x0006), "\06" ); 1.55 +new TestCase( SECTION, "\\07", String.fromCharCode(0x0007), "\07" ); 1.56 + 1.57 +new TestCase( SECTION, "\\010", String.fromCharCode(0x0008), "\010" ); 1.58 +new TestCase( SECTION, "\\011", String.fromCharCode(0x0009), "\011" ); 1.59 +new TestCase( SECTION, "\\012", String.fromCharCode(0x000A), "\012" ); 1.60 +new TestCase( SECTION, "\\013", String.fromCharCode(0x000B), "\013" ); 1.61 +new TestCase( SECTION, "\\014", String.fromCharCode(0x000C), "\014" ); 1.62 +new TestCase( SECTION, "\\015", String.fromCharCode(0x000D), "\015" ); 1.63 +new TestCase( SECTION, "\\016", String.fromCharCode(0x000E), "\016" ); 1.64 +new TestCase( SECTION, "\\017", String.fromCharCode(0x000F), "\017" ); 1.65 +new TestCase( SECTION, "\\020", String.fromCharCode(0x0010), "\020" ); 1.66 +new TestCase( SECTION, "\\042", String.fromCharCode(0x0022), "\042" ); 1.67 + 1.68 +new TestCase( SECTION, "\\0", String.fromCharCode(0x0000), "\0" ); 1.69 +new TestCase( SECTION, "\\1", String.fromCharCode(0x0001), "\1" ); 1.70 +new TestCase( SECTION, "\\2", String.fromCharCode(0x0002), "\2" ); 1.71 +new TestCase( SECTION, "\\3", String.fromCharCode(0x0003), "\3" ); 1.72 +new TestCase( SECTION, "\\4", String.fromCharCode(0x0004), "\4" ); 1.73 +new TestCase( SECTION, "\\5", String.fromCharCode(0x0005), "\5" ); 1.74 +new TestCase( SECTION, "\\6", String.fromCharCode(0x0006), "\6" ); 1.75 +new TestCase( SECTION, "\\7", String.fromCharCode(0x0007), "\7" ); 1.76 + 1.77 +new TestCase( SECTION, "\\10", String.fromCharCode(0x0008), "\10" ); 1.78 +new TestCase( SECTION, "\\11", String.fromCharCode(0x0009), "\11" ); 1.79 +new TestCase( SECTION, "\\12", String.fromCharCode(0x000A), "\12" ); 1.80 +new TestCase( SECTION, "\\13", String.fromCharCode(0x000B), "\13" ); 1.81 +new TestCase( SECTION, "\\14", String.fromCharCode(0x000C), "\14" ); 1.82 +new TestCase( SECTION, "\\15", String.fromCharCode(0x000D), "\15" ); 1.83 +new TestCase( SECTION, "\\16", String.fromCharCode(0x000E), "\16" ); 1.84 +new TestCase( SECTION, "\\17", String.fromCharCode(0x000F), "\17" ); 1.85 +new TestCase( SECTION, "\\20", String.fromCharCode(0x0010), "\20" ); 1.86 +new TestCase( SECTION, "\\42", String.fromCharCode(0x0022), "\42" ); 1.87 + 1.88 +new TestCase( SECTION, "\\000", String.fromCharCode(0), "\000" ); 1.89 +new TestCase( SECTION, "\\111", String.fromCharCode(73), "\111" ); 1.90 +new TestCase( SECTION, "\\222", String.fromCharCode(146), "\222" ); 1.91 +new TestCase( SECTION, "\\333", String.fromCharCode(219), "\333" ); 1.92 + 1.93 +// following line commented out as it causes a compile time error 1.94 +// new TestCase( SECTION, "\\444", "444", "\444" ); 1.95 + 1.96 +// DoubleStringCharacters:DoubleStringCharacter::EscapeSequence::HexEscapeSequence 1.97 +new TestCase( SECTION, "\\xF0", String.fromCharCode(240), "\xF0" ); 1.98 +new TestCase( SECTION, "\\xE1", String.fromCharCode(225), "\xE1" ); 1.99 +new TestCase( SECTION, "\\xD2", String.fromCharCode(210), "\xD2" ); 1.100 +new TestCase( SECTION, "\\xC3", String.fromCharCode(195), "\xC3" ); 1.101 +new TestCase( SECTION, "\\xB4", String.fromCharCode(180), "\xB4" ); 1.102 +new TestCase( SECTION, "\\xA5", String.fromCharCode(165), "\xA5" ); 1.103 +new TestCase( SECTION, "\\x96", String.fromCharCode(150), "\x96" ); 1.104 +new TestCase( SECTION, "\\x87", String.fromCharCode(135), "\x87" ); 1.105 +new TestCase( SECTION, "\\x78", String.fromCharCode(120), "\x78" ); 1.106 +new TestCase( SECTION, "\\x69", String.fromCharCode(105), "\x69" ); 1.107 +new TestCase( SECTION, "\\x5A", String.fromCharCode(90), "\x5A" ); 1.108 +new TestCase( SECTION, "\\x4B", String.fromCharCode(75), "\x4B" ); 1.109 +new TestCase( SECTION, "\\x3C", String.fromCharCode(60), "\x3C" ); 1.110 +new TestCase( SECTION, "\\x2D", String.fromCharCode(45), "\x2D" ); 1.111 +new TestCase( SECTION, "\\x1E", String.fromCharCode(30), "\x1E" ); 1.112 +new TestCase( SECTION, "\\x0F", String.fromCharCode(15), "\x0F" ); 1.113 + 1.114 +// string literals only take up to two hext digits. therefore, the third character in this string 1.115 +// should be interpreted as a StringCharacter and not part of the HextEscapeSequence 1.116 + 1.117 +new TestCase( SECTION, "\\xF0F", String.fromCharCode(240)+"F", "\xF0F" ); 1.118 +new TestCase( SECTION, "\\xE1E", String.fromCharCode(225)+"E", "\xE1E" ); 1.119 +new TestCase( SECTION, "\\xD2D", String.fromCharCode(210)+"D", "\xD2D" ); 1.120 +new TestCase( SECTION, "\\xC3C", String.fromCharCode(195)+"C", "\xC3C" ); 1.121 +new TestCase( SECTION, "\\xB4B", String.fromCharCode(180)+"B", "\xB4B" ); 1.122 +new TestCase( SECTION, "\\xA5A", String.fromCharCode(165)+"A", "\xA5A" ); 1.123 +new TestCase( SECTION, "\\x969", String.fromCharCode(150)+"9", "\x969" ); 1.124 +new TestCase( SECTION, "\\x878", String.fromCharCode(135)+"8", "\x878" ); 1.125 +new TestCase( SECTION, "\\x787", String.fromCharCode(120)+"7", "\x787" ); 1.126 +new TestCase( SECTION, "\\x696", String.fromCharCode(105)+"6", "\x696" ); 1.127 +new TestCase( SECTION, "\\x5A5", String.fromCharCode(90)+"5", "\x5A5" ); 1.128 +new TestCase( SECTION, "\\x4B4", String.fromCharCode(75)+"4", "\x4B4" ); 1.129 +new TestCase( SECTION, "\\x3C3", String.fromCharCode(60)+"3", "\x3C3" ); 1.130 +new TestCase( SECTION, "\\x2D2", String.fromCharCode(45)+"2", "\x2D2" ); 1.131 +new TestCase( SECTION, "\\x1E1", String.fromCharCode(30)+"1", "\x1E1" ); 1.132 +new TestCase( SECTION, "\\x0F0", String.fromCharCode(15)+"0", "\x0F0" ); 1.133 + 1.134 +// DoubleStringCharacter::EscapeSequence::CharacterEscapeSequence::\ NonEscapeCharacter 1.135 +new TestCase( SECTION, "\\a", "a", "\a" ); 1.136 +new TestCase( SECTION, "\\c", "c", "\c" ); 1.137 +new TestCase( SECTION, "\\d", "d", "\d" ); 1.138 +new TestCase( SECTION, "\\e", "e", "\e" ); 1.139 +new TestCase( SECTION, "\\g", "g", "\g" ); 1.140 +new TestCase( SECTION, "\\h", "h", "\h" ); 1.141 +new TestCase( SECTION, "\\i", "i", "\i" ); 1.142 +new TestCase( SECTION, "\\j", "j", "\j" ); 1.143 +new TestCase( SECTION, "\\k", "k", "\k" ); 1.144 +new TestCase( SECTION, "\\l", "l", "\l" ); 1.145 +new TestCase( SECTION, "\\m", "m", "\m" ); 1.146 +new TestCase( SECTION, "\\o", "o", "\o" ); 1.147 +new TestCase( SECTION, "\\p", "p", "\p" ); 1.148 +new TestCase( SECTION, "\\q", "q", "\q" ); 1.149 +new TestCase( SECTION, "\\s", "s", "\s" ); 1.150 +new TestCase( SECTION, "\\w", "w", "\w" ); 1.151 +new TestCase( SECTION, "\\y", "y", "\y" ); 1.152 +new TestCase( SECTION, "\\z", "z", "\z" ); 1.153 +new TestCase( SECTION, "\\9", "9", "\9" ); 1.154 + 1.155 +new TestCase( SECTION, "\\A", "A", "\A" ); 1.156 +new TestCase( SECTION, "\\B", "B", "\B" ); 1.157 +new TestCase( SECTION, "\\C", "C", "\C" ); 1.158 +new TestCase( SECTION, "\\D", "D", "\D" ); 1.159 +new TestCase( SECTION, "\\E", "E", "\E" ); 1.160 +new TestCase( SECTION, "\\F", "F", "\F" ); 1.161 +new TestCase( SECTION, "\\G", "G", "\G" ); 1.162 +new TestCase( SECTION, "\\H", "H", "\H" ); 1.163 +new TestCase( SECTION, "\\I", "I", "\I" ); 1.164 +new TestCase( SECTION, "\\J", "J", "\J" ); 1.165 +new TestCase( SECTION, "\\K", "K", "\K" ); 1.166 +new TestCase( SECTION, "\\L", "L", "\L" ); 1.167 +new TestCase( SECTION, "\\M", "M", "\M" ); 1.168 +new TestCase( SECTION, "\\N", "N", "\N" ); 1.169 +new TestCase( SECTION, "\\O", "O", "\O" ); 1.170 +new TestCase( SECTION, "\\P", "P", "\P" ); 1.171 +new TestCase( SECTION, "\\Q", "Q", "\Q" ); 1.172 +new TestCase( SECTION, "\\R", "R", "\R" ); 1.173 +new TestCase( SECTION, "\\S", "S", "\S" ); 1.174 +new TestCase( SECTION, "\\T", "T", "\T" ); 1.175 +new TestCase( SECTION, "\\U", "U", "\U" ); 1.176 +new TestCase( SECTION, "\\V", "V", "\V" ); 1.177 +new TestCase( SECTION, "\\W", "W", "\W" ); 1.178 +new TestCase( SECTION, "\\X", "X", "\X" ); 1.179 +new TestCase( SECTION, "\\Y", "Y", "\Y" ); 1.180 +new TestCase( SECTION, "\\Z", "Z", "\Z" ); 1.181 + 1.182 +// DoubleStringCharacter::EscapeSequence::UnicodeEscapeSequence 1.183 + 1.184 +new TestCase( SECTION, "\\u0020", " ", "\u0020" ); 1.185 +new TestCase( SECTION, "\\u0021", "!", "\u0021" ); 1.186 +new TestCase( SECTION, "\\u0022", "\"", "\u0022" ); 1.187 +new TestCase( SECTION, "\\u0023", "#", "\u0023" ); 1.188 +new TestCase( SECTION, "\\u0024", "$", "\u0024" ); 1.189 +new TestCase( SECTION, "\\u0025", "%", "\u0025" ); 1.190 +new TestCase( SECTION, "\\u0026", "&", "\u0026" ); 1.191 +new TestCase( SECTION, "\\u0027", "'", "\u0027" ); 1.192 +new TestCase( SECTION, "\\u0028", "(", "\u0028" ); 1.193 +new TestCase( SECTION, "\\u0029", ")", "\u0029" ); 1.194 +new TestCase( SECTION, "\\u002A", "*", "\u002A" ); 1.195 +new TestCase( SECTION, "\\u002B", "+", "\u002B" ); 1.196 +new TestCase( SECTION, "\\u002C", ",", "\u002C" ); 1.197 +new TestCase( SECTION, "\\u002D", "-", "\u002D" ); 1.198 +new TestCase( SECTION, "\\u002E", ".", "\u002E" ); 1.199 +new TestCase( SECTION, "\\u002F", "/", "\u002F" ); 1.200 +new TestCase( SECTION, "\\u0030", "0", "\u0030" ); 1.201 +new TestCase( SECTION, "\\u0031", "1", "\u0031" ); 1.202 +new TestCase( SECTION, "\\u0032", "2", "\u0032" ); 1.203 +new TestCase( SECTION, "\\u0033", "3", "\u0033" ); 1.204 +new TestCase( SECTION, "\\u0034", "4", "\u0034" ); 1.205 +new TestCase( SECTION, "\\u0035", "5", "\u0035" ); 1.206 +new TestCase( SECTION, "\\u0036", "6", "\u0036" ); 1.207 +new TestCase( SECTION, "\\u0037", "7", "\u0037" ); 1.208 +new TestCase( SECTION, "\\u0038", "8", "\u0038" ); 1.209 +new TestCase( SECTION, "\\u0039", "9", "\u0039" ); 1.210 + 1.211 +test();