Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a MurmurHash3_64.update unit-test for TypedArrays which share the same underlying ArrayBuffer (PR 12534 follow-up) #12542

Merged
merged 1 commit into from
Oct 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions test/unit/murmurhash3_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
);
});