test-buffer-iterator.js
925 Bytes
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
58
59
60
61
62
63
64
65
'use strict';
var Buffer = require('../../').Buffer;
var assert = require('assert');
var buffer = Buffer.from([1, 2, 3, 4, 5]);
var arr;
var b;
// buffers should be iterable
arr = [];
for (b of buffer)
arr.push(b);
assert.deepStrictEqual(arr, [1, 2, 3, 4, 5]);
// buffer iterators should be iterable
arr = [];
for (b of buffer[Symbol.iterator]())
arr.push(b);
assert.deepStrictEqual(arr, [1, 2, 3, 4, 5]);
// buffer#values() should return iterator for values
arr = [];
for (b of buffer.values())
arr.push(b);
assert.deepStrictEqual(arr, [1, 2, 3, 4, 5]);
// buffer#keys() should return iterator for keys
arr = [];
for (b of buffer.keys())
arr.push(b);
assert.deepStrictEqual(arr, [0, 1, 2, 3, 4]);
// buffer#entries() should return iterator for entries
arr = [];
for (b of buffer.entries())
arr.push(b);
assert.deepStrictEqual(arr, [
[0, 1],
[1, 2],
[2, 3],
[3, 4],
[4, 5]
]);