import { findFoldings } from "./folding.js";
import { assertEquals } from "./deps_test.ts";

Deno.test("findFoldings()", async (t) => {
  await t.step("general", () => {
    const lines = [
      " aa",
      "a",
      "a",
      "",
      "ccc",
      " d",
      " d",
      "  d",
      "    d",
      "  d",
      "  d",
      " d",
      "  d",
      "d",
      "  d",
      "",
      "  d",
      "",
      "a",
      " b",
      "  c",
    ].map((text, i) => ({ text, id: `${i}` }));
    assertEquals([...findFoldings(lines)], [
      { id: "0", indent: 1, children: [] },
      { id: "1", indent: 0, children: [] },
      { id: "2", indent: 0, children: [] },
      { id: "3", indent: 0, children: [] },
      { id: "5", indent: 1, children: [] },
      { id: "8", indent: 4, children: [] },
      { id: "7", indent: 2, children: ["8"] },
      { id: "9", indent: 2, children: [] },
      { id: "10", indent: 2, children: [] },
      { id: "6", indent: 1, children: ["7", "8", "9", "10"] },
      { id: "12", indent: 2, children: [] },
      { id: "11", indent: 1, children: ["12"] },
      { id: "4", indent: 0, children: ["5", "6", "7", "8", "9", "10", "11", "12"] },
      { id: "14", indent: 2, children: [] },
      { id: "13", indent: 0, children: ["14"] },
      { id: "16", indent: 2, children: [] },
      { id: "15", indent: 0, children: ["16"] },
      { id: "17", indent: 0, children: [] },
      { id: "20", indent: 2, children: [] },
      { id: "19", indent: 1, children: ["20"] },
      { id: "18", indent: 0, children: ["19", "20" ] },
    ]);
  });
  
  await t.step("no indent", () => {
    const lines = [
      "a",
      "a",
      "a",
    ].map((text, i) => ({ text, id: `${i}` }));
    assertEquals([...findFoldings(lines)], [
      { id: "0", indent: 0, children: [] },
      { id: "1", indent: 0, children: [] },
      { id: "2", indent: 0, children: [] },
    ]);
  })
});