# test.rules/shared/matchers/location.matcher.test.ts

> 39 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-rules-shared-matchers-location-matcher-test-ts
Source text: https://banes-lab.com/source/testing/test.rules/shared/matchers/location.matcher.test.ts.txt

Listed in [test.rules/shared/matchers](https://banes-lab.com/api/source/testing/test.rules/shared/matchers.md), before [test.rules/shared/matchers/vocabulary.matcher.test.ts](https://banes-lab.com/source/testing/test.rules/shared/matchers/vocabulary.matcher.test.ts.md).

## Contained in

- [test.rules/shared/matchers](https://banes-lab.com/anatomy/testing/folder-testing-test-rules-shared-matchers.md)

## Source

```typescript
import { describe, expect, it } from "vitest";
import {
    hintLiteralsOf,
    isPathLike,
    isSegmentLike,
    joinedPathsOf,
    stringLiteralsOf,
    stripComments,
} from "@ssot/govlab/shared/matchers/location.matcher.ts";
import { relativePath } from "@ssot/paths";

describe("isSegmentLike and isPathLike", () => {
    it("accepts a plain path segment and refuses specifiers, flags and manifests", () => {
        expect(isSegmentLike("folder")).toBe(true);
        expect(isSegmentLike("@scope/pkg")).toBe(false);
        expect(isSegmentLike("--flag")).toBe(false);
        expect(isSegmentLike("package.json")).toBe(false);
    });

    it("treats a slash-joined value or a source filename as path-like and a media type or system path as not", () => {
        expect(isPathLike(`${relativePath("app.member")}/core/probe.ts`)).toBe(true);
        expect(isPathLike("probe.ts")).toBe(true);
        expect(isPathLike("text/plain")).toBe(false);
        expect(isPathLike("/usr/bin/env")).toBe(false);
        expect(isPathLike(".hidden")).toBe(false);
        expect(isPathLike(`${relativePath("govlabHost.shared")}/resolvers/anchor.resolver.ts`)).toBe(false);
    });
});

describe("stripComments and stringLiteralsOf", () => {
    it("drops line and block comments and keeps the literals of the remaining code", () => {
        const text = `const a = "x"; // "hidden"\n/* "also" */ const b = 'y';`;
        expect(stringLiteralsOf(stripComments(text))).toStrictEqual(["x", "y"]);
    });
});

describe("joinedPathsOf and hintLiteralsOf", () => {
    it("joins the literal segments handed to a path join and reads the declared hints", () => {
        const text = `join(root, "a", "b"); const X_HINTS = ["a/b", "c"];`;
        expect(joinedPathsOf(text)).toStrictEqual(["a/b"]);
        expect([...hintLiteralsOf(text)]).toStrictEqual(["a/b", "c"]);
    });
});
```
