ensure_custom_equality_test.js 1.5 KB

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