forked from mihaifm/linq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterator.js
More file actions
37 lines (31 loc) · 967 Bytes
/
iterator.js
File metadata and controls
37 lines (31 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var {test, testModule, deepEqual} = require('./testutils.js')
var Enumerable = require('../linq.min');
testModule("Iterator");
test("for..of", function () {
let actual = [];
for (var a of Enumerable.from([1, 2, 3])) {
actual.push(a);
}
deepEqual(actual, [1, 2, 3]);
});
test("Symbol.iterator", function ()
{
let actual = [1,2,3,4];
expected = Array.from(Enumerable.from(actual));
deepEqual(actual, expected);
var actual2 = actual.map(function(x) { return x * 2 }); // [2,4,6,8];
expected = Enumerable.from(actual).select(function(x) { return x * 2 });
deepEqual(actual2, Array.from(expected));
});
test("from Iterable", function () {
function* words() {
yield "abc";
yield "def";
}
deepEqual(Enumerable.from(words()).toArray(), ["abc", "def"]);
let actual = [];
for (var a of Enumerable.from(words())) {
actual.push(a);
}
deepEqual(actual, ["abc", "def"]);
});