-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
String.prototype.isWellFormed
/String.prototype.toWellFormed
: add …
…tests
- Loading branch information
Showing
15 changed files
with
402 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (C) 2022 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-string.prototype.iswellformed | ||
description: > | ||
String.prototype.isWellFormed.length value and descriptor. | ||
info: | | ||
String.prototype.isWellFormed( ) | ||
17 ECMAScript Standard Built-in Objects | ||
includes: [propertyHelper.js] | ||
features: [String.prototype.isWellFormed] | ||
---*/ | ||
|
||
verifyProperty(String.prototype.isWellFormed, 'length', { | ||
configurable: true, | ||
enumerable: false, | ||
writable: false, | ||
value: 0 | ||
}); |
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,21 @@ | ||
// Copyright (C) 2022 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-string.prototype.iswellformed | ||
description: > | ||
String.prototype.isWellFormed.name value and descriptor. | ||
info: | | ||
String.prototype.isWellFormed( ) | ||
17 ECMAScript Standard Built-in Objects | ||
includes: [propertyHelper.js] | ||
features: [String.prototype.isWellFormed] | ||
---*/ | ||
|
||
verifyProperty(String.prototype.isWellFormed, 'name', { | ||
enumerable: false, | ||
writable: false, | ||
configurable: true, | ||
value: 'isWellFormed' | ||
}); |
32 changes: 32 additions & 0 deletions
32
test/built-ins/String/prototype/isWellFormed/not-a-constructor.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) 2022 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-ecmascript-standard-built-in-objects | ||
description: > | ||
String.prototype.includes does not implement [[Construct]], is not new-able | ||
info: | | ||
ECMAScript Function Objects | ||
Built-in function objects that are not identified as constructors do not | ||
implement the [[Construct]] internal method unless otherwise specified in | ||
the description of a particular function. | ||
sec-evaluatenew | ||
... | ||
7. If IsConstructor(constructor) is false, throw a TypeError exception. | ||
... | ||
includes: [isConstructor.js] | ||
features: [String.prototype.isWellFormed, Reflect.construct] | ||
---*/ | ||
|
||
assert.sameValue( | ||
isConstructor(String.prototype.isWellFormed), | ||
false, | ||
'isConstructor(String.prototype.isWellFormed) must return false' | ||
); | ||
|
||
assert.throws(TypeError, function () { | ||
new String.prototype.isWellFormed(); | ||
}, '`new String.prototype.isWellFormed()` throws TypeError'); |
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) 2022 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-string.prototype.iswellformed | ||
description: > | ||
Property type and descriptor. | ||
info: | | ||
String.prototype.isWellFormed( ) | ||
17 ECMAScript Standard Built-in Objects | ||
includes: [propertyHelper.js] | ||
features: [String.prototype.isWellFormed] | ||
---*/ | ||
assert.sameValue(typeof String.prototype.isWellFormed, 'function'); | ||
|
||
assert.sameValue( | ||
typeof String.prototype.isWellFormed, | ||
'function', | ||
'The value of `typeof String.prototype.isWellFormed` is "function"' | ||
); | ||
|
||
verifyProperty(String.prototype, 'isWellFormed', { | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
}); |
22 changes: 22 additions & 0 deletions
22
test/built-ins/String/prototype/isWellFormed/return-abrupt-from-this.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,22 @@ | ||
// Copyright (C) 2022 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-string.prototype.iswellformed | ||
description: > | ||
Return abrupt from RequireObjectCoercible(this value). | ||
info: | | ||
String.prototype.isWellFormed( ) | ||
1. Let O be ? RequireObjectCoercible(this value). | ||
features: [String.prototype.isWellFormed] | ||
---*/ | ||
assert.sameValue(typeof String.prototype.isWellFormed, 'function'); | ||
|
||
assert.throws(TypeError, function () { | ||
String.prototype.isWellFormed.call(undefined); | ||
}, '`String.prototype.isWellFormed.call(undefined)` throws TypeError'); | ||
|
||
assert.throws(TypeError, function () { | ||
String.prototype.isWellFormed.call(null); | ||
}, '`String.prototype.isWellFormed.call(null)` throws TypeError'); |
44 changes: 44 additions & 0 deletions
44
test/built-ins/String/prototype/isWellFormed/returns-boolean.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,44 @@ | ||
// Copyright (C) 2022 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-string.prototype.iswellformed | ||
description: > | ||
The method should return a boolean. | ||
info: | | ||
String.prototype.isWellFormed ( ) | ||
1. Let O be ? RequireObjectCoercible(this value). | ||
2. Let S be ? ToString(O). | ||
3. Return IsStringWellFormedUnicode(S). | ||
features: [String.prototype.isWellFormed] | ||
---*/ | ||
assert.sameValue(typeof String.prototype.isWellFormed, 'function'); | ||
|
||
var leadingPoo = '\uD83D'; | ||
var trailingPoo = '\uDCA9'; | ||
var wholePoo = leadingPoo + trailingPoo; | ||
|
||
assert.sameValue( | ||
('a' + leadingPoo + 'c' + leadingPoo + 'e').isWellFormed(), | ||
false, | ||
'lone leading surrogates are not well-formed' | ||
); | ||
assert.sameValue( | ||
('a' + trailingPoo + 'c' + trailingPoo + 'e').isWellFormed(), | ||
false, | ||
'lone trailing surrogates are not well-formed' | ||
); | ||
assert.sameValue( | ||
('a' + trailingPoo + leadingPoo + 'd').isWellFormed(), | ||
false, | ||
'a wrong-ordered surrogate pair is not well-formed' | ||
) | ||
|
||
assert.sameValue('a💩c'.isWellFormed(), true, 'a surrogate pair using a literal code point is well-formed'); | ||
assert.sameValue('a\uD83D\uDCA9c'.isWellFormed(), true, 'a surrogate pair formed by escape sequences is well-formed'); | ||
assert.sameValue(('a' + leadingPoo + trailingPoo + 'd').isWellFormed(), true, 'a surrogate pair formed by concatenation is well-formed'); | ||
assert.sameValue(wholePoo.slice(0, 1).isWellFormed(), false, 'a surrogate pair sliced to the leading surrogate is not well-formed'); | ||
assert.sameValue(wholePoo.slice(1).isWellFormed(), false, 'a surrogate pair sliced to the trailing surrogate is not well-formed'); | ||
assert.sameValue('abc'.isWellFormed(), true, 'a latin-1 string is well-formed'); | ||
assert.sameValue('a\u25A8c'.isWellFormed(), true, 'a non-ASCII character is well-formed'); |
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,27 @@ | ||
// Copyright (C) 2022 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-string.prototype.iswellformed | ||
description: > | ||
The method should coerce the receiver to a string. | ||
info: | | ||
String.prototype.isWellFormed ( ) | ||
1. Let O be ? RequireObjectCoercible(this value). | ||
2. Let S be ? ToString(O). | ||
3. Return IsStringWellFormedUnicode(S). | ||
features: [String.prototype.isWellFormed] | ||
---*/ | ||
|
||
var obj = { | ||
toString: function () { | ||
throw new Test262Error('calls ToString'); | ||
} | ||
}; | ||
|
||
asserts.throws( | ||
function () { String.prototype.isWellFormed.call(obj); }, | ||
Test262Error, | ||
'coerces the receiver to a string' | ||
); |
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,21 @@ | ||
// Copyright (C) 2022 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-string.prototype.towellformed | ||
description: > | ||
String.prototype.toWellFormed.length value and descriptor. | ||
info: | | ||
String.prototype.toWellFormed( ) | ||
17 ECMAScript Standard Built-in Objects | ||
includes: [propertyHelper.js] | ||
features: [String.prototype.toWellFormed] | ||
---*/ | ||
|
||
verifyProperty(String.prototype.toWellFormed, 'length', { | ||
configurable: true, | ||
enumerable: false, | ||
writable: false, | ||
value: 0 | ||
}); |
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,21 @@ | ||
// Copyright (C) 2022 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-string.prototype.towellformed | ||
description: > | ||
String.prototype.toWellFormed.name value and descriptor. | ||
info: | | ||
String.prototype.toWellFormed( ) | ||
17 ECMAScript Standard Built-in Objects | ||
includes: [propertyHelper.js] | ||
features: [String.prototype.toWellFormed] | ||
---*/ | ||
|
||
verifyProperty(String.prototype.toWellFormed, 'name', { | ||
enumerable: false, | ||
writable: false, | ||
configurable: true, | ||
value: 'isWellFormed' | ||
}); |
32 changes: 32 additions & 0 deletions
32
test/built-ins/String/prototype/toWellFormed/not-a-constructor.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) 2022 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-ecmascript-standard-built-in-objects | ||
description: > | ||
String.prototype.includes does not implement [[Construct]], is not new-able | ||
info: | | ||
ECMAScript Function Objects | ||
Built-in function objects that are not identified as constructors do not | ||
implement the [[Construct]] internal method unless otherwise specified in | ||
the description of a particular function. | ||
sec-evaluatenew | ||
... | ||
7. If IsConstructor(constructor) is false, throw a TypeError exception. | ||
... | ||
includes: [isConstructor.js] | ||
features: [String.prototype.toWellFormed, Reflect.construct] | ||
---*/ | ||
|
||
assert.sameValue( | ||
isConstructor(String.prototype.toWellFormed), | ||
false, | ||
'isConstructor(String.prototype.toWellFormed) must return false' | ||
); | ||
|
||
assert.throws(TypeError, function () { | ||
new String.prototype.toWellFormed(); | ||
}, '`new String.prototype.toWellFormed()` throws TypeError'); |
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) 2022 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-string.prototype.towellformed | ||
description: > | ||
Property type and descriptor. | ||
info: | | ||
String.prototype.toWellFormed( ) | ||
17 ECMAScript Standard Built-in Objects | ||
includes: [propertyHelper.js] | ||
features: [String.prototype.toWellFormed] | ||
---*/ | ||
assert.sameValue(typeof String.prototype.toWellFormed, 'function'); | ||
|
||
assert.sameValue( | ||
typeof String.prototype.isWellFormed, | ||
'function', | ||
'The value of `typeof String.prototype.toWellFormed` is "function"' | ||
); | ||
|
||
verifyProperty(String.prototype, 'toWellFormed', { | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
}); |
22 changes: 22 additions & 0 deletions
22
test/built-ins/String/prototype/toWellFormed/return-abrupt-from-this.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,22 @@ | ||
// Copyright (C) 2022 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-string.prototype.towellformed | ||
description: > | ||
Return abrupt from RequireObjectCoercible(this value). | ||
info: | | ||
String.prototype.toWellFormed( ) | ||
1. Let O be ? RequireObjectCoercible(this value). | ||
features: [String.prototype.toWellFormed] | ||
---*/ | ||
assert.sameValue(typeof String.prototype.toWellFormed, 'function'); | ||
|
||
assert.throws(TypeError, function () { | ||
String.prototype.toWellFormed.call(undefined); | ||
}, '`String.prototype.toWellFormed.call(undefined)` throws TypeError'); | ||
|
||
assert.throws(TypeError, function () { | ||
String.prototype.toWellFormed.call(null); | ||
}, '`String.prototype.toWellFormed.call(null)` throws TypeError'); |
Oops, something went wrong.