# tests/core/matchers/reference.matcher.test.ts

> 37 lines of code and 0 definitions.

Tree: Coordination tree
Language: typescript
Canonical: https://banes-lab.com/anatomy/coordination#file-coordination-tests-core-matchers-reference-matcher-test-ts
Source text: https://banes-lab.com/assets/sources/source.213527ec7251ce703a9a0e7dc641359e3de511927c6d343fff29cf93d505d35d.generated.txt

## Source

```typescript
import type { Inline, Segment } from "../../../tools/core/types/segment.types.ts";
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { referencesIn } from "../../../tools/core/matchers/reference.matcher.ts";

const inline = function inline(value: string): Inline {
    return { end: 0, kind: "inline-code", line: 3, start: 0, value };
};

const segment = function segment(fields: Partial<Segment>): Segment {
    return { end: 0, inlines: [], kind: "text", line: 3, start: 0, text: "", ...fields };
};

describe("referencesIn", () => {
    it("reads a path from a reference field, dropping its scheme, anchor and line locator", () => {
        const field = segment({ key: "see", kind: "field", value: "local:tools/core/a.ts#part:12 and more" });
        assert.deepEqual(referencesIn(field), [
            { line: 3, locus: "see:", raw: "local:tools/core/a.ts#part:12 and more", target: "tools/core/a.ts" },
        ]);
    });

    it("reads inline paths and skips external links, bare names, folders and patterns", () => {
        const text = segment({
            inlines: [
                "`tools/b.md`",
                "https://example.com/a.md",
                "a.md",
                "tools/core",
                "tools/<name>.md",
                "@scope/pkg/c.ts",
            ].map(inline),
        });
        assert.deepEqual(
            referencesIn(text).map((reference) => reference.target),
            ["tools/b.md", "scope/pkg/c.ts"],
        );
    });

    it("ignores fields that carry no reference", () => {
        assert.deepEqual(referencesIn(segment({ key: "owner", kind: "field", value: "tools/a.ts" })), []);
    });
});
```
