@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

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