Add clear function to Enumerable{Set,Map} (#5486)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
Arr00
2025-02-10 12:02:43 -05:00
committed by GitHub
parent 441dc141ac
commit 3658269505
10 changed files with 326 additions and 0 deletions

View File

@ -109,6 +109,49 @@ function shouldBehaveLikeSet() {
expect(await this.methods.contains(this.valueB)).to.be.false;
});
});
describe('clear', function () {
it('clears a single value', async function () {
await this.methods.add(this.valueA);
await this.methods.clear();
expect(await this.methods.contains(this.valueA)).to.be.false;
await expectMembersMatch(this.methods, []);
});
it('clears multiple values', async function () {
await this.methods.add(this.valueA);
await this.methods.add(this.valueB);
await this.methods.add(this.valueC);
await this.methods.clear();
expect(await this.methods.contains(this.valueA)).to.be.false;
expect(await this.methods.contains(this.valueB)).to.be.false;
expect(await this.methods.contains(this.valueC)).to.be.false;
await expectMembersMatch(this.methods, []);
});
it('does not revert on empty set', async function () {
await this.methods.clear();
});
it('clear then add value', async function () {
await this.methods.add(this.valueA);
await this.methods.add(this.valueB);
await this.methods.add(this.valueC);
await this.methods.clear();
await this.methods.add(this.valueA);
expect(await this.methods.contains(this.valueA)).to.be.true;
expect(await this.methods.contains(this.valueB)).to.be.false;
expect(await this.methods.contains(this.valueC)).to.be.false;
await expectMembersMatch(this.methods, [this.valueA]);
});
});
}
module.exports = {