# test.content/core/normalizers/word.normalizer.test.ts

> 31 lines of code and 0 definitions.

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

Listed in [test.content/core/normalizers](https://banes-lab.com/api/source/testing/test.content/core/normalizers.md), after [test.content/core/normalizers/sentence.normalizer.test.ts](https://banes-lab.com/source/testing/test.content/core/normalizers/sentence.normalizer.test.ts.md).

## Contained in

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

## Source

```typescript
import {
    countAny,
    countTerm,
    digitMetricsOf,
    isDigitMetric,
    lowerWordsOf,
    wordsOf,
} from "@banes-lab/content/core/normalizers/word.normalizer.ts";
import { describe, expect, it } from "vitest";

const UNITS = ["ms", "s", "%"];

describe("wordsOf and lowerWordsOf", () => {
    it("splits on punctuation and whitespace and lowers on request", () => {
        expect(wordsOf("Read the file, then Verify.")).toStrictEqual(["Read", "the", "file", "then", "Verify"]);
        expect(lowerWordsOf("A B")).toStrictEqual(["a", "b"]);
    });
});

describe("countTerm and countAny", () => {
    it("matches a term only at word boundaries", () => {
        expect(countTerm("a novel idea; novelty is not novel", "novel")).toBe(2);
        expect(countAny("robust and elegant, robustly", ["robust", "elegant"])).toBe(2);
    });
});

describe("isDigitMetric and digitMetricsOf", () => {
    it("recognizes a number followed by a unit and nothing else", () => {
        expect(isDigitMetric("300ms", UNITS)).toBe(true);
        expect(isDigitMetric("40%", UNITS)).toBe(true);
        expect(isDigitMetric("ms", UNITS)).toBe(false);
        expect(isDigitMetric("files", UNITS)).toBe(false);
        expect(digitMetricsOf("300ms and 2.5s but not 150 lines", UNITS)).toBe(2);
    });
});
```
