mirror of https://github.com/tc39/test262.git
Merge pull request #369 from littledan/master
Reinforce test for the use of ToLength(lastIndex) in RegExp
This commit is contained in:
commit
d54ff00df2
|
@ -1,38 +1,38 @@
|
||||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
/*---
|
/*---
|
||||||
info: >
|
info: >
|
||||||
RegExp.prototype.exec behavior depends on global property.
|
RegExp.prototype.exec behavior depends on the lastIndex property:
|
||||||
Let global is true and let I = If ToLength(lastIndex).
|
ToLength(lastIndex) is the starting point for the search, so
|
||||||
Then if I>length then set lastIndex to 0 and return null
|
negative numbers result in searching from 0.
|
||||||
es5id: 15.10.6.2_A5_T3
|
es5id: 15.10.6.2_A5_T3
|
||||||
description: "Set lastIndex to -1 and call /(?:ab|cd)\\d?/g.exec(\"aacd22 \")"
|
description: "Set lastIndex to -1 and call /(?:ab|cd)\\d?/g.exec(\"aacd22 \")"
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
var __re = /(?:ab|cd)\d?/g;
|
var __re = /(?:ab|cd)\d?/g;
|
||||||
__re.lastIndex=-1;
|
__re.lastIndex=-1;
|
||||||
var __executed = __re.test("aacd22 ");
|
var __executed = __re.exec("aacd22 ");
|
||||||
|
|
||||||
//CHECK#1
|
//CHECK#1
|
||||||
if (!__executed) {
|
if (__executed[0] !== "cd2") {
|
||||||
$ERROR('#1: __re = /(?:ab|cd)\\d?/g; __re.lastIndex=-1; __executed = __re.test("aacd22 "); __executed === true');
|
$ERROR('#1: __re = /(?:ab|cd)\\d?/g; __re.lastIndex=-1; __executed = __re.exec("aacd22 "); __executed[0] === "cd2"');
|
||||||
}
|
}
|
||||||
|
|
||||||
//CHECK#2
|
//CHECK#2
|
||||||
if (__re.lastIndex !== 5) {
|
if (__re.lastIndex !== 5) {
|
||||||
$ERROR('#2: __re = /(?:ab|cd)\\d?/g; __re.lastIndex=-1; __executed = __re.test("aacd22 "); __re.lastIndex === 5. Actual: ' + (__re.lastIndex));
|
$ERROR('#2: __re = /(?:ab|cd)\\d?/g; __re.lastIndex=-1; __executed = __re.exec("aacd22 "); __re.lastIndex === 5. Actual: ' + (__re.lastIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
__re.lastIndex=-100;
|
__re.lastIndex=-100;
|
||||||
__executed = __re.test("aacd22 ");
|
__executed = __re.exec("aacd22 ");
|
||||||
|
|
||||||
//CHECK#3
|
//CHECK#3
|
||||||
if (!__executed) {
|
if (__executed[0] !== "cd2") {
|
||||||
$ERROR('#3: __re = /(?:ab|cd)\\d?/g; __re.lastIndex=-1; __executed = __re.test("aacd22 "); __re.lastIndex=-100; __executed = __re.test("aacd22 "); __executed === true');
|
$ERROR('#3: __re = /(?:ab|cd)\\d?/g; __re.lastIndex=-1; __executed = __re.exec("aacd22 "); __re.lastIndex=-100; __executed = __re.exec("aacd22 "); __executed[0] === "cd2"');
|
||||||
}
|
}
|
||||||
|
|
||||||
//CHECK#4
|
//CHECK#4
|
||||||
if (__re.lastIndex !== 5) {
|
if (__re.lastIndex !== 5) {
|
||||||
$ERROR('#4: __re = /(?:ab|cd)\\d?/g; __re.lastIndex=-1; __executed = __re.test("aacd22 "); __re.lastIndex=-100; __executed = __re.test("aacd22 "); __re.lastIndex === 5. Actual: ' + (__re.lastIndex));
|
$ERROR('#4: __re = /(?:ab|cd)\\d?/g; __re.lastIndex=-1; __executed = __re.exec("aacd22 "); __re.lastIndex=-100; __executed = __re.exec("aacd22 "); __re.lastIndex === 5. Actual: ' + (__re.lastIndex));
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
info: >
|
||||||
|
RegExp.prototype.test behavior depends on the lastIndex property:
|
||||||
|
ToLength(lastIndex) is the starting point for the search, so
|
||||||
|
negative numbers result in searching from 0.
|
||||||
|
es5id: 15.10.6.3_A1_T22
|
||||||
|
description: "Set lastIndex to -1 and call /(?:ab|cd)\\d?/g.test(\"aacd22 \")"
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var __re = /(?:ab|cd)\d?/g;
|
||||||
|
__re.lastIndex=-1;
|
||||||
|
var __executed = __re.test("aacd22 ");
|
||||||
|
|
||||||
|
//CHECK#1
|
||||||
|
if (!__executed) {
|
||||||
|
$ERROR('#1: __re = /(?:ab|cd)\\d?/g; __re.lastIndex=-1; __executed = __re.test("aacd22 "); __executed === true');
|
||||||
|
}
|
||||||
|
|
||||||
|
//CHECK#2
|
||||||
|
if (__re.lastIndex !== 5) {
|
||||||
|
$ERROR('#2: __re = /(?:ab|cd)\\d?/g; __re.lastIndex=-1; __executed = __re.test("aacd22 "); __re.lastIndex === 5. Actual: ' + (__re.lastIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
__re.lastIndex=-100;
|
||||||
|
__executed = __re.test("aacd22 ");
|
||||||
|
|
||||||
|
//CHECK#3
|
||||||
|
if (!__executed) {
|
||||||
|
$ERROR('#3: __re = /(?:ab|cd)\\d?/g; __re.lastIndex=-1; __executed = __re.test("aacd22 "); __re.lastIndex=-100; __executed = __re.test("aacd22 "); __executed === true');
|
||||||
|
}
|
||||||
|
|
||||||
|
//CHECK#4
|
||||||
|
if (__re.lastIndex !== 5) {
|
||||||
|
$ERROR('#4: __re = /(?:ab|cd)\\d?/g; __re.lastIndex=-1; __executed = __re.test("aacd22 "); __re.lastIndex=-100; __executed = __re.test("aacd22 "); __re.lastIndex === 5. Actual: ' + (__re.lastIndex));
|
||||||
|
}
|
Loading…
Reference in New Issue