# test.govlab/pipeline/core/selectors/violation.selector.test.ts

> 28 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-govlab-pipeline-core-selectors-violation-selector-test-ts
Source text: https://banes-lab.com/source/testing/test.govlab/pipeline/core/selectors/violation.selector.test.ts.txt

Listed in [test.govlab/pipeline/core/selectors](https://banes-lab.com/api/source/testing/test.govlab/pipeline/core/selectors.md), after [test.govlab/pipeline/core/selectors/stage.selector.test.ts](https://banes-lab.com/source/testing/test.govlab/pipeline/core/selectors/stage.selector.test.ts.md).

## Contained in

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

## Source

```typescript
import { describe, expect, it } from "vitest";
import { lastCount } from "@govlab/pipeline/core/selectors/violation.selector.ts";

describe("lastCount", () => {
    it("reads the count that precedes the keyword", () => {
        expect(lastCount("12 errors")).toBe(12);
    });

    it("takes the last occurrence, so a tail summary wins over an earlier line", () => {
        expect(lastCount("3 errors\nsome output\n7 errors")).toBe(7);
    });

    it("prefers the earliest keyword in the vocabulary over a later one", () => {
        expect(lastCount("5 errors, 9 advisories")).toBe(5);
    });

    it("matches regardless of case", () => {
        expect(lastCount("4 PROBLEMS")).toBe(4);
    });

    it("tolerates spaces between the count and the keyword", () => {
        expect(lastCount("8   findings")).toBe(8);
    });

    it("returns null when a keyword carries no leading count", () => {
        expect(lastCount("errors were found")).toBeNull();
    });

    it("returns null when the output names no counted keyword", () => {
        expect(lastCount("everything is fine")).toBeNull();
    });

    it("reads zero as a count rather than as absence", () => {
        expect(lastCount("0 violations")).toBe(0);
    });
});
```
