Skip to content

Commit d07e806

Browse files
committed
Add first tests.
1 parent 037e75c commit d07e806

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

Diff for: test/iterate-array.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { assert } = require('chai');
2+
const iterate = require('../index');
3+
4+
describe('iterate arrays', function () {
5+
it('should iterate all items in an array', function() {
6+
const steps = [];
7+
const testArr = ['a', 'b', 'c', 'd', 'e'];
8+
9+
iterate(testArr, (item, index, arr) => steps.push([item, index, arr]));
10+
11+
assert.deepEqual(steps, [
12+
['a', 0, testArr],
13+
['b', 1, testArr],
14+
['c', 2, testArr],
15+
['d', 3, testArr],
16+
['e', 4, testArr],
17+
]);
18+
});
19+
});

Diff for: test/iterate-strings.test.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const { assert } = require('chai');
2+
const iterate = require('../index');
3+
4+
describe('iterate string', function () {
5+
it('should iterate all chars in a primative string', function() {
6+
const steps = [];
7+
const testStr = 'abcde';
8+
9+
iterate(testStr, (char, index, str) => steps.push([char, index, str]));
10+
11+
assert.deepEqual(steps, [
12+
['a', 0, testStr],
13+
['b', 1, testStr],
14+
['c', 2, testStr],
15+
['d', 3, testStr],
16+
['e', 4, testStr],
17+
]);
18+
});
19+
20+
it('should iterate all chars in a string instance', function() {
21+
const steps = [];
22+
const testStr = new String('abcde');
23+
24+
iterate(testStr, (char, index, str) => steps.push([char, index, str]));
25+
26+
assert.deepEqual(steps, [
27+
['a', 0, testStr],
28+
['b', 1, testStr],
29+
['c', 2, testStr],
30+
['d', 3, testStr],
31+
['e', 4, testStr],
32+
]);
33+
});
34+
});

Diff for: test/iterate-typed-array.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { assert } = require('chai');
2+
const iterate = require('../index');
3+
4+
describe('iterate typed arrays', function () {
5+
it('should iterate all items in a typed array', function() {
6+
const steps = [];
7+
const testArr = new Int32Array([1, 2, 3, 4, 5]);
8+
9+
iterate(testArr, (number, index, arr) => steps.push([number, index, arr]));
10+
11+
assert.deepEqual(steps, [
12+
[1, 0, testArr],
13+
[2, 1, testArr],
14+
[3, 2, testArr],
15+
[4, 3, testArr],
16+
[5, 4, testArr],
17+
]);
18+
});
19+
});

0 commit comments

Comments
 (0)