test: tighten cli root option coverage

This commit is contained in:
Peter Steinberger
2026-03-13 18:30:36 +00:00
parent f0a266cb86
commit 8cef6f2120

View File

@@ -1,16 +1,32 @@
import { describe, expect, it } from "vitest";
import { consumeRootOptionToken } from "./cli-root-options.js";
import { consumeRootOptionToken, isValueToken } from "./cli-root-options.js";
describe("consumeRootOptionToken", () => {
it("consumes boolean and inline root options", () => {
expect(consumeRootOptionToken(["--dev"], 0)).toBe(1);
expect(consumeRootOptionToken(["--profile=work"], 0)).toBe(1);
expect(consumeRootOptionToken(["--log-level=debug"], 0)).toBe(1);
});
it("consumes split root value option only when next token is a value", () => {
expect(consumeRootOptionToken(["--profile", "work"], 0)).toBe(2);
expect(consumeRootOptionToken(["--profile", "--no-color"], 0)).toBe(1);
expect(consumeRootOptionToken(["--profile", "--"], 0)).toBe(1);
describe("isValueToken", () => {
it.each([
{ value: "work", expected: true },
{ value: "-1", expected: true },
{ value: "-1.5", expected: true },
{ value: "--", expected: false },
{ value: "--dev", expected: false },
{ value: undefined, expected: false },
])("classifies %j", ({ value, expected }) => {
expect(isValueToken(value)).toBe(expected);
});
});
describe("consumeRootOptionToken", () => {
it.each([
{ args: ["--dev"], index: 0, expected: 1 },
{ args: ["--profile=work"], index: 0, expected: 1 },
{ args: ["--log-level=debug"], index: 0, expected: 1 },
{ args: ["--profile", "work"], index: 0, expected: 2 },
{ args: ["--profile", "-1"], index: 0, expected: 2 },
{ args: ["--log-level", "-1.5"], index: 0, expected: 2 },
{ args: ["--profile", "--no-color"], index: 0, expected: 1 },
{ args: ["--profile", "--"], index: 0, expected: 1 },
{ args: ["--unknown"], index: 0, expected: 0 },
{ args: [], index: 0, expected: 0 },
])("consumes %j at %d", ({ args, index, expected }) => {
expect(consumeRootOptionToken(args, index)).toBe(expected);
});
});