• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @fileoverview Tests for uint8arrays.js.
3 */
4goog.module('protobuf.binary.Uint8ArraysTest');
5
6goog.setTestOnly();
7
8const {concatenateByteArrays} = goog.require('protobuf.binary.uint8arrays');
9
10describe('concatenateByteArrays does', () => {
11  it('concatenate empty array', () => {
12    const byteArrays = [];
13    expect(concatenateByteArrays(byteArrays)).toEqual(new Uint8Array(0));
14  });
15
16  it('concatenate Uint8Arrays', () => {
17    const byteArrays = [new Uint8Array([0x01]), new Uint8Array([0x02])];
18    expect(concatenateByteArrays(byteArrays)).toEqual(new Uint8Array([
19      0x01, 0x02
20    ]));
21  });
22
23  it('concatenate array of bytes', () => {
24    const byteArrays = [[0x01], [0x02]];
25    expect(concatenateByteArrays(byteArrays)).toEqual(new Uint8Array([
26      0x01, 0x02
27    ]));
28  });
29
30  it('concatenate array of non-bytes', () => {
31    // Note in unchecked mode we produce invalid output for invalid inputs.
32    // This test just documents our behavior in those cases.
33    // These values might change at any point and are not considered
34    // what the implementation should be doing here.
35    const byteArrays = [[40.0], [256]];
36    expect(concatenateByteArrays(byteArrays)).toEqual(new Uint8Array([
37      0x28, 0x00
38    ]));
39  });
40
41  it('throw for null array', () => {
42    expect(
43        () => concatenateByteArrays(
44            /** @type {!Array<!Uint8Array>} */ (/** @type {*} */ (null))))
45        .toThrow();
46  });
47});
48