-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathBoolean.js
39 lines (34 loc) · 1.15 KB
/
Boolean.js
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
import assert from 'assert';
import {Boolean, uint8, DecodeStream, EncodeStream} from 'restructure';
describe('Boolean', function() {
describe('decode', function() {
it('should decode 0 as false', function() {
const buffer = new Uint8Array([0]);
const boolean = new Boolean(uint8);
assert.deepEqual(boolean.fromBuffer(buffer), false);
});
it('should decode 1 as true', function() {
const buffer = new Uint8Array([1]);
const boolean = new Boolean(uint8);
assert.deepEqual(boolean.fromBuffer(buffer), true);
});
});
describe('size', () =>
it('should return given type size', function() {
const boolean = new Boolean(uint8);
assert.deepEqual(boolean.size(), 1);
})
);
describe('encode', function() {
it('should encode false as 0', function() {
const boolean = new Boolean(uint8);
const buffer = boolean.toBuffer(false);
assert.deepEqual(buffer, Buffer.from([0]));
});
it('should encode true as 1', function() {
const boolean = new Boolean(uint8);
const buffer = boolean.toBuffer(true);
assert.deepEqual(buffer, Buffer.from([1]));
});
});
});