Merge pull request #12542 from Snuffleupagus/murmurhash-slice-test

Add a `MurmurHash3_64.update` unit-test for TypedArrays which share the same underlying ArrayBuffer (PR 12534 follow-up)
This commit is contained in:
Tim van der Meij 2020-10-28 22:15:00 +01:00 committed by GitHub
commit 91ca2674c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,4 +60,34 @@ describe("MurmurHash3_64", function () {
const hexdigest2 = hash.hexdigest();
expect(hexdigest1).not.toEqual(hexdigest2);
});
it(
"generates correct hashes for TypedArrays which share the same " +
"underlying ArrayBuffer (issue 12533)",
function () {
// prettier-ignore
const typedArray = new Uint8Array([
0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
]);
const startArray = new Uint8Array(typedArray.buffer, 0, 10);
const endArray = new Uint8Array(typedArray.buffer, 10, 10);
expect(startArray).not.toEqual(endArray);
const startHash = new MurmurHash3_64();
startHash.update(startArray);
const startHexdigest = startHash.hexdigest();
const endHash = new MurmurHash3_64();
endHash.update(endArray);
const endHexdigest = endHash.hexdigest();
// The two hashes *must* be different.
expect(startHexdigest).not.toEqual(endHexdigest);
expect(startHexdigest).toEqual("a49de339cc5b0819");
expect(endHexdigest).toEqual("f81a92d9e214ab35");
}
);
});