import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Whole-word Unicode search finds line 151 after 150 partial lines", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("words-project", {
    "src/words.txt": "wörlds\n".repeat(150) + "wörld\n",
    "src/ascii.txt": Array.from({ length: 150 }, (_, n) => `const needleSuffix${n} = 1;\n`).join("") + "needle();\n",
  });
  const thread = await t3.thread({ project, title: "Whole-word search", messages: ["Start"] });
  await t3.open(thread);
  await screen.getByRole("textbox").press("Control+Shift+f");
  await screen.getByRole("button", "Match whole word", { exact: true }).click();
  const input = screen.getByRole("combobox", "Search in words-project");
  await input.fill("needle");
  await screen.getByText("1 results in 1 files", { exact: true }).waitFor();
  await app.screenshot("ascii-control");
  await input.fill("wörld");
  await screen.getByText(/^[01] results in [01] files$/).waitFor();
  await app.screenshot("unicode-whole-word-line-151");
  await expect(screen.getByText("words.txt", { exact: true })).toBeVisible();
});
