Skip to content

Commit 91ca267

Browse files
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)
2 parents ea4d88a + 852c61e commit 91ca267

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/unit/murmurhash3_spec.js

+30
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,34 @@ describe("MurmurHash3_64", function () {
6060
const hexdigest2 = hash.hexdigest();
6161
expect(hexdigest1).not.toEqual(hexdigest2);
6262
});
63+
64+
it(
65+
"generates correct hashes for TypedArrays which share the same " +
66+
"underlying ArrayBuffer (issue 12533)",
67+
function () {
68+
// prettier-ignore
69+
const typedArray = new Uint8Array([
70+
0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
71+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
72+
]);
73+
const startArray = new Uint8Array(typedArray.buffer, 0, 10);
74+
const endArray = new Uint8Array(typedArray.buffer, 10, 10);
75+
76+
expect(startArray).not.toEqual(endArray);
77+
78+
const startHash = new MurmurHash3_64();
79+
startHash.update(startArray);
80+
const startHexdigest = startHash.hexdigest();
81+
82+
const endHash = new MurmurHash3_64();
83+
endHash.update(endArray);
84+
const endHexdigest = endHash.hexdigest();
85+
86+
// The two hashes *must* be different.
87+
expect(startHexdigest).not.toEqual(endHexdigest);
88+
89+
expect(startHexdigest).toEqual("a49de339cc5b0819");
90+
expect(endHexdigest).toEqual("f81a92d9e214ab35");
91+
}
92+
);
6393
});

0 commit comments

Comments
 (0)