Skip to content

Commit

Permalink
[Tests] add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 25, 2023
1 parent e16074b commit d344bb0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"evalmd": "^0.0.19",
"for-each": "^0.3.3",
"functions-have-names": "^1.2.3",
"has-property-descriptors": "^1.0.1",
"has-strict-mode": "^1.0.1",
"in-publish": "^2.0.1",
"npmignore": "^0.3.0",
Expand Down
61 changes: 61 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var $Set = require('es-set/polyfill')();
var forEach = require('for-each');
var v = require('es-value-fixtures');
var debug = require('object-inspect');
var hasPropertyDescriptors = require('has-property-descriptors')();

module.exports = function (isSubsetOf, t) {
t.test('throws on non-set receivers', function (st) {
Expand Down Expand Up @@ -81,6 +82,66 @@ module.exports = function (isSubsetOf, t) {
st.end();
});

t.test('test262: setlike with equal size', function (st) {
var setLike = {
arr: [42, 44, 45],
size: 3,
keys: function () {
return this.arr[Symbol.iterator]();
},
has: function (key) {
return this.arr.indexOf(key) !== -1;
}
};

var firstSet = new $Set([42, 43, 45]);

st.equal(isSubsetOf(firstSet, setLike), false);

st.end();
});

t.test('test262: set method receiver is cleared', { skip: !hasPropertyDescriptors }, function (st) {
var firstSet = new $Set([42, 43]);

var otherSet = new $Set([42, 43, 47]);

Object.defineProperty(otherSet, 'size', {
get: function () {
firstSet.clear();
return 3;
}
});

st.equal(isSubsetOf(firstSet, otherSet), true);

st.end();
});

t.test('test262: set method after table transition in receiver', function (st) {
var firstSet = new Set([42, 43, 44]);

var setLike = {
size: 5,
keys: function () {
return [1, 2, 3, 4, 5].keys();
},
has: function (key) {
if (key === 42) {
// Cause a table transition in the receiver.
firstSet.clear();
}
// Return true so we keep iterating the transitioned receiver.
return true;
}
};

st.equal(firstSet.isSubsetOf(setLike), true);
st.equal(firstSet.size, 0);

st.end();
});

t.test('subsets', function (st) {
var set1 = new $Set([1, 2, 3]);
var set2 = new $Set([4, 5, 6]);
Expand Down

0 comments on commit d344bb0

Please sign in to comment.