1import { describe, expect, it } from "bun:test";
2import ignore from "../src/ignore.ts";
3import { cases, SHOULD_TEST_WINDOWS } from "./fixtures/cases.ts";
4
5type UpstreamCase = {
6 description: string;
7 patterns: Parameters<ReturnType<typeof ignore>["add"]>[0];
8 paths_object: Record<string, unknown>;
9 paths: string[];
10 expected: string[];
11 scopes: false | string[];
12};
13
14describe("ignore v7.0.5 upstream cases", () => {
15 cases((testCase: UpstreamCase) => {
16 const { description, patterns, paths_object, paths, expected, scopes } =
17 testCase;
18
19 if (scopes === false || scopes.includes("filter")) {
20 it(`filter: ${description}`, () => {
21 expect(ignore().add(patterns).filter(paths).sort()).toEqual(
22 [...expected].sort(),
23 );
24 });
25
26 it(`createFilter: ${description}`, () => {
27 expect(
28 paths.filter(ignore().add(patterns).createFilter()).sort(),
29 ).toEqual([...expected].sort());
30 });
31 }
32
33 if (scopes === false || scopes.includes("ignores")) {
34 it(`ignores: ${description}`, () => {
35 const matcher = ignore().add(patterns);
36 for (const [path, ignored] of Object.entries(paths_object)) {
37 expect(matcher.ignores(path)).toBe(Boolean(ignored));
38 }
39 });
40 }
41
42 if (scopes === false || scopes.includes("checkIgnore")) {
43 it(`checkIgnore: ${description}`, () => {
44 const matcher = ignore().add(patterns);
45 for (const [path, ignored] of Object.entries(paths_object)) {
46 expect(matcher.checkIgnore(path).ignored).toBe(Boolean(ignored));
47 }
48 });
49 }
50
51 if (
52 SHOULD_TEST_WINDOWS &&
53 (scopes === false || scopes.includes("filter"))
54 ) {
55 it(`win32 filter: ${description}`, () => {
56 const windowsPaths = paths.map((path) => path.replaceAll("/", "\\"));
57 expect(ignore().add(patterns).filter(windowsPaths).sort()).toEqual(
58 expected.map((path) => path.replaceAll("/", "\\")).sort(),
59 );
60 });
61 }
62 });
63});