-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuffer-keyed-map.test.js
More file actions
88 lines (74 loc) · 2.06 KB
/
buffer-keyed-map.test.js
File metadata and controls
88 lines (74 loc) · 2.06 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict';
var expect = require('chai').expect;
describe('BufferKeyedMap', function () {
var BufferKeyedMap = require('../release/buffer-keyed-map').default,
instance,
output;
beforeEach(function () {
instance = new BufferKeyedMap();
});
describe('#get', function () {
var obj = {obj1: 'obj1'};
beforeEach(function() {
instance.data = {
'\x00\xFE\xFF': obj,
'\x01\xAA\xBB': {obj2: 'obj2'},
};
output = instance.get(Buffer.from([0, 0xFE, 0xFF]));
});
it('returns a stored object by its index', function() {
expect(output).to.eql(obj);
});
});
describe('#set', function() {
var obj = {obj1: 'obj1'};
beforeEach(function() {
instance.data = {
'\x01\xAA\xBB': {obj2: 'obj2'},
};
instance.set(Buffer.from([0x05, 0xAA, 0xFE, 0xFF]), obj);
});
it('stores the given object', function() {
expect(instance.data['\x05\xAA\xFE\xFF']).to.eql(obj);
});
});
describe('#delete', function() {
beforeEach(function() {
instance.data = {
'\x05\xAA\xFE\xFF': {obj1: 'obj1'},
'\x01\xAA\xBB': {obj2: 'obj2'},
};
instance.delete(Buffer.from([0x05, 0xAA, 0xFE, 0xFF]));
});
it('stores the given object', function() {
expect(instance.data['\xAA\xFE\xFF']).to.be.undefined;
});
});
describe('#getData', function() {
var data = {
'\x05\xAA\xFE\xFF': {obj1: 'obj1'},
'\x01\xAA\xBB': {obj2: 'obj2'},
};
beforeEach(function() {
instance.data = data;
output = instance.getData();
});
it('returns an array of the map values', function() {
expect(output).to.equal(data);
});
});
describe('#getValues', function() {
var obj1 = {obj1: 'obj1'},
obj2 = {obj2: 'obj2'};
beforeEach(function() {
instance.data = {
'\x05\xAA\xFE\xFF': obj1,
'\x01\xAA\xBB': obj2,
};
output = instance.getValues();
});
it('returns an array of the map values', function() {
expect(output).to.eql([obj1, obj2]);
});
});
});