Skip to content

Commit

Permalink
[Tests] add more test coverage from tc39/test262#3755
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 20, 2022
1 parent d0f31ef commit 9f9bf60
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

"rules": {
"id-length": 0,
"max-lines-per-function": 0,
"new-cap": [2, {
"capIsNewExceptions": [
"RequireObjectCoercible",
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@
"es-value-fixtures": "^1.4.2",
"eslint": "=8.8.0",
"functions-have-names": "^1.2.3",
"has-bigints": "^1.0.2",
"has-strict-mode": "^1.0.1",
"has-symbols": "^1.0.3",
"in-publish": "^2.0.1",
"mock-property": "^1.0.0",
"npmignore": "^0.3.0",
"nyc": "^10.3.2",
"safe-publish-latest": "^2.0.0",
Expand Down
35 changes: 35 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,47 @@ var v = require('es-value-fixtures');
var forEach = require('for-each');
var inspect = require('object-inspect');
var SymbolDescriptiveString = require('es-abstract/2022/SymbolDescriptiveString');
var mockProperty = require('mock-property');
var hasBigInts = require('has-bigints')();
var hasSymbols = require('has-symbols')();

var leadingPoo = '\uD83D';
var trailingPoo = '\uDCA9';
var wholePoo = leadingPoo + trailingPoo;

module.exports = function (isWellFormed, t) {
t.test('does not call prototype toString methods on primitives', function (st) {
st.teardown(mockProperty(Boolean.prototype, 'toString', function fakeToString() {
st.fail('Boolean.prototype.toString should not be called');
}));
st.teardown(mockProperty(Number.prototype, 'toString', function fakeToString() {
st.fail('Number.prototype.toString should not be called');
}));
if (hasBigInts) {
st.teardown(mockProperty(BigInt.prototype, 'toString', function fakeToString() {
st.fail('BigInt.prototype.toString should not be called');
}));
}
if (hasSymbols) {
st.teardown(mockProperty(Symbol.prototype, 'toString', function fakeToString() {
st.fail('Symbol.prototype.toString should not be called');
}));
}

forEach(v.nonNullPrimitives, function (nonNullPrimitive) {
if (typeof nonNullPrimitive === 'symbol') {
st['throws'](
function () { isWellFormed(nonNullPrimitive); },
inspect(nonNullPrimitive) + ' throws when implicitly coerced to a string, and does not call the proto method'
);
} else if (typeof nonNullPrimitive !== 'string') {
st.equal(isWellFormed(nonNullPrimitive), true, inspect(nonNullPrimitive) + ' stringifies without calling the proto method');
}
});

st.end();
});

t.test('well-formed strings', function (st) {
forEach(v.nonStrings.concat(
v.strings,
Expand Down

0 comments on commit 9f9bf60

Please sign in to comment.