Skip to content

Commit

Permalink
Merge pull request #486 from canjs/i468-multiple-entries-support
Browse files Browse the repository at this point in the history
weak-reference-set does mutiple entries support
  • Loading branch information
cherifGsoul authored Jul 8, 2019
2 parents c1cbcfd + 7590a4b commit 4d3dd31
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions helpers/helpers_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require("./map-deep-merge-test");
require("./weak-reference-set-test");

var idMerge = require("./id-merge");

Expand Down
39 changes: 39 additions & 0 deletions helpers/weak-reference-set-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var QUnit = require('steal-qunit');
var WeakReferenceSet = require('./weak-reference-set');

QUnit.module("weak-reference-set");

QUnit.test("Multiple entries support #468", function(assert) {
var set = new WeakReferenceSet();

var item1 = {};
var item2 = {};
var item3 = {};

var items = [item1, item2, item3];

for (var index = 0; index < items.length; index++) {
set.addReference(items[index]);
}

assert.equal(set.get(item1), item1, "Got the first item");
assert.equal(set.get(item2), item2, "Got the second item");
assert.equal(set.get(item3), item3, "Got the third item");
});

QUnit.test("Multiple entries support with multiple reference #468", function(assert) {
var set = new WeakReferenceSet();

var obj = {};
var obj2 = {};

for (var index = 0; index < 3; index++) {
set.addReference(obj);
}

set.addReference(obj2);

assert.equal(set.referenceCount(obj), 3, "Got the correct reference count");
assert.equal(set.referenceCount(obj2), 1, "Got correct reference count for multiple entries");
});

1 change: 1 addition & 0 deletions helpers/weak-reference-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ assign(WeakReferenceSet.prototype,{
index = i;
return false;
}
return true;
});
return index !== undefined ? index : -1;
},
Expand Down

0 comments on commit 4d3dd31

Please sign in to comment.