Commit f72f2c50 authored by Kim, Hyeonseo's avatar Kim, Hyeonseo
Browse files

feat: enhance getAsciiArt tests for color support and update test descriptions

parent 99af9e62
Loading
Loading
Loading
Loading
+61 −5
Original line number Diff line number Diff line
import { assertEquals } from "@std/assert";
import fetchMock from "fetch-mock";
import { getAsciiArt, getFaviconUrl, Jimp, rgbTo256Color } from "./node.ts";
import { checkTerminalColorSupport, getAsciiArt, getFaviconUrl, Jimp, rgbTo256Color } from "./node.ts";

const HTML_WITH_SMALL_ICON = `
<!DOCTYPE html>
@@ -152,7 +152,7 @@ Deno.test("rgbTo256Color - check grayscale", () => {
  assertEquals(results, expected_gray_idx);
});

Deno.test("getAsciiArt - Darkest Letter", async () => {
Deno.test("getAsciiArt - Darkest Letter without color support", async () => {
  // Create black and white 1x1 images using Jimp constructor
  const blackImage = new Jimp({ width: 1, height: 1, color: 0x000000ff });
  const blackImageBuffer = await blackImage.getBuffer("image/webp");
@@ -160,13 +160,13 @@ Deno.test("getAsciiArt - Darkest Letter", async () => {
  const blackResult = getAsciiArt(
    await Jimp.read(blackImageBuffer),
    1,
    true,
    "none",
  );

  assertEquals(blackResult, "");
});

Deno.test("getAsciiArt - Brightest Letter", async () => {
Deno.test("getAsciiArt - Brightest Letter without color support", async () => {
  // Create black and white 1x1 images using Jimp constructor
  const whiteImage = new Jimp({ width: 1, height: 1, color: 0xffffffff });
  const whiteImageBuffer = await whiteImage.getBuffer("image/webp");
@@ -174,8 +174,64 @@ Deno.test("getAsciiArt - Brightest Letter", async () => {
  const whiteResult = getAsciiArt(
    await Jimp.read(whiteImageBuffer),
    1,
    true,
    "none",
  );

  assertEquals(whiteResult, " ");
});

Deno.test("getAsciiArt - Darkest Letter with 256 color support", async () => {
  // Create black and white 1x1 images using Jimp constructor
  const blackImage = new Jimp({ width: 1, height: 1, color: 0x000000ff });
  const blackImageBuffer = await blackImage.getBuffer("image/webp");
  
  const blackResult = getAsciiArt(
    await Jimp.read(blackImageBuffer),
    1,
    "256color",
  );

  assertEquals(blackResult, "\u001b[38;5;16m█\u001b[39m");
});

Deno.test("getAsciiArt - Brightest Letter with 256 color support", async () => {
  // Create black and white 1x1 images using Jimp constructor
  const whiteImage = new Jimp({ width: 1, height: 1, color: 0xffffffff });
  const whiteImageBuffer = await whiteImage.getBuffer("image/webp");

  const whiteResult = getAsciiArt(
    await Jimp.read(whiteImageBuffer),
    1,
    "256color",
  );

  assertEquals(whiteResult, "\u001b[38;5;231m \u001b[39m");
});

Deno.test("getAsciiArt - Darkest Letter with true color support", async () => {
  // Create black and white 1x1 images using Jimp constructor
  const blackImage = new Jimp({ width: 1, height: 1, color: 0x000000ff });
  const blackImageBuffer = await blackImage.getBuffer("image/webp");
  
  const blackResult = getAsciiArt(
    await Jimp.read(blackImageBuffer),
    1,
    "truecolor",
  );

  assertEquals(blackResult, "\u001b[38;2;0;0;0m█\u001b[39m");
});

Deno.test("getAsciiArt - Brightest Letter with true color support", async () => {
  // Create black and white 1x1 images using Jimp constructor
  const whiteImage = new Jimp({ width: 1, height: 1, color: 0xffffffff });
  const whiteImageBuffer = await whiteImage.getBuffer("image/webp");

  const whiteResult = getAsciiArt(
    await Jimp.read(whiteImageBuffer),
    1,
    "truecolor",
  );

  assertEquals(whiteResult, "\u001b[38;2;255;255;255m \u001b[39m");
});