deno.land / x / linq@4.0.2 / test / iterator.js

نووسراو ببینە
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { test, testModule, deepEqual } from './testutils.js'import Enumerable from '../linq.js'
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]; let expected = Array.from(Enumerable.from(actual)); deepEqual(actual, expected); let 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"]);});
test("reusable iterator", function () { const set = new Set([1, 2, 3])
let a = Enumerable.from(set.entries());
deepEqual(a.toArray(), [[1, 1], [2, 2], [3, 3]]); deepEqual(a.toArray(), []);
let b = Enumerable.from(() => set.entries());
deepEqual(b.toArray(), [[1, 1], [2, 2], [3, 3]]); deepEqual(b.toArray(), [[1, 1], [2, 2], [3, 3]]);
let c = Enumerable.from(() => ['x', 'y', 'z']);
deepEqual(c.toArray(), ['x', 'y', 'z']); deepEqual(c.toArray(), ['x', 'y', 'z']);});
linq

Version Info

Tagged at
7 months ago