Add dependencies locally

This commit is contained in:
Ahrimdon
2024-03-07 05:13:50 -05:00
parent e4a5cd056e
commit 9a56906be7
9538 changed files with 3064916 additions and 107 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,44 @@
/**
* @fileoverview Tests in this file will fail if our custom equality have not
* been installed.
* see b/131864652
*/
goog.module('protobuf.testing.ensureCustomEqualityTest');
const BufferDecoder = goog.require('protobuf.binary.BufferDecoder');
const ByteString = goog.require('protobuf.ByteString');
describe('Custom equality', () => {
it('ensure that custom equality for ArrayBuffer is installed', () => {
const buffer1 = new ArrayBuffer(4);
const buffer2 = new ArrayBuffer(4);
const array = new Uint8Array(buffer1);
array[0] = 1;
expect(buffer1).not.toEqual(buffer2);
});
it('ensure that custom equality for ByteString is installed', () => {
const HALLO_IN_BASE64 = 'aGFsbG8=';
const BYTES_WITH_HALLO = new Uint8Array([
'h'.charCodeAt(0),
'a'.charCodeAt(0),
'l'.charCodeAt(0),
'l'.charCodeAt(0),
'o'.charCodeAt(0),
]);
const byteString1 = ByteString.fromBase64String(HALLO_IN_BASE64);
const byteString2 = ByteString.fromArrayBufferView(BYTES_WITH_HALLO);
expect(byteString1).toEqual(byteString2);
});
it('ensure that custom equality for BufferDecoder is installed', () => {
const arrayBuffer1 = new Uint8Array([0, 1, 2]).buffer;
const arrayBuffer2 = new Uint8Array([0, 1, 2]).buffer;
const bufferDecoder1 = BufferDecoder.fromArrayBuffer(arrayBuffer1);
const bufferDecoder2 = BufferDecoder.fromArrayBuffer(arrayBuffer2);
expect(bufferDecoder1).toEqual(bufferDecoder2);
});
});

View File

@ -0,0 +1,88 @@
/**
* @fileoverview Installs our custom equality matchers in Jasmine.
*/
goog.module('protobuf.testing.jasmineProtoBuf');
const BufferDecoder = goog.require('protobuf.binary.BufferDecoder');
const ByteString = goog.require('protobuf.ByteString');
const {arrayBufferEqual} = goog.require('protobuf.binary.typedArrays');
/**
* A function that ensures custom equality for ByteStrings.
* Since Jasmine compare structure by default Bytestrings might be equal that
* are not equal since ArrayBuffers still compare content in g3.
* (Jasmine fix upstream: https://github.com/jasmine/jasmine/issues/1687)
* Also ByteStrings that are equal might compare non equal in jasmine of the
* base64 string has been initialized.
* @param {*} first
* @param {*} second
* @return {boolean|undefined}
*/
const byteStringEquality = (first, second) => {
if (second instanceof ByteString) {
return second.equals(first);
}
// Intentionally not returning anything, this signals to jasmine that we
// did not perform any equality on the given objects.
};
/**
* A function that ensures custom equality for ArrayBuffers.
* By default Jasmine does not compare the content of an ArrayBuffer and thus
* will return true for buffers with the same length but different content.
* @param {*} first
* @param {*} second
* @return {boolean|undefined}
*/
const arrayBufferCustomEquality = (first, second) => {
if (first instanceof ArrayBuffer && second instanceof ArrayBuffer) {
return arrayBufferEqual(first, second);
}
// Intentionally not returning anything, this signals to jasmine that we
// did not perform any equality on the given objects.
};
/**
* A function that ensures custom equality for ArrayBuffers.
* By default Jasmine does not compare the content of an ArrayBuffer and thus
* will return true for buffers with the same length but different content.
* @param {*} first
* @param {*} second
* @return {boolean|undefined}
*/
const bufferDecoderCustomEquality = (first, second) => {
if (first instanceof BufferDecoder && second instanceof BufferDecoder) {
return first.asByteString().equals(second.asByteString());
}
// Intentionally not returning anything, this signals to jasmine that we
// did not perform any equality on the given objects.
};
/**
* Overrides the default ArrayBuffer toString method ([object ArrayBuffer]) with
* a more readable representation.
*/
function overrideArrayBufferToString() {
/**
* Returns the hex values of the underlying bytes of the ArrayBuffer.
*
* @override
* @return {string}
*/
ArrayBuffer.prototype.toString = function() {
const arr = Array.from(new Uint8Array(this));
return 'ArrayBuffer[' +
arr.map((b) => '0x' + (b & 0xFF).toString(16).toUpperCase())
.join(', ') +
']';
};
}
beforeEach(() => {
jasmine.addCustomEqualityTester(arrayBufferCustomEquality);
jasmine.addCustomEqualityTester(bufferDecoderCustomEquality);
jasmine.addCustomEqualityTester(byteStringEquality);
overrideArrayBufferToString();
});