mirror of
https://github.com/millionco/react-doctor.git
synced 2026-09-14 20:00:24 +08:00
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vite-plus/test";
|
|
import { parseFileLineArgument } from "../src/cli/utils/parse-file-line-argument.js";
|
|
|
|
describe("parseFileLineArgument", () => {
|
|
it("parses `path:line` into its parts", () => {
|
|
expect(parseFileLineArgument("src/foo.tsx:42")).toEqual({
|
|
filePath: "src/foo.tsx",
|
|
line: 42,
|
|
});
|
|
});
|
|
|
|
it("uses the LAST colon so paths with colons (Windows drive letters) round-trip", () => {
|
|
expect(parseFileLineArgument("C:/repo/src/foo.tsx:7")).toEqual({
|
|
filePath: "C:/repo/src/foo.tsx",
|
|
line: 7,
|
|
});
|
|
});
|
|
|
|
it("rejects arguments with no colon", () => {
|
|
expect(() => parseFileLineArgument("src/foo.tsx")).toThrowError(/<file>:<line>/);
|
|
});
|
|
|
|
it("rejects empty file paths", () => {
|
|
expect(() => parseFileLineArgument(":42")).toThrowError(/Missing file path/);
|
|
});
|
|
|
|
it("rejects non-positive line numbers", () => {
|
|
expect(() => parseFileLineArgument("src/foo.tsx:0")).toThrowError(/positive line number/);
|
|
expect(() => parseFileLineArgument("src/foo.tsx:-1")).toThrowError(/positive line number/);
|
|
});
|
|
|
|
it("rejects non-numeric line tokens", () => {
|
|
expect(() => parseFileLineArgument("src/foo.tsx:abc")).toThrowError(/positive line number/);
|
|
expect(() => parseFileLineArgument("src/foo.tsx:42abc")).toThrowError(/positive line number/);
|
|
});
|
|
});
|