Skip to content

Commit

Permalink
Adding tests to ensure that default iterators on builtins === the app…
Browse files Browse the repository at this point in the history
…ropriate prototype function.
  • Loading branch information
ljharb committed Apr 16, 2015
1 parent 5c29d38 commit 71a5870
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 6 additions & 3 deletions test/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var runArrayTests = function () {
var functionsHaveNames = (function foo() {}).name === 'foo';
var ifFunctionsHaveNamesIt = functionsHaveNames ? it : xit;
var ifSymbolIteratorIt = isSymbol(Sym.iterator) ? it : xit;
var ifSymbolIteratorAndArrayValuesIt = isSymbol(Sym.iterator) && Array.prototype.values ? it : xit;
var ifSymbolUnscopablesIt = isSymbol(Sym.unscopables) ? it : xit;

describe('Array', function () {
Expand All @@ -29,9 +30,11 @@ var runArrayTests = function () {
expect(iterator.next()).to.eql({ done: false, value: b });
expect(iterator.next()).to.eql({ done: false, value: c });
expect(iterator.next()).to.eql({ done: true, value: undefined });
if (Array.prototype.values) {
expect(iteratorFn).to.equal(a.values);
}
});

ifSymbolIteratorAndArrayValuesIt('has the right default iteration function', function () {
// fixed in Webkit https://bugs.webkit.org/show_bug.cgi?id=143838
expect(Array.prototype).to.have.property(Sym.iterator, Array.prototype.values);
});
});

Expand Down
16 changes: 16 additions & 0 deletions test/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ describe('Collections', function () {
}
};

var Sym = typeof Symbol !== 'undefined' ? Symbol : {};
var isSymbol = function (sym) {
return typeof Sym === 'function' && typeof sym === 'symbol';
};
var ifSymbolIteratorIt = isSymbol(Sym.iterator) ? it : xit;

var testMapping = function (map, key, value) {
expect(map.has(key)).to.equal(false);
expect(map.get(key)).to.equal(undefined);
Expand Down Expand Up @@ -326,6 +332,11 @@ describe('Collections', function () {
expect(map).to.have.entries(Array.from(map.entries()));
});

ifSymbolIteratorIt('has the right default iteration function', function () {
// fixed in Webkit https://bugs.webkit.org/show_bug.cgi?id=143838
expect(Map.prototype).to.have.property(Sym.iterator, Map.prototype.entries);
});

describe('#forEach', function () {
var map;

Expand Down Expand Up @@ -814,6 +825,11 @@ describe('Collections', function () {
});
});

ifSymbolIteratorIt('has the right default iteration function', function () {
// fixed in Webkit https://bugs.webkit.org/show_bug.cgi?id=143838
expect(Set.prototype).to.have.property(Sym.iterator, Set.prototype.values);
});

it('should preserve insertion order', function () {
var arr1 = ['d', 'a', 'b'];
var arr2 = [3, 2, 'z', 'a', 1];
Expand Down

0 comments on commit 71a5870

Please sign in to comment.