-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { assert } = require('chai'); | ||
const iterate = require('../index'); | ||
|
||
describe('iterate arrays', function () { | ||
it('should iterate all items in an array', function() { | ||
const steps = []; | ||
const testArr = ['a', 'b', 'c', 'd', 'e']; | ||
|
||
iterate(testArr, (item, index, arr) => steps.push([item, index, arr])); | ||
|
||
assert.deepEqual(steps, [ | ||
['a', 0, testArr], | ||
['b', 1, testArr], | ||
['c', 2, testArr], | ||
['d', 3, testArr], | ||
['e', 4, testArr], | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const { assert } = require('chai'); | ||
const iterate = require('../index'); | ||
|
||
describe('iterate string', function () { | ||
it('should iterate all chars in a primative string', function() { | ||
const steps = []; | ||
const testStr = 'abcde'; | ||
|
||
iterate(testStr, (char, index, str) => steps.push([char, index, str])); | ||
|
||
assert.deepEqual(steps, [ | ||
['a', 0, testStr], | ||
['b', 1, testStr], | ||
['c', 2, testStr], | ||
['d', 3, testStr], | ||
['e', 4, testStr], | ||
]); | ||
}); | ||
|
||
it('should iterate all chars in a string instance', function() { | ||
const steps = []; | ||
const testStr = new String('abcde'); | ||
|
||
iterate(testStr, (char, index, str) => steps.push([char, index, str])); | ||
|
||
assert.deepEqual(steps, [ | ||
['a', 0, testStr], | ||
['b', 1, testStr], | ||
['c', 2, testStr], | ||
['d', 3, testStr], | ||
['e', 4, testStr], | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { assert } = require('chai'); | ||
const iterate = require('../index'); | ||
|
||
describe('iterate typed arrays', function () { | ||
it('should iterate all items in a typed array', function() { | ||
const steps = []; | ||
const testArr = new Int32Array([1, 2, 3, 4, 5]); | ||
|
||
iterate(testArr, (number, index, arr) => steps.push([number, index, arr])); | ||
|
||
assert.deepEqual(steps, [ | ||
[1, 0, testArr], | ||
[2, 1, testArr], | ||
[3, 2, testArr], | ||
[4, 3, testArr], | ||
[5, 4, testArr], | ||
]); | ||
}); | ||
}); |