• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @fileoverview Tests in this file will fail if our custom equality have not
3 * been installed.
4 * see b/131864652
5 */
6
7goog.module('protobuf.testing.ensureCustomEqualityTest');
8
9const BufferDecoder = goog.require('protobuf.binary.BufferDecoder');
10const ByteString = goog.require('protobuf.ByteString');
11
12describe('Custom equality', () => {
13  it('ensure that custom equality for ArrayBuffer is installed', () => {
14    const buffer1 = new ArrayBuffer(4);
15    const buffer2 = new ArrayBuffer(4);
16    const array = new Uint8Array(buffer1);
17    array[0] = 1;
18    expect(buffer1).not.toEqual(buffer2);
19  });
20
21  it('ensure that custom equality for ByteString is installed', () => {
22    const HALLO_IN_BASE64 = 'aGFsbG8=';
23    const BYTES_WITH_HALLO = new Uint8Array([
24      'h'.charCodeAt(0),
25      'a'.charCodeAt(0),
26      'l'.charCodeAt(0),
27      'l'.charCodeAt(0),
28      'o'.charCodeAt(0),
29    ]);
30
31    const byteString1 = ByteString.fromBase64String(HALLO_IN_BASE64);
32    const byteString2 = ByteString.fromArrayBufferView(BYTES_WITH_HALLO);
33    expect(byteString1).toEqual(byteString2);
34  });
35
36  it('ensure that custom equality for BufferDecoder is installed', () => {
37    const arrayBuffer1 = new Uint8Array([0, 1, 2]).buffer;
38    const arrayBuffer2 = new Uint8Array([0, 1, 2]).buffer;
39
40    const bufferDecoder1 = BufferDecoder.fromArrayBuffer(arrayBuffer1);
41    const bufferDecoder2 = BufferDecoder.fromArrayBuffer(arrayBuffer2);
42    expect(bufferDecoder1).toEqual(bufferDecoder2);
43  });
44});
45