# test.govlab/quality/core/parsers/knob.parser.test.ts

> 50 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-govlab-quality-core-parsers-knob-parser-test-ts
Source text: https://banes-lab.com/source/testing/test.govlab/quality/core/parsers/knob.parser.test.ts.txt

Listed in [test.govlab/quality/core/parsers](https://banes-lab.com/api/source/testing/test.govlab/quality/core/parsers.md), after [test.govlab/quality/core/parsers/invocation.parser.test.ts](https://banes-lab.com/source/testing/test.govlab/quality/core/parsers/invocation.parser.test.ts.md) and before [test.govlab/quality/core/parsers/location.parser.test.ts](https://banes-lab.com/source/testing/test.govlab/quality/core/parsers/location.parser.test.ts.md).

## Contained in

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

## Source

```typescript
import { describe, expect, it } from "vitest";
import {
    intAfter,
    intAt,
    isDigitsOnly,
    trailingIdentifier,
    withoutRubyTags,
} from "@govlab/quality/core/parsers/knob.parser.ts";

const TWELVE = 12;
const FORTY = 40;
const WINDOW = 8;

describe("intAt", () => {
    it("reads the first digit run after leading non-digits", () => {
        expect(intAt("abc 12 def", 0)).toBe(TWELVE);
        expect(intAt("no digits", 0)).toBeNull();
    });

    it("stops at line and statement boundaries", () => {
        expect(intAt("ab\n12", 0)).toBeNull();
        expect(intAt("ab;12", 0)).toBeNull();
    });
});

describe("intAfter", () => {
    it("finds an integer following a marker within the window", () => {
        expect(intAfter("size = 40;", "size", { from: 0 })).toBe(FORTY);
        expect(intAfter("size = 40;", "size", { from: 0, window: WINDOW })).toBe(FORTY);
        expect(intAfter("nope 5", "size", { from: 0 })).toBeNull();
    });

    it("refuses a marker past the window", () => {
        expect(intAfter("padding padding size = 4", "size", { from: 0, window: 1 })).toBeNull();
    });
});

describe("withoutRubyTags", () => {
    it("strips the ruby tags and keeps plain text", () => {
        expect(withoutRubyTags("x!ruby/z y")).toBe("x y");
        expect(withoutRubyTags("plain")).toBe("plain");
    });
});

describe("isDigitsOnly", () => {
    it("checks a string is all digits", () => {
        expect(isDigitsOnly("123")).toBe(true);
        expect(isDigitsOnly("12a")).toBe(false);
        expect(isDigitsOnly("")).toBe(false);
    });
});

describe("trailingIdentifier", () => {
    it("keeps the trailing identifier run", () => {
        expect(trailingIdentifier("foo-bar_baz")).toBe("bar_baz");
        expect(trailingIdentifier("abc")).toBe("abc");
    });
});
```
