]> git.r.bdr.sh - rbdr/dotfiles/blob
ae7c2199e84a729535a2ba4bcb883220b47784c0
[rbdr/dotfiles] /
1 'use strict';
2
3 var iteratorSymbol = require('es6-symbol').iterator;
4
5 module.exports = function (T) {
6 return {
7 Values: function (a) {
8 var x = ['raz', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć'], it;
9
10 it = new T(x);
11 a(it[iteratorSymbol](), it, "@@iterator");
12 a.deep(it.next(), { done: false, value: 'raz' }, "#1");
13 a.deep(it.next(), { done: false, value: 'dwa' }, "#2");
14 x.splice(1, 0, 'elo');
15 a.deep(it.next(), { done: false, value: 'dwa' }, "Insert");
16 a.deep(it.next(), { done: false, value: 'trzy' }, "#3");
17 a.deep(it.next(), { done: false, value: 'cztery' }, "#4");
18 x.pop();
19 a.deep(it.next(), { done: false, value: 'pięć' }, "#5");
20 a.deep(it.next(), { done: true, value: undefined }, "End");
21 },
22 "Keys & Values": function (a) {
23 var x = ['raz', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć'], it;
24
25 it = new T(x, 'key+value');
26 a(it[iteratorSymbol](), it, "@@iterator");
27 a.deep(it.next(), { done: false, value: [0, 'raz'] }, "#1");
28 a.deep(it.next(), { done: false, value: [1, 'dwa'] }, "#2");
29 x.splice(1, 0, 'elo');
30 a.deep(it.next(), { done: false, value: [2, 'dwa'] }, "Insert");
31 a.deep(it.next(), { done: false, value: [3, 'trzy'] }, "#3");
32 a.deep(it.next(), { done: false, value: [4, 'cztery'] }, "#4");
33 x.pop();
34 a.deep(it.next(), { done: false, value: [5, 'pięć'] }, "#5");
35 a.deep(it.next(), { done: true, value: undefined }, "End");
36 },
37 Keys: function (a) {
38 var x = ['raz', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć'], it;
39
40 it = new T(x, 'key');
41 a(it[iteratorSymbol](), it, "@@iterator");
42 a.deep(it.next(), { done: false, value: 0 }, "#1");
43 a.deep(it.next(), { done: false, value: 1 }, "#2");
44 x.splice(1, 0, 'elo');
45 a.deep(it.next(), { done: false, value: 2 }, "Insert");
46 a.deep(it.next(), { done: false, value: 3 }, "#3");
47 a.deep(it.next(), { done: false, value: 4 }, "#4");
48 x.pop();
49 a.deep(it.next(), { done: false, value: 5 }, "#5");
50 a.deep(it.next(), { done: true, value: undefined }, "End");
51 },
52 Sparse: function (a) {
53 var x = new Array(6), it;
54
55 x[2] = 'raz';
56 x[4] = 'dwa';
57 it = new T(x);
58 a.deep(it.next(), { done: false, value: undefined }, "#1");
59 a.deep(it.next(), { done: false, value: undefined }, "#2");
60 a.deep(it.next(), { done: false, value: 'raz' }, "#3");
61 a.deep(it.next(), { done: false, value: undefined }, "#4");
62 a.deep(it.next(), { done: false, value: 'dwa' }, "#5");
63 a.deep(it.next(), { done: false, value: undefined }, "#6");
64 a.deep(it.next(), { done: true, value: undefined }, "End");
65 }
66 };
67 };