1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | const assert = require("assert");
|
20 | const mocha_1 = require("mocha");
|
21 | const index_1 = require("../index");
|
22 | mocha_1.describe('#forEachAsync()', function () {
|
23 | mocha_1.describe('Array', function () {
|
24 | mocha_1.it('should work fill output array by sync action', async function () {
|
25 | const IN_ARR = [1, 2, 3, 4, 5];
|
26 | const OUT_ARR = [];
|
27 | await index_1.forEachAsync(IN_ARR, (item, i) => {
|
28 | OUT_ARR.push(`${item * 10}::${i}`);
|
29 | });
|
30 | assert.equal(OUT_ARR.length, IN_ARR.length);
|
31 | assert.strictEqual(OUT_ARR.length, IN_ARR.length);
|
32 | for (let i = 0; i < OUT_ARR.length; i++) {
|
33 | const ITEM = OUT_ARR[i];
|
34 | const EXPECTED = `${IN_ARR[i] * 10}::${i}`;
|
35 | assert.equal(ITEM, EXPECTED);
|
36 | }
|
37 | });
|
38 | mocha_1.it('should work fill output array by async action', async function () {
|
39 | const IN_ARR = [1, 2, 3, 4, 5];
|
40 | const OUT_ARR = [];
|
41 | await index_1.forEachAsync(IN_ARR, async (item, i) => {
|
42 | OUT_ARR.push(`${item * 10}::${i}`);
|
43 | });
|
44 | assert.equal(OUT_ARR.length, IN_ARR.length);
|
45 | assert.strictEqual(OUT_ARR.length, IN_ARR.length);
|
46 | for (let i = 0; i < OUT_ARR.length; i++) {
|
47 | const ITEM = OUT_ARR[i];
|
48 | const EXPECTED = `${IN_ARR[i] * 10}::${i}`;
|
49 | assert.equal(ITEM, EXPECTED);
|
50 | }
|
51 | });
|
52 | });
|
53 | mocha_1.describe('Generators', function () {
|
54 | const TO_ITERATOR = function* (arr) {
|
55 | for (const ITEM of arr) {
|
56 | yield ITEM;
|
57 | }
|
58 | };
|
59 | mocha_1.it('should work fill output array by sync action', async function () {
|
60 | const IN_ARR = [1, 2, 3, 4, 5];
|
61 | const OUT_ARR = [];
|
62 | await index_1.forEachAsync(TO_ITERATOR(IN_ARR), (item, i) => {
|
63 | OUT_ARR.push(`${item * 10}::${i}`);
|
64 | });
|
65 | assert.equal(OUT_ARR.length, IN_ARR.length);
|
66 | assert.strictEqual(OUT_ARR.length, IN_ARR.length);
|
67 | for (let i = 0; i < OUT_ARR.length; i++) {
|
68 | const ITEM = OUT_ARR[i];
|
69 | const EXPECTED = `${IN_ARR[i] * 10}::${i}`;
|
70 | assert.equal(ITEM, EXPECTED);
|
71 | }
|
72 | });
|
73 | mocha_1.it('should work fill output array by async action', async function () {
|
74 | const IN_ARR = [1, 2, 3, 4, 5];
|
75 | const OUT_ARR = [];
|
76 | await index_1.forEachAsync(TO_ITERATOR(IN_ARR), async (item, i) => {
|
77 | OUT_ARR.push(`${item * 10}::${i}`);
|
78 | });
|
79 | assert.equal(OUT_ARR.length, IN_ARR.length);
|
80 | assert.strictEqual(OUT_ARR.length, IN_ARR.length);
|
81 | for (let i = 0; i < OUT_ARR.length; i++) {
|
82 | const ITEM = OUT_ARR[i];
|
83 | const EXPECTED = `${IN_ARR[i] * 10}::${i}`;
|
84 | assert.equal(ITEM, EXPECTED);
|
85 | }
|
86 | });
|
87 | });
|
88 | mocha_1.describe('Strings', function () {
|
89 | mocha_1.it('should work fill output array by sync action', async function () {
|
90 | const IN_STR = '12345';
|
91 | const OUT_ARR = [];
|
92 | await index_1.forEachAsync(IN_STR, (item, i) => {
|
93 | OUT_ARR.push(`${parseInt(item) * 10}::${i}`);
|
94 | });
|
95 | assert.equal(OUT_ARR.length, IN_STR.length);
|
96 | assert.strictEqual(OUT_ARR.length, IN_STR.length);
|
97 | for (let i = 0; i < OUT_ARR.length; i++) {
|
98 | const ITEM = OUT_ARR[i];
|
99 | const EXPECTED = `${parseInt(IN_STR[i]) * 10}::${i}`;
|
100 | assert.equal(ITEM, EXPECTED);
|
101 | }
|
102 | });
|
103 | mocha_1.it('should work fill output array by async action', async function () {
|
104 | const IN_STR = '12345';
|
105 | const OUT_ARR = [];
|
106 | await index_1.forEachAsync(IN_STR, (item, i) => {
|
107 | OUT_ARR.push(`${parseInt(item) * 10}::${i}`);
|
108 | });
|
109 | assert.equal(OUT_ARR.length, IN_STR.length);
|
110 | assert.strictEqual(OUT_ARR.length, IN_STR.length);
|
111 | for (let i = 0; i < OUT_ARR.length; i++) {
|
112 | const ITEM = OUT_ARR[i];
|
113 | const EXPECTED = `${parseInt(IN_STR[i]) * 10}::${i}`;
|
114 | assert.equal(ITEM, EXPECTED);
|
115 | }
|
116 | });
|
117 | });
|
118 | });
|
119 |
|
\ | No newline at end of file |