Skip to content

Commit 3cf8f91

Browse files
add test for trimmed 0
1 parent f9ff567 commit 3cf8f91

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

__test__/index.spec.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test('sum from native', (t) => {
99

1010
// empty hash a67c89456ea2fcd58cdf557c01357632d4f0d28c51dd0d8f79a4c739352f71a7
1111

12-
function testEncode(t, imagePath, expectedHash) {
12+
function testEncode(t, imagePath, expectedHash, trim = false) {
1313
let buffer = fs.readFileSync(imagePath);
1414

1515
//let arr = new Uint8Array(buffer);
@@ -19,6 +19,9 @@ function testEncode(t, imagePath, expectedHash) {
1919
console.log('hash ', hash);
2020

2121
let mchash = Buffer.from(encoded.minecraftHash).toString('hex');
22+
if (trim) {
23+
mchash = mchash.replace(/^0+/, '');
24+
}
2225
console.log('mchash ', mchash);
2326

2427
console.log('expected', expectedHash);
@@ -35,7 +38,8 @@ for (const params of [
3538
['images/randomImage2.png', '57a6d6ddebafe045e9a0501c7c489f6de47e670fc4ef1b0c1b2c2a9a2c8c0cbc'],
3639
['images/randomImage3.png', '1b84a8081994cce186eeae4787f95bce663d6711272782ce659d9cc954fec435'],
3740
['images/randomImage4.png', 'e19abca2800650b449fff3f12ed3d1bd0f20861d7cdd00c66d62264b52837e2c'],
38-
['images/trimmed0.png', '0aa97a60ff386b6075aea693893106358def0cd580e6360599811e08bde38b6f'] // mojang strips the leading 0, this doesn't currently
41+
['images/trimmed0.png', '0aa97a60ff386b6075aea693893106358def0cd580e6360599811e08bde38b6f'], // mojang strips the leading 0, this doesn't currently
42+
['images/trimmed0.png', 'aa97a60ff386b6075aea693893106358def0cd580e6360599811e08bde38b6f', true]
3943
]) {
4044
test(testEncode, ...params);
4145
}

0 commit comments

Comments
 (0)