Skip to content

Commit

Permalink
String.prototype.isWellFormed/String.prototype.toWellFormed: add …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
ljharb committed Sep 14, 2022
1 parent 8f19bb4 commit 9496643
Show file tree
Hide file tree
Showing 15 changed files with 423 additions and 1 deletion.
7 changes: 6 additions & 1 deletion features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ decorators
# https://github.com/tc39/proposal-duplicate-named-capturing-groups
regexp-duplicate-named-groups

# Well-formed Unicode strings
# https://github.com/tc39/proposal-is-usv-string
String.prototype.isWellFormed
String.prototype.toWellFormed

## Standard language features
#
# Language features that have been included in a published version of the
Expand Down Expand Up @@ -377,4 +382,4 @@ __setter__
# object, go here.

IsHTMLDDA
host-gc-required
host-gc-required
24 changes: 24 additions & 0 deletions test/built-ins/String/prototype/isWellFormed/length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.is-well-formed
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]
---*/
assert.sameValue(typeof String.prototype.isWellFormed, 'function');

assert.sameValue(
String.prototype.isWellFormed.length, 0,
'The value of String.prototype.isWellFormed.length is 0'
);

verifyNotEnumerable(String.prototype.isWellFormed, 'length');
verifyNotWritable(String.prototype.isWellFormed, 'length');
verifyConfigurable(String.prototype.isWellFormed, 'length');
26 changes: 26 additions & 0 deletions test/built-ins/String/prototype/isWellFormed/name.js
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.is-well-formed
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]
---*/
assert.sameValue(typeof String.prototype.isWellFormed, 'function');

assert.sameValue(
String.prototype.isWellFormed.name, 'isWellFormed',
'The value of String.prototype.isWellFormed.name is "isWellFormed"'
);

verifyProperty(String.prototype.isWellFormed, 'name', {
enumerable: false,
writable: false,
configurable: true
});
34 changes: 34 additions & 0 deletions test/built-ins/String/prototype/isWellFormed/not-a-constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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: [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');


26 changes: 26 additions & 0 deletions test/built-ins/String/prototype/isWellFormed/prop-desc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-string.prototype.is-well-formed
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
});
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.is-well-formed
description: >
Return abrupt from RequireObjectCoercible(this value).
info: |
String.prototype.isWellFormed( )
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 test/built-ins/String/prototype/isWellFormed/returns-boolean.js
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.at
description: >
The method should return an Iterator instance.
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,
'leading lone surrogates are not well-formed'
);
assert.sameValue(
('a' + trailingPoo + 'c' + trailingPoo + 'e').isWellFormed(),
false,
'trailing lone surrogates are not well-formed'
);
assert.sameValue(
('a' + leadingPoo + trailingPoo + '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');
27 changes: 27 additions & 0 deletions test/built-ins/String/prototype/isWellFormed/to-string.js
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 return an Iterator instance.
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'
);
24 changes: 24 additions & 0 deletions test/built-ins/String/prototype/toWellFormed/length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.to-well-formed
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]
---*/
assert.sameValue(typeof String.prototype.toWellFormed, 'function');

assert.sameValue(
String.prototype.toWellFormed.length, 0,
'The value of String.prototype.toWellFormed.length is 0'
);

verifyNotEnumerable(String.prototype.toWellFormed, 'length');
verifyNotWritable(String.prototype.toWellFormed, 'length');
verifyConfigurable(String.prototype.toWellFormed, 'length');
26 changes: 26 additions & 0 deletions test/built-ins/String/prototype/toWellFormed/name.js
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.to-well-formed
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]
---*/
assert.sameValue(typeof String.prototype.toWellFormed, 'function');

assert.sameValue(
String.prototype.toWellFormed.name, 'isWellFormed',
'The value of String.prototype.toWellFormed.name is "toWellFormed"'
);

verifyProperty(String.prototype.toWellFormed, 'name', {
enumerable: false,
writable: false,
configurable: true
});
34 changes: 34 additions & 0 deletions test/built-ins/String/prototype/toWellFormed/not-a-constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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: [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');


26 changes: 26 additions & 0 deletions test/built-ins/String/prototype/toWellFormed/prop-desc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-string.prototype.is-well-formed
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
});
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.to-well-formed
description: >
Return abrupt from RequireObjectCoercible(this value).
info: |
String.prototype.toWellFormed( )
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');
Loading

0 comments on commit 9496643

Please sign in to comment.