Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: James Long <longster@gmail.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: runvip <164729189+runvip@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com> Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: Simon Klee <hello@simonklee.dk> Co-authored-by: Jay <air@live.ca> Co-authored-by: David Hill <1879069+iamdavidhill@users.noreply.github.com>
46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import { buildFileTreeV2Model, flattenFileTreeV2 } from "./file-tree-v2-model"
|
|
|
|
describe("file tree v2 model", () => {
|
|
test("builds sorted depth-first rows", () => {
|
|
const model = buildFileTreeV2Model(["src/z.ts", "src/lib/b.ts", "src/lib/a.ts", "README.md", "docs/guide.md"])
|
|
|
|
expect(model.total).toBe(8)
|
|
expect(flattenFileTreeV2(model, () => true).map((row) => [row.node.path, row.node.type, row.level])).toEqual([
|
|
["docs", "directory", 0],
|
|
["docs/guide.md", "file", 1],
|
|
["src", "directory", 0],
|
|
["src/lib", "directory", 1],
|
|
["src/lib/a.ts", "file", 2],
|
|
["src/lib/b.ts", "file", 2],
|
|
["src/z.ts", "file", 1],
|
|
["README.md", "file", 0],
|
|
])
|
|
})
|
|
|
|
test("omits descendants of collapsed directories", () => {
|
|
const model = buildFileTreeV2Model(["src/lib/a.ts", "src/z.ts"])
|
|
|
|
expect(flattenFileTreeV2(model, (path) => path !== "src/lib").map((row) => row.node.path)).toEqual([
|
|
"src",
|
|
"src/lib",
|
|
"src/z.ts",
|
|
])
|
|
})
|
|
|
|
test("normalizes separators and duplicate paths", () => {
|
|
const model = buildFileTreeV2Model(["src\\lib\\a.ts", "src/lib/a.ts", "/src//lib/b.ts/"])
|
|
const rows = flattenFileTreeV2(model, () => true)
|
|
|
|
expect(model.total).toBe(4)
|
|
expect(rows.map((row) => row.node.path)).toEqual(["src", "src/lib", "src/lib/a.ts", "src/lib/b.ts"])
|
|
expect(rows.find((row) => row.node.path === "src/lib/a.ts")?.node.originalPath).toBe("src\\lib\\a.ts")
|
|
})
|
|
|
|
test("supports paths deeper than the legacy recursion limit", () => {
|
|
const file = `${Array.from({ length: 130 }, (_, index) => `dir-${index}`).join("/")}/file.ts`
|
|
const model = buildFileTreeV2Model([file])
|
|
|
|
expect(flattenFileTreeV2(model, () => true)).toHaveLength(131)
|
|
})
|
|
})
|