mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
- Added `tests/utils/hex.test.mjs` - Covered `normalizeHexString` with various input types - Covered `HEX64_REGEX` with valid and invalid cases - Verified aliases `normalizeHexId` and `normalizeHexPubkey` Co-authored-by: PR0M3TH3AN <[email protected]>
64 lines
2.0 KiB
JavaScript
64 lines
2.0 KiB
JavaScript
import { describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
normalizeHexString,
|
|
normalizeHexId,
|
|
normalizeHexPubkey,
|
|
HEX64_REGEX,
|
|
} from "../../js/utils/hex.js";
|
|
|
|
describe("hex utils", () => {
|
|
describe("normalizeHexString", () => {
|
|
it("should return empty string for non-string inputs", () => {
|
|
assert.equal(normalizeHexString(undefined), "");
|
|
assert.equal(normalizeHexString(null), "");
|
|
assert.equal(normalizeHexString(123), "");
|
|
assert.equal(normalizeHexString({}), "");
|
|
});
|
|
|
|
it("should return empty string for empty or whitespace-only strings", () => {
|
|
assert.equal(normalizeHexString(""), "");
|
|
assert.equal(normalizeHexString(" "), "");
|
|
});
|
|
|
|
it("should trim and lowercase valid hex strings", () => {
|
|
assert.equal(normalizeHexString("ABC"), "abc");
|
|
assert.equal(normalizeHexString(" DEF "), "def");
|
|
assert.equal(normalizeHexString("AbCdEf"), "abcdef");
|
|
});
|
|
});
|
|
|
|
describe("aliases", () => {
|
|
it("should export normalizeHexId as an alias", () => {
|
|
assert.equal(normalizeHexId, normalizeHexString);
|
|
});
|
|
|
|
it("should export normalizeHexPubkey as an alias", () => {
|
|
assert.equal(normalizeHexPubkey, normalizeHexString);
|
|
});
|
|
});
|
|
|
|
describe("HEX64_REGEX", () => {
|
|
it("should match valid 64-character hex strings", () => {
|
|
const validHex = "a".repeat(64);
|
|
assert.match(validHex, HEX64_REGEX);
|
|
const mixedCase = "A".repeat(32) + "b".repeat(32);
|
|
assert.match(mixedCase, HEX64_REGEX);
|
|
});
|
|
|
|
it("should not match strings with incorrect length", () => {
|
|
assert.doesNotMatch("a".repeat(63), HEX64_REGEX);
|
|
assert.doesNotMatch("a".repeat(65), HEX64_REGEX);
|
|
});
|
|
|
|
it("should not match strings with non-hex characters", () => {
|
|
const invalidChar = "a".repeat(63) + "g";
|
|
assert.doesNotMatch(invalidChar, HEX64_REGEX);
|
|
});
|
|
|
|
it("should not match empty strings", () => {
|
|
assert.doesNotMatch("", HEX64_REGEX);
|
|
});
|
|
});
|
|
});
|