Protocol Buffers - Google's data interchange format (grpc依赖)
https://developers.google.com/protocol-buffers/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
48 lines
1.4 KiB
5 years ago
|
/**
|
||
|
* @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();
|
||
|
});
|
||
|
});
|