60%
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require("assert");
|
||||
const crypto = require("crypto");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const run = async () => {
|
||||
const source = fs.readFileSync(path.join(__dirname, "../utils/md5.js"), "utf8");
|
||||
const moduleUrl = `data:text/javascript;base64,${Buffer.from(source).toString("base64")}`;
|
||||
const { calcMD5Bytes } = await import(moduleUrl);
|
||||
for (const value of [Buffer.from([]), Buffer.from([0, 1, 127, 128, 255]), Buffer.from("家谱图片", "utf8")]) {
|
||||
const expected = crypto.createHash("md5").update(value).digest("hex");
|
||||
assert.strictEqual(calcMD5Bytes(value), expected);
|
||||
assert.strictEqual(calcMD5Bytes(value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength)), expected);
|
||||
}
|
||||
assert.throws(() => calcMD5Bytes("not-bytes"), /ArrayBuffer/);
|
||||
process.stdout.write("MD5-BYTES-RUNTIME-SMOKE PASS\n");
|
||||
};
|
||||
|
||||
run().catch((error) => {
|
||||
process.stderr.write(`${error.stack || error.message}\n`);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user