# tests/core/inspectors/taxonomy.inspector.test.ts

> 59 lines of code and 0 definitions.

Tree: Coordination tree
Language: typescript
Canonical: https://banes-lab.com/anatomy/coordination#file-coordination-tests-core-inspectors-taxonomy-inspector-test-ts
Source text: https://banes-lab.com/assets/sources/source.f976bb26b0506760a8174ec629ed3f4bb178b6ad5e44e36469511af042c14c29.generated.txt

## Source

```typescript
import { describe, it } from "node:test";
import { foreignMarkerIn, isDirectory } from "../../../tools/core/inspectors/taxonomy.inspector.ts";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import assert from "node:assert/strict";
import { resolve } from "node:path";
import { tmpdir } from "node:os";

const SCOPE = {
    foreignGrammar: {
        groupingDelimiters: [
            ["(", ")"],
            ["", "]"],
        ],
        ownershipManifests: ["package.json"],
    },
    ignored: ["node_modules"],
};

const grown = function grown(paths: readonly string[]): string {
    const root = mkdtempSync(resolve(tmpdir(), "taxonomy-inspector-"));
    for (const path of paths) {
        const absolute = resolve(root, path);
        mkdirSync(resolve(absolute, ".."), { recursive: true });
        writeFileSync(absolute, "");
    }
    return root;
};

const withTree = function withTree(paths: readonly string[], probe: (root: string) => void): void {
    const root = grown(paths);
    try {
        probe(root);
    } finally {
        rmSync(root, { force: true, recursive: true });
    }
};

describe("isDirectory", () => {
    it("is true for a folder and false for a file or a missing path", () => {
        withTree(["tools/a.ts"], (root) => {
            assert.equal(isDirectory(root, "tools"), true);
            assert.equal(isDirectory(root, "tools/a.ts"), false);
            assert.equal(isDirectory(root, "missing"), false);
        });
    });
});

describe("foreignMarkerIn", () => {
    it("finds an ownership manifest below the root", () => {
        withTree(["tools/core/nested/package.json"], (root) => {
            assert.deepEqual(foreignMarkerIn(root, "tools", SCOPE)?.evidence, "tools/core/nested/package.json");
        });
    });

    it("finds a grouping folder of another grammar", () => {
        withTree(["tools/(group)/a.ts"], (root) => {
            assert.deepEqual(foreignMarkerIn(root, "tools", SCOPE)?.evidence, "tools/(group)");
        });
    });

    it("skips ignored folders and a pair with an empty delimiter, and finds nothing in a clean tree", () => {
        withTree(["tools/node_modules/package.json", "tools/core/list]/a.ts"], (root) => {
            assert.equal(foreignMarkerIn(root, "tools", SCOPE), null);
        });
    });
});
```
