mirror of
https://github.com/openclaw/openclaw.git
synced 2026-10-03 09:39:25 +00:00
* test(status): deslop s223 tests * test(onepassword): deslop s225 tests * test(mcp): deslop s224 tests * test(scripts): deslop s215 tests * test(fal): deslop s226 tests * test(feishu): deslop s227 tests * test(amazon-bedrock-mantle): deslop s229 tests * test(lobster): deslop s234 tests * test(comfy): deslop s228 tests * test(irc): deslop s230 tests
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
parseStrictNonNegativeDecimal,
|
|
readPositiveEnvInt,
|
|
} from "../../scripts/lib/numeric-options.mjs";
|
|
|
|
describe("parseStrictNonNegativeDecimal", () => {
|
|
it.each([
|
|
["0", 0],
|
|
[" 42 ", 42],
|
|
[42, 42],
|
|
])("parses canonical decimal value %j", (raw, expected) => {
|
|
expect(parseStrictNonNegativeDecimal(raw, "limit")).toBe(expected);
|
|
});
|
|
|
|
it.each(["", "01", "+1", "-1", "1.5", "1e3", "0x10"])("rejects non-canonical value %j", (raw) => {
|
|
expect(() => parseStrictNonNegativeDecimal(raw, "limit")).toThrow(
|
|
"limit must be a non-negative integer",
|
|
);
|
|
});
|
|
|
|
it("distinguishes unsafe canonical integers", () => {
|
|
expect(() => parseStrictNonNegativeDecimal("9007199254740992", "limit")).toThrow(
|
|
"limit must be a safe integer",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("readPositiveEnvInt", () => {
|
|
it("uses the fallback for missing or blank values", () => {
|
|
expect(readPositiveEnvInt("LIMIT", {}, 42)).toBe(42);
|
|
expect(readPositiveEnvInt("LIMIT", { LIMIT: " " }, 42)).toBe(42);
|
|
});
|
|
|
|
it("reads strict positive safe integers", () => {
|
|
expect(readPositiveEnvInt("LIMIT", { LIMIT: " 123 " }, 42)).toBe(123);
|
|
});
|
|
|
|
it.each(["0", "-1", "1.5", "1e3", "0x10", "9007199254740992"])(
|
|
"rejects invalid value %s",
|
|
(raw) => {
|
|
expect(() => readPositiveEnvInt("LIMIT", { LIMIT: raw }, 42)).toThrow(
|
|
`invalid LIMIT: ${raw}`,
|
|
);
|
|
},
|
|
);
|
|
});
|