forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fleshed out tests for String.p.matchAll, RegExp.p[@@matchall], and %R…
…egExpStringIteratorPrototype% Tests were updated and assuming tc39/proposal-string-matchall#33 will be merged.
- Loading branch information
1 parent
879ecf3
commit 6a87be1
Showing
62 changed files
with
1,815 additions
and
215 deletions.
There are no files selected for viewing
22 changes: 0 additions & 22 deletions
22
test/built-ins/RegExp/prototype/Symbol.matchAll/get-species-constructor-err.js
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
test/built-ins/RegExp/prototype/Symbol.matchAll/internal-regexp-lastindex-not-zero.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: | | ||
Throws TypeError when internally created RegExp's lastIndex is not 0 | ||
info: | | ||
RegExp.prototype [ @@matchAll ] ( string ) | ||
[...] | ||
3. Return ? MatchAllIterator(R, string). | ||
MatchAllIterator ( R, O ) | ||
[...] | ||
2. If ? IsRegExp(R) is true, then | ||
[...] | ||
3. Else, | ||
a. Let matcher be RegExpCreate(R, "g"). | ||
b. If ? IsRegExp(matcher) is not true, throw a TypeError exception. | ||
[...] | ||
3. If Get(matcher, "lastIndex") is not 0, throw a TypeError exception. | ||
features: [Symbol.match, Symbol.matchAll] | ||
---*/ | ||
|
||
const originalMatch = RegExp.prototype[Symbol.match]; | ||
Object.defineProperty(RegExp.prototype, Symbol.match, { | ||
get() { | ||
this.lastIndex = 1; | ||
return true; | ||
} | ||
}); | ||
|
||
try { | ||
assert.throws(TypeError, () => { | ||
RegExp.prototype[Symbol.matchAll].call({}, ''); | ||
}); | ||
} finally { | ||
Object.defineProperty(RegExp.prototype, Symbol.match, { | ||
value: originalMatch | ||
}); | ||
} |
36 changes: 36 additions & 0 deletions
36
test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-internal-regexp-is-false.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: Throws TypeError when internally created RegExp's @@match is false | ||
info: | | ||
RegExp.prototype [ @@matchAll ] ( string ) | ||
[...] | ||
3. Return ? MatchAllIterator(R, string). | ||
MatchAllIterator ( R, O ) | ||
[...] | ||
2. If ? IsRegExp(R) is true, then | ||
[...] | ||
3. Else, | ||
a. Let matcher be RegExpCreate(R, "g"). | ||
b. If ? IsRegExp(matcher) is not true, throw a TypeError exception. | ||
features: [Symbol.match, Symbol.matchAll] | ||
---*/ | ||
|
||
const originalMatch = RegExp.prototype[Symbol.match]; | ||
Object.defineProperty(RegExp.prototype, Symbol.match, { | ||
get() { | ||
return false; | ||
} | ||
}); | ||
|
||
try { | ||
assert.throws(TypeError, () => { | ||
RegExp.prototype[Symbol.matchAll].call({}, ''); | ||
}); | ||
} finally { | ||
Object.defineProperty(RegExp.prototype, Symbol.match, { | ||
value: originalMatch | ||
}); | ||
} |
36 changes: 36 additions & 0 deletions
36
test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-internal-regexp-throws.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: Re-throw errors from during retrieval of @@match property | ||
info: | | ||
RegExp.prototype [ @@matchAll ] ( string ) | ||
[...] | ||
3. Return ? MatchAllIterator(R, string). | ||
MatchAllIterator ( R, O ) | ||
[...] | ||
2. If ? IsRegExp(R) is true, then | ||
[...] | ||
3. Else, | ||
a. Let matcher be RegExpCreate(R, "g"). | ||
b. If ? IsRegExp(matcher) is not true, throw a TypeError exception. | ||
features: [Symbol.match, Symbol.matchAll] | ||
---*/ | ||
|
||
const originalMatch = RegExp.prototype[Symbol.match]; | ||
Object.defineProperty(RegExp.prototype, Symbol.match, { | ||
get() { | ||
throw new Test262Error(); | ||
} | ||
}); | ||
|
||
try { | ||
assert.throws(Test262Error, () => { | ||
RegExp.prototype[Symbol.matchAll].call({}, ''); | ||
}); | ||
} finally { | ||
Object.defineProperty(RegExp.prototype, Symbol.match, { | ||
value: originalMatch | ||
}); | ||
} |
26 changes: 26 additions & 0 deletions
26
test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-this-throws.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: Re-throw errors from regexp's @@match getter | ||
info: | | ||
RegExp.prototype [ @@matchAll ] ( string ) | ||
[...] | ||
3. Return ? MatchAllIterator(R, string). | ||
MatchAllIterator ( R, O ) | ||
[...] | ||
2. If ? IsRegExp(R) is true, then | ||
[...] | ||
features: [Symbol.match, Symbol.matchAll] | ||
---*/ | ||
|
||
const obj = { | ||
get [Symbol.match]() { | ||
throw new Test262Error(); | ||
} | ||
}; | ||
|
||
assert.throws(Test262Error, () => { | ||
RegExp.prototype[Symbol.matchAll].call(obj, ''); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
test/built-ins/RegExp/prototype/Symbol.matchAll/regexpcreate-this-throws.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: Re-throw errors from creating internal RegExp | ||
info: | | ||
RegExp.prototype [ @@matchAll ] ( string ) | ||
[...] | ||
3. Return ? MatchAllIterator(R, string). | ||
MatchAllIterator ( R, O ) | ||
[...] | ||
2. If ? IsRegExp(R) is true, then | ||
[...] | ||
3. Else, | ||
a. Let R be RegExpCreate(R, "g"). | ||
features: [Symbol.matchAll] | ||
---*/ | ||
|
||
const obj = { | ||
toString() { | ||
throw new Test262Error(); | ||
} | ||
}; | ||
|
||
assert.throws(Test262Error, function() { | ||
RegExp.prototype[Symbol.matchAll].call(obj, ''); | ||
}); | ||
|
32 changes: 32 additions & 0 deletions
32
.../built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-get-constructor-throws.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: | | ||
Re-throw errors from RegExp's constructor getter | ||
info: | | ||
RegExp.prototype [ @@matchAll ] ( string ) | ||
[...] | ||
3. Return ? MatchAllIterator(R, string). | ||
MatchAllIterator ( R, O ) | ||
[...] | ||
2. If ? IsRegExp(R) is true, then | ||
a. Let C be ? SpeciesConstructor(R, RegExp). | ||
SpeciesConstructor ( O, defaultConstructor ) | ||
[...] | ||
2. Let C be ? Get(O, "constructor"). | ||
features: [Symbol.matchAll] | ||
---*/ | ||
|
||
const regexp = /./; | ||
Object.defineProperty(regexp, 'constructor', { | ||
get(){ | ||
throw new Test262Error(); | ||
} | ||
}); | ||
|
||
assert.throws(Test262Error, () => { | ||
regexp[Symbol.matchAll](''); | ||
}); |
31 changes: 31 additions & 0 deletions
31
test/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-get-species-throws.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: Re-throw errors from during retrieval of @@species property | ||
info: | | ||
RegExp.prototype [ @@matchAll ] ( string ) | ||
[...] | ||
3. Return ? MatchAllIterator(R, string). | ||
MatchAllIterator ( R, O ) | ||
[...] | ||
2. If ? IsRegExp(R) is true, then | ||
a. Let C be ? SpeciesConstructor(R, RegExp). | ||
SpeciesConstructor ( O, defaultConstructor ) | ||
[...] | ||
2. Let C be ? Get(O, "constructor"). | ||
features: [Symbol.matchAll, Symbol.species] | ||
---*/ | ||
|
||
const regexp = /./; | ||
regexp.constructor = { | ||
get [Symbol.species]() { | ||
throw new Test262Error(); | ||
} | ||
}; | ||
|
||
assert.throws(Test262Error, () => { | ||
regexp[Symbol.matchAll](''); | ||
}); |
41 changes: 41 additions & 0 deletions
41
test/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-is-not-object-throws.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: Throws TypeError if `constructor` property is not an object | ||
info: | | ||
RegExp.prototype [ @@matchAll ] ( string ) | ||
[...] | ||
3. Return ? MatchAllIterator(R, string). | ||
MatchAllIterator ( R, O ) | ||
[...] | ||
2. If ? IsRegExp(R) is true, then | ||
a. Let C be ? SpeciesConstructor(R, RegExp). | ||
SpeciesConstructor ( O, defaultConstructor ) | ||
[...] | ||
2. Let C be ? Get(O, "constructor"). | ||
3. If C is undefined, return defaultConstructor. | ||
4. If Type(C) is not Object, throw a TypeError exception. | ||
features: [Symbol.matchAll] | ||
---*/ | ||
|
||
const regexp = /./; | ||
|
||
function callMatchAll() { regexp[Symbol.matchAll](''); } | ||
|
||
regexp.constructor = null; | ||
assert.throws(TypeError, callMatchAll, "`constructor` value is null"); | ||
|
||
regexp.constructor = true; | ||
assert.throws(TypeError, callMatchAll, "`constructor` value is Boolean"); | ||
|
||
regexp.constructor = ""; | ||
assert.throws(TypeError, callMatchAll, "`constructor` value is String"); | ||
|
||
regexp.constructor = Symbol(); | ||
assert.throws(TypeError, callMatchAll, "`constructor` value is Symbol"); | ||
|
||
regexp.constructor = 1; | ||
assert.throws(TypeError, callMatchAll, "`constructor` value is Number"); |
Oops, something went wrong.