Skip to content

Commit 15683a5

Browse files
committed
Add test for getAsciiArt
1 parent c59d53a commit 15683a5

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

cli/node.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assertEquals } from "@std/assert";
22
import fetchMock from "fetch-mock";
3-
import { getFaviconUrl, rgbTo256Color } from "./node.ts";
3+
import { getAsciiArt, getFaviconUrl, Jimp, rgbTo256Color } from "./node.ts";
44

55
const HTML_WITH_SMALL_ICON = `
66
<!DOCTYPE html>
@@ -153,3 +153,16 @@ Deno.test("rgbTo256Color - check grayscale", () => {
153153
);
154154
assertEquals(results, EXPECTED_GRAY_IDX);
155155
});
156+
157+
Deno.test("getAsciiArt - Darkest Letter", () => {
158+
// Create black and white 1x1 images using Jimp constructor
159+
const blackImage = new Jimp({ width: 1, height: 1, color: 0x000000ff });
160+
161+
const blackResult = getAsciiArt(
162+
blackImage as unknown as Parameters<typeof getAsciiArt>[0],
163+
1,
164+
true,
165+
);
166+
167+
assertEquals(blackResult.includes("█"), true);
168+
});

cli/node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export async function getFaviconUrl(
253253
return new URL("/favicon.ico", response.url);
254254
}
255255

256-
const Jimp = createJimp({
256+
export const Jimp = createJimp({
257257
formats: [...defaultFormats, webp],
258258
plugins: defaultPlugins,
259259
});
@@ -323,7 +323,7 @@ export function rgbTo256Color(r: number, g: number, b: number): number {
323323
return 16 + (36 * r6) + (6 * g6) + b6;
324324
}
325325

326-
function getAsciiArt(
326+
export function getAsciiArt(
327327
image: Awaited<ReturnType<typeof Jimp.read>>,
328328
width = DEFAULT_IMAGE_WIDTH,
329329
trueColorSupport: boolean,

0 commit comments

Comments
 (0)