2023-08-01 14:20:57 +00:00
|
|
|
import { assertEquals } from "assert";
|
2023-08-02 16:43:02 +00:00
|
|
|
import { stubbingWarn } from "../helpers.ts";
|
2023-08-01 14:20:57 +00:00
|
|
|
import parseHash from "../../public/png/parseHash.js";
|
|
|
|
|
2023-08-02 16:43:02 +00:00
|
|
|
Deno.test(
|
|
|
|
"returns null if hash cannot be parsed",
|
|
|
|
stubbingWarn(() => {
|
|
|
|
const testCases = [
|
|
|
|
// Missing fields
|
|
|
|
"#null",
|
|
|
|
"#{}",
|
|
|
|
"#{%22name%22:%22image.png%22}",
|
|
|
|
"#{%22bytes%22:%22AQID%22}",
|
|
|
|
// Invalid JSON
|
|
|
|
"",
|
|
|
|
"#{%22name%22:%22small.png%22,%22bytes%22:%22iAQID",
|
|
|
|
];
|
2023-08-01 14:20:57 +00:00
|
|
|
|
|
|
|
for (const testCase of testCases) {
|
|
|
|
assertEquals(
|
|
|
|
parseHash(testCase),
|
|
|
|
null,
|
|
|
|
`Parsing ${testCase} should fail`,
|
|
|
|
);
|
|
|
|
}
|
2023-08-02 16:43:02 +00:00
|
|
|
}),
|
|
|
|
);
|
2023-08-01 14:20:57 +00:00
|
|
|
|
|
|
|
Deno.test("parses hashes", () => {
|
|
|
|
const hash = "#{%22name%22:%22small.png%22,%22bytes%22:%22AQID%22}";
|
|
|
|
assertEquals(parseHash(hash), {
|
|
|
|
name: "small.png",
|
|
|
|
bytes: new Uint8Array([1, 2, 3]),
|
|
|
|
});
|
|
|
|
});
|