# test.govlab/docs/core/normalizers/diagram.normalizer.test.ts

> 23 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-govlab-docs-core-normalizers-diagram-normalizer-test-ts
Source text: https://banes-lab.com/source/testing/test.govlab/docs/core/normalizers/diagram.normalizer.test.ts.txt

Listed in [test.govlab/docs/core/normalizers](https://banes-lab.com/api/source/testing/test.govlab/docs/core/normalizers.md), before [test.govlab/docs/core/normalizers/reference.normalizer.test.ts](https://banes-lab.com/source/testing/test.govlab/docs/core/normalizers/reference.normalizer.test.ts.md).

## Contained in

- [test.govlab/docs/core/normalizers](https://banes-lab.com/anatomy/testing/folder-testing-test-govlab-docs-core-normalizers.md)

## Source

```typescript
import { describe, expect, it } from "vitest";
import { idSanitize, label, nodeId } from "@govlab/docs/core/normalizers/diagram.normalizer.ts";

describe("label", () => {
    it("drops reserved and non-ASCII characters and collapses whitespace", () => {
        expect(label("run (x) — then;  go")).toBe("run x then, go");
    });
});

describe("idSanitize", () => {
    it("keeps an identifier, fills other characters and prefixes a leading digit", () => {
        expect(idSanitize("a-b.c")).toBe("a_b_c");
        expect(idSanitize("1x")).toBe("n_1x");
        expect(idSanitize("")).toBe("n");
    });
});

describe("nodeId", () => {
    it("builds a stable id from the last name segment plus a hash of the whole name", () => {
        const id = nodeId("src/a.ts#createThing");
        expect(id.startsWith("createThing_")).toBe(true);
        expect(nodeId("src/a.ts#createThing")).toBe(id);
        expect(nodeId("src/b.ts#createThing")).not.toBe(id);
        expect(nodeId("pkg/2fast").startsWith("n2fast_")).toBe(true);
    });
});
```
