import { describe, test, expect } from "bun:test";
import { stripAnsi } from "@/utils/ansi.js";

describe("stripAnsi", () => {
  test("plain ASCII passes through unchanged", () => {
    expect(stripAnsi("hello world")).toBe("hello world");
  });

  test("strips a single ANSI color sequence", () => {
    expect(stripAnsi("\u001b[31mred\u001b[0m")).toBe("red");
  });

  test("strips multiple ANSI sequences in one string", () => {
    expect(stripAnsi("\u001b[1m\u001b[32mOK\u001b[0m done")).toBe("OK done");
  });

  test("returns empty string for empty input", () => {
    expect(stripAnsi("")).toBe("");
  });

  test("preserves Unicode while removing ANSI sequences", () => {
    expect(stripAnsi("\u001b[36m日本語\u001b[0m café")).toBe("日本語 café");
  });

  test("strips orphaned SGR fragments (no ESC byte prefix)", () => {
    // The implementation removes bracket-style SGR like [32m even when
    // the leading ESC byte was lost in transit (common in HTTP log lines).
    expect(stripAnsi("[32mgreen text[0m")).toBe("green text");
  });
});
