-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathuint8arrays_test.js
47 lines (40 loc) · 1.41 KB
/
uint8arrays_test.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
40
41
42
43
44
45
46
47
/**
* @fileoverview Tests for uint8arrays.js.
*/
goog.module('protobuf.binary.Uint8ArraysTest');
goog.setTestOnly();
const {concatenateByteArrays} = goog.require('protobuf.binary.uint8arrays');
describe('concatenateByteArrays does', () => {
it('concatenate empty array', () => {
const byteArrays = [];
expect(concatenateByteArrays(byteArrays)).toEqual(new Uint8Array(0));
});
it('concatenate Uint8Arrays', () => {
const byteArrays = [new Uint8Array([0x01]), new Uint8Array([0x02])];
expect(concatenateByteArrays(byteArrays)).toEqual(new Uint8Array([
0x01, 0x02
]));
});
it('concatenate array of bytes', () => {
const byteArrays = [[0x01], [0x02]];
expect(concatenateByteArrays(byteArrays)).toEqual(new Uint8Array([
0x01, 0x02
]));
});
it('concatenate array of non-bytes', () => {
// Note in unchecked mode we produce invalid output for invalid inputs.
// This test just documents our behavior in those cases.
// These values might change at any point and are not considered
// what the implementation should be doing here.
const byteArrays = [[40.0], [256]];
expect(concatenateByteArrays(byteArrays)).toEqual(new Uint8Array([
0x28, 0x00
]));
});
it('throw for null array', () => {
expect(
() => concatenateByteArrays(
/** @type {!Array<!Uint8Array>} */ (/** @type {*} */ (null))))
.toThrow();
});
});