test: tighten small helper edge coverage

This commit is contained in:
Peter Steinberger 2026-03-13 19:18:45 +00:00
parent 4f78d8542d
commit 03d076283c
3 changed files with 31 additions and 6 deletions

View File

@ -6,8 +6,11 @@ describe("isValueToken", () => {
{ value: "work", expected: true },
{ value: "-1", expected: true },
{ value: "-1.5", expected: true },
{ value: "-0.5", expected: true },
{ value: "--", expected: false },
{ value: "--dev", expected: false },
{ value: "-", expected: false },
{ value: "", expected: false },
{ value: undefined, expected: false },
])("classifies %j", ({ value, expected }) => {
expect(isValueToken(value)).toBe(expected);
@ -24,6 +27,8 @@ describe("consumeRootOptionToken", () => {
{ args: ["--log-level", "-1.5"], index: 0, expected: 2 },
{ args: ["--profile", "--no-color"], index: 0, expected: 1 },
{ args: ["--profile", "--"], index: 0, expected: 1 },
{ args: ["x", "--profile", "work"], index: 1, expected: 2 },
{ args: ["--log-level", ""], index: 0, expected: 1 },
{ args: ["--unknown"], index: 0, expected: 0 },
{ args: [], index: 0, expected: 0 },
])("consumes %j at %d", ({ args, index, expected }) => {

View File

@ -18,6 +18,11 @@ describe("jsonUtf8Bytes", () => {
value: undefined,
expected: Buffer.byteLength("undefined", "utf8"),
},
{
name: "unicode strings",
value: "🙂",
expected: Buffer.byteLength(JSON.stringify("🙂"), "utf8"),
},
])("returns utf8 byte length for $name", ({ value, expected }) => {
expect(jsonUtf8Bytes(value)).toBe(expected);
});
@ -31,4 +36,8 @@ describe("jsonUtf8Bytes", () => {
it("uses string conversion for BigInt serialization failures", () => {
expect(jsonUtf8Bytes(12n)).toBe(Buffer.byteLength("12", "utf8"));
});
it("uses string conversion for symbol serialization failures", () => {
expect(jsonUtf8Bytes(Symbol("token"))).toBe(Buffer.byteLength("Symbol(token)", "utf8"));
});
});

View File

@ -9,10 +9,21 @@ describe("isPlainObject", () => {
},
);
it.each([null, [], new Date(), /re/, "x", 42, () => null, new Map()])(
"rejects non-plain values: %j",
(value) => {
expect(isPlainObject(value)).toBe(false);
},
);
it.each([
null,
[],
new Date(),
/re/,
"x",
42,
() => null,
new Map(),
{ [Symbol.toStringTag]: "Array" },
])("rejects non-plain values: %j", (value) => {
expect(isPlainObject(value)).toBe(false);
});
it("accepts object-tag values with an explicit Object toStringTag", () => {
expect(isPlainObject({ [Symbol.toStringTag]: "Object" })).toBe(true);
});
});