1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/String/15.5.4.11.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,499 @@ 1.4 +// |reftest| fails 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 +var BUGNUMBER = 392378; 1.10 +var summary = '15.5.4.11 - String.prototype.replace'; 1.11 +var rex, f, a, i; 1.12 + 1.13 +reportCompare( 1.14 + 2, 1.15 + String.prototype.replace.length, 1.16 + "Section 1" 1.17 +); 1.18 + 1.19 +reportCompare( 1.20 + "321", 1.21 + String.prototype.replace.call(123, "123", "321"), 1.22 + "Section 2" 1.23 +); 1.24 + 1.25 +reportCompare( 1.26 + "ok", 1.27 + "ok".replace(), 1.28 + "Section 3" 1.29 +); 1.30 + 1.31 +reportCompare( 1.32 + "undefined**", 1.33 + "***".replace("*"), 1.34 + "Section 4" 1.35 +); 1.36 + 1.37 +reportCompare( 1.38 + "xnullz", 1.39 + "xyz".replace("y", null), 1.40 + "Section 5" 1.41 +); 1.42 + 1.43 +reportCompare( 1.44 + "x123", 1.45 + "xyz".replace("yz", 123), 1.46 + "Section 6" 1.47 +); 1.48 + 1.49 +reportCompare( 1.50 + "/x/g/x/g/x/g", 1.51 + "xxx".replace(/x/g, /x/g), 1.52 + "Section 7" 1.53 +); 1.54 + 1.55 +reportCompare( 1.56 + "ok", 1.57 + "undefined".replace(undefined, "ok"), 1.58 + "Section 8" 1.59 +); 1.60 + 1.61 +reportCompare( 1.62 + "ok", 1.63 + "null".replace(null, "ok"), 1.64 + "Section 9" 1.65 +); 1.66 + 1.67 +reportCompare( 1.68 + "ok", 1.69 + "123".replace(123, "ok"), 1.70 + "Section 10" 1.71 +); 1.72 + 1.73 +reportCompare( 1.74 + "xzyxyz", 1.75 + "xyzxyz".replace("yz", "zy"), 1.76 + "Section 11" 1.77 +); 1.78 + 1.79 +reportCompare( 1.80 + "ok", 1.81 + "(xyz)".replace("(xyz)", "ok"), 1.82 + "Section 12" 1.83 +); 1.84 + 1.85 +reportCompare( 1.86 + "*$&yzxyz", 1.87 + "xyzxyz".replace("x", "*$$&"), 1.88 + "Section 13" 1.89 +); 1.90 + 1.91 +reportCompare( 1.92 + "xy*z*", 1.93 + "xyz".replace("z", "*$&*"), 1.94 + "Section 14" 1.95 +); 1.96 + 1.97 +reportCompare( 1.98 + "xyxyzxyz", 1.99 + "xyzxyzxyz".replace("zxy", "$`"), 1.100 + "Section 15" 1.101 +); 1.102 + 1.103 +reportCompare( 1.104 + "zxyzxyzzxyz", 1.105 + "xyzxyz".replace("xy", "$'xyz"), 1.106 + "Section 16" 1.107 +); 1.108 + 1.109 +reportCompare( 1.110 + "$", 1.111 + "xyzxyz".replace("xyzxyz", "$"), 1.112 + "Section 17" 1.113 +); 1.114 + 1.115 +reportCompare( 1.116 + "x$0$00xyz", 1.117 + "xyzxyz".replace("yz", "$0$00"), 1.118 + "Section 18" 1.119 +); 1.120 + 1.121 +// Result for $1/$01 .. $99 is implementation-defined if searchValue is no 1.122 +// regular expression. $+ is a non-standard Mozilla extension. 1.123 + 1.124 +reportCompare( 1.125 + "$!$\"$-1$*$#$.$xyz$$", 1.126 + "xyzxyz$$".replace("xyz", "$!$\"$-1$*$#$.$"), 1.127 + "Section 19" 1.128 +); 1.129 + 1.130 +reportCompare( 1.131 + "$$$&$$$&$&", 1.132 + "$$$&".replace("$$", "$$$$$$&$&$$&"), 1.133 + "Section 20" 1.134 +); 1.135 + 1.136 +reportCompare( 1.137 + "yxx", 1.138 + "xxx".replace(/x/, "y"), 1.139 + "Section 21" 1.140 +); 1.141 + 1.142 +reportCompare( 1.143 + "yyy", 1.144 + "xxx".replace(/x/g, "y"), 1.145 + "Section 22" 1.146 +); 1.147 + 1.148 +rex = /x/, rex.lastIndex = 1; 1.149 +reportCompare( 1.150 + "yxx1", 1.151 + "xxx".replace(rex, "y") + rex.lastIndex, 1.152 + "Section 23" 1.153 +); 1.154 + 1.155 +rex = /x/g, rex.lastIndex = 1; 1.156 +reportCompare( 1.157 + "yyy0", 1.158 + "xxx".replace(rex, "y") + rex.lastIndex, 1.159 + "Section 24" 1.160 +); 1.161 + 1.162 +rex = /y/, rex.lastIndex = 1; 1.163 +reportCompare( 1.164 + "xxx1", 1.165 + "xxx".replace(rex, "y") + rex.lastIndex, 1.166 + "Section 25" 1.167 +); 1.168 + 1.169 +rex = /y/g, rex.lastIndex = 1; 1.170 +reportCompare( 1.171 + "xxx0", 1.172 + "xxx".replace(rex, "y") + rex.lastIndex, 1.173 + "Section 26" 1.174 +); 1.175 + 1.176 +rex = /x?/, rex.lastIndex = 1; 1.177 +reportCompare( 1.178 + "(x)xx1", 1.179 + "xxx".replace(rex, "($&)") + rex.lastIndex, 1.180 + "Section 27" 1.181 +); 1.182 + 1.183 +rex = /x?/g, rex.lastIndex = 1; 1.184 +reportCompare( 1.185 + "(x)(x)(x)()0", 1.186 + "xxx".replace(rex, "($&)") + rex.lastIndex, 1.187 + "Section 28" 1.188 +); 1.189 + 1.190 +rex = /y?/, rex.lastIndex = 1; 1.191 +reportCompare( 1.192 + "()xxx1", 1.193 + "xxx".replace(rex, "($&)") + rex.lastIndex, 1.194 + "Section 29" 1.195 +); 1.196 + 1.197 +rex = /y?/g, rex.lastIndex = 1; 1.198 +reportCompare( 1.199 + "()x()x()x()0", 1.200 + "xxx".replace(rex, "($&)") + rex.lastIndex, 1.201 + "Section 30" 1.202 +); 1.203 + 1.204 +reportCompare( 1.205 + "xy$0xy$zxy$zxyz$zxyz", 1.206 + "xyzxyzxyz".replace(/zxy/, "$0$`$$$&$$$'$"), 1.207 + "Section 31" 1.208 +); 1.209 + 1.210 +reportCompare( 1.211 + "xy$0xy$zxy$zxyz$$0xyzxy$zxy$z$z", 1.212 + "xyzxyzxyz".replace(/zxy/g, "$0$`$$$&$$$'$"), 1.213 + "Section 32" 1.214 +); 1.215 + 1.216 +reportCompare( 1.217 + "xyxyxyzxyxyxyz", 1.218 + "xyzxyz".replace(/(((x)(y)()()))()()()(z)/g, "$01$2$3$04$5$6$7$8$09$10"), 1.219 + "Section 33" 1.220 +); 1.221 + 1.222 +rex = RegExp( 1.223 + "()()()()()()()()()()" + 1.224 + "()()()()()()()()()()" + 1.225 + "()()()()()()()()()()" + 1.226 + "()()()()()()()()()()" + 1.227 + "()()()()()()()()()()" + 1.228 + "()()()()()()()()()()" + 1.229 + "()()()()()()()()()()" + 1.230 + "()()()()()()()()()()" + 1.231 + "()()()()()()()()()()" + 1.232 + "()()()()()()()()(y)"); 1.233 +reportCompare( 1.234 + "x(y)z", 1.235 + "xyz".replace(rex, "($99)"), 1.236 + "Section 34" 1.237 +); 1.238 + 1.239 +rex = RegExp( 1.240 + "()()()()()()()()()(x)" + 1.241 + "()()()()()()()()()()" + 1.242 + "()()()()()()()()()()" + 1.243 + "()()()()()()()()()()" + 1.244 + "()()()()()()()()()()" + 1.245 + "()()()()()()()()()()" + 1.246 + "()()()()()()()()()()" + 1.247 + "()()()()()()()()()()" + 1.248 + "()()()()()()()()()()" + 1.249 + "()()()()()()()()()(y)"); 1.250 +reportCompare( 1.251 + "(x0)z", 1.252 + "xyz".replace(rex, "($100)"), 1.253 + "Section 35" 1.254 +); 1.255 + 1.256 +reportCompare( 1.257 + "xyz(XYZ)", 1.258 + "xyzXYZ".replace(/XYZ/g, "($&)"), 1.259 + "Section 36" 1.260 +); 1.261 + 1.262 +reportCompare( 1.263 + "(xyz)(XYZ)", 1.264 + "xyzXYZ".replace(/xYz/gi, "($&)"), 1.265 + "Section 37" 1.266 +); 1.267 + 1.268 +reportCompare( 1.269 + "xyz\rxyz\n", 1.270 + "xyz\rxyz\n".replace(/xyz$/g, "($&)"), 1.271 + "Section 38" 1.272 +); 1.273 + 1.274 +reportCompare( 1.275 + "(xyz)\r(xyz)\n", 1.276 + "xyz\rxyz\n".replace(/xyz$/gm, "($&)"), 1.277 + "Section 39" 1.278 +); 1.279 + 1.280 +f = function () { return "failure" }; 1.281 + 1.282 +reportCompare( 1.283 + "ok", 1.284 + "ok".replace("x", f), 1.285 + "Section 40" 1.286 +); 1.287 + 1.288 +reportCompare( 1.289 + "ok", 1.290 + "ok".replace(/(?=k)ok/, f), 1.291 + "Section 41" 1.292 +); 1.293 + 1.294 +reportCompare( 1.295 + "ok", 1.296 + "ok".replace(/(?!)ok/, f), 1.297 + "Section 42" 1.298 +); 1.299 + 1.300 +reportCompare( 1.301 + "ok", 1.302 + "ok".replace(/ok(?!$)/, f), 1.303 + "Section 43" 1.304 +); 1.305 + 1.306 +f = function (sub, offs, str) { 1.307 + return ["", sub, typeof sub, offs, typeof offs, str, typeof str, ""] 1.308 + .join("|"); 1.309 +}; 1.310 + 1.311 +reportCompare( 1.312 + "x|y|string|1|number|xyz|string|z", 1.313 + "xyz".replace("y", f), 1.314 + "Section 44" 1.315 +); 1.316 + 1.317 +reportCompare( 1.318 + "x|(y)|string|1|number|x(y)z|string|z", 1.319 + "x(y)z".replace("(y)", f), 1.320 + "Section 45" 1.321 +); 1.322 + 1.323 +reportCompare( 1.324 + "x|y*|string|1|number|xy*z|string|z", 1.325 + "xy*z".replace("y*", f), 1.326 + "Section 46" 1.327 +); 1.328 + 1.329 +reportCompare( 1.330 + "12|3|string|2|number|12345|string|45", 1.331 + String.prototype.replace.call(1.2345e4, 3, f), 1.332 + "Section 47" 1.333 +); 1.334 + 1.335 +reportCompare( 1.336 + "|x|string|0|number|xxx|string|xx", 1.337 + "xxx".replace(/^x/g, f), 1.338 + "Section 48" 1.339 +); 1.340 + 1.341 +reportCompare( 1.342 + "xx|x|string|2|number|xxx|string|", 1.343 + "xxx".replace(/x$/g, f), 1.344 + "Section 49" 1.345 +); 1.346 + 1.347 +f = function (sub, paren, offs, str) { 1.348 + return ["", sub, typeof sub, paren, typeof paren, offs, typeof offs, 1.349 + str, typeof str, ""].join("|"); 1.350 +}; 1.351 + 1.352 +reportCompare( 1.353 + "xy|z|string|z|string|2|number|xyz|string|", 1.354 + "xyz".replace(/(z)/g, f), 1.355 + "Section 50" 1.356 +); 1.357 + 1.358 +reportCompare( 1.359 + "xyz||string||string|3|number|xyz|string|", 1.360 + "xyz".replace(/($)/g, f), 1.361 + "Section 51" 1.362 +); 1.363 + 1.364 +reportCompare( 1.365 + "|xy|string|y|string|0|number|xyz|string|z", 1.366 + "xyz".replace(/(?:x)(y)/g, f), 1.367 + "Section 52" 1.368 +); 1.369 + 1.370 +reportCompare( 1.371 + "|x|string|x|string|0|number|xyz|string|yz", 1.372 + "xyz".replace(/((?=xy)x)/g, f), 1.373 + "Section 53" 1.374 +); 1.375 + 1.376 +reportCompare( 1.377 + "|x|string|x|string|0|number|xyz|string|yz", 1.378 + "xyz".replace(/(x(?=y))/g, f), 1.379 + "Section 54" 1.380 +); 1.381 + 1.382 +reportCompare( 1.383 + "x|y|string|y|string|1|number|xyz|string|z", 1.384 + "xyz".replace(/((?!x)y)/g, f), 1.385 + "Section 55" 1.386 +); 1.387 + 1.388 +reportCompare( 1.389 + "|x|string|x|string|0|number|xyz|string|" + 1.390 + "|y|string||undefined|1|number|xyz|string|z", 1.391 + "xyz".replace(/y|(x)/g, f), 1.392 + "Section 56" 1.393 +); 1.394 + 1.395 +reportCompare( 1.396 + "xy|z|string||string|2|number|xyz|string|", 1.397 + "xyz".replace(/(z?)z/, f), 1.398 + "Section 57" 1.399 +); 1.400 + 1.401 +reportCompare( 1.402 + "xy|z|string||undefined|2|number|xyz|string|", 1.403 + "xyz".replace(/(z)?z/, f), 1.404 + "Section 58" 1.405 +); 1.406 + 1.407 +reportCompare( 1.408 + "xy|z|string||undefined|2|number|xyz|string|", 1.409 + "xyz".replace(/(z)?\1z/, f), 1.410 + "Section 59" 1.411 +); 1.412 + 1.413 +reportCompare( 1.414 + "xy|z|string||undefined|2|number|xyz|string|", 1.415 + "xyz".replace(/\1(z)?z/, f), 1.416 + "Section 60" 1.417 +); 1.418 + 1.419 +reportCompare( 1.420 + "xy|z|string||string|2|number|xyz|string|", 1.421 + "xyz".replace(/(z?\1)z/, f), 1.422 + "Section 61" 1.423 +); 1.424 + 1.425 +f = function (sub, paren1, paren2, offs, str) { 1.426 + return ["", sub, typeof sub, paren1, typeof paren1, paren2, typeof paren2, 1.427 + offs, typeof offs, str, typeof str, ""].join("|"); 1.428 +}; 1.429 + 1.430 +reportCompare( 1.431 + "x|y|string|y|string||undefined|1|number|xyz|string|z", 1.432 + "xyz".replace(/(y)(\1)?/, f), 1.433 + "Section 62" 1.434 +); 1.435 + 1.436 +reportCompare( 1.437 + "x|yy|string|y|string|y|string|1|number|xyyz|string|z", 1.438 + "xyyz".replace(/(y)(\1)?/g, f), 1.439 + "Section 63" 1.440 +); 1.441 + 1.442 +reportCompare( 1.443 + "x|y|string|y|string||undefined|1|number|xyyz|string|" + 1.444 + "|y|string|y|string||undefined|2|number|xyyz|string|z", 1.445 + "xyyz".replace(/(y)(\1)??/g, f), 1.446 + "Section 64" 1.447 +); 1.448 + 1.449 +reportCompare( 1.450 + "x|y|string|y|string|y|string|1|number|xyz|string|z", 1.451 + "xyz".replace(/(?=(y))(\1)?/, f), 1.452 + "Section 65" 1.453 +); 1.454 + 1.455 +reportCompare( 1.456 + "xyy|z|string||undefined||string|3|number|xyyz|string|", 1.457 + "xyyz".replace(/(?!(y)y)(\1)z/, f), 1.458 + "Section 66" 1.459 +); 1.460 + 1.461 +rex = RegExp( 1.462 + "()()()()()()()()()()" + 1.463 + "()()()()()()()()()()" + 1.464 + "()()()()()()()()()()" + 1.465 + "()()()()()()()()()()" + 1.466 + "()()()()()()()()()()" + 1.467 + "()()()()()()()()()()" + 1.468 + "()()()()()()()()()()" + 1.469 + "()()()()()()()()()()" + 1.470 + "()()()()()()()()()()" + 1.471 + "()()()()()()()()()()(z)?(y)"); 1.472 +a = ["sub"]; 1.473 +for (i = 1; i <= 102; ++i) 1.474 + a[i] = "p" + i; 1.475 +a[103] = "offs"; 1.476 +a[104] = "str"; 1.477 +a[105] = "return ['', sub, typeof sub, offs, typeof offs, str, typeof str, " + 1.478 + "p100, typeof p100, p101, typeof p101, p102, typeof p102, ''].join('|');"; 1.479 +f = Function.apply(null, a); 1.480 +reportCompare( 1.481 + "x|y|string|1|number|xyz|string||string||undefined|y|string|z", 1.482 + "xyz".replace(rex, f), 1.483 + "Section 67" 1.484 +); 1.485 + 1.486 +reportCompare( 1.487 + "undefined", 1.488 + "".replace(/.*/g, function () {}), 1.489 + "Section 68" 1.490 +); 1.491 + 1.492 +reportCompare( 1.493 + "nullxnullynullznull", 1.494 + "xyz".replace(/.??/g, function () { return null; }), 1.495 + "Section 69" 1.496 +); 1.497 + 1.498 +reportCompare( 1.499 + "111", 1.500 + "xyz".replace(/./g, function () { return 1; }), 1.501 + "Section 70" 1.502 +);