-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests for Set methods #3738
Comments
Hello @bakkot thanks for this issue! I'm a first time contributor to test262, in the process of writing some tests for these features (see #3816 ) and am also cross-referencing this todo list as I look to add more tests. Forgive my ignorance, but I had a question about:
Is that related to this section in the Being very new to this process, I was wondering if something like that needs to be explicitly called out in the spec or if it's common to just keep it in something like Thank you 🙂 |
Yup.
It doesn't need to be called out in the spec - it's something you can conclude already from looking at the algorithm and seeing that it does not invoke I usually try to call these things out in a separate document, but not all proposals will have such a thing. |
Thank you very much for the context! |
#3816 implements the following for
I don't think this applies to
I'm not entirely sure I understand this one.
I don't think I fully understand this one, sorry. Any insights on the above would be helpful. Thank you! |
The second half of the original bullet doesn't apply to What this means is that if you pass something which is not a Set as an argument to function observableIterator() {
let values = ['a', 'b'];
let index = 0;
return {
get next() {
console.log('getting next');
return function () {
console.log('calling next');
return {
get done() {
console.log('getting done');
return index >= values.length;
},
get value() {
console.log('getting value');
return values[index++];
},
};
};
},
};
}
let observableSetLike = {
get size() {
console.log('getting size');
return {
valueOf() {
console.log('coercing size');
return 2;
},
};
},
get has() {
console.log('getting has');
return function (arg) {
console.log('looking up', arg);
return arg === 'a' || arg === 'b';
};
},
get keys() {
console.log('getting keys');
return function () {
console.log('calling keys');
return observableIterator();
};
},
};
new Set().union(observableSetLike); // prints a whole bunch of stuff and ultimately ends up with a Set holding two elements 'a' and 'b'
The "receiver" is the thing on which a method is invoked. So for example this method should throw when invoked with the Set.prototype.union.call(observableSetLike, new Set); // throws, doesn't print anything
As above, you can have something like let baseSet = new Set(['a', 'b', 'c', 'd', 'e']);
function mutatingIterator() {
let index = 0;
let values = ['x', 'y'];
return {
next() {
baseSet.delete('b');
baseSet.delete('c');
baseSet.add('b');
baseSet.add('d');
return {
done: index >= 2,
value: values[index++],
};
},
};
}
let evilSetLike = {
size: 2,
has() {
throw new Error('should not be invoked in this case example');
},
keys() {
return mutatingIterator();
},
};
console.log([...baseSet.union(evilSetLike)]); // ['a', 'b', 'c', 'd', 'e', 'x', 'y']
console.log([...baseSet]); // ['a', 'd', 'e', 'b'] The bit to note here is that |
@bakkot thank you very much for those examples! I added those tests in this commit and additionally added your name to the copyright as I mostly used your example code to write them. (Let me know if you want me to remove that attribution, though - I'll do what you feel is best). I think that wraps it up for |
Ref #3949 |
The Set methods proposal is now stage 3 (🎉 ). That means it's time for tests! Here's the things which occur to me offhand; feel free to edit this issue to add more.
size
/has
/keys
size
orhas
orkeys
size
is, or coerces to,NaN
has
orkeys
is non-callablesize
,has
, orkeys
properties, nor those ofSet.prototype
union
,intersection
,difference
,symmetricDifference
Set.prototype.add
to construct the result (testing this requires mutatingSet.prototype
)This list previously included a special case for a sorting step in
intersection
, but that step was removed in tc39/proposal-set-methods#94. The new behavior should now be covered by the "order of the result, both when the receiver is smaller and larger than the argument" case above.The text was updated successfully, but these errors were encountered: