Download src/cli/shared/parse-port.test.ts from SaylorTwift/openclaw: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/cli/shared/parse-port.test.ts
- Command line
-
hf download hf://SaylorTwift/openclaw/src/cli/shared/parse-port.test.ts
-
curl -L -o parse-port.test.ts https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/cli/shared/parse-port.test.ts
1.55 kB
| // Parse port tests cover shared CLI port parsing and validation. | |
| import { describe, expect, it } from "vitest"; | |
| import { parsePort } from "./parse-port.js"; | |
| describe("parsePort (#83899, #83900)", () => { | |
| it("returns null for nullish inputs", () => { | |
| expect(parsePort(undefined)).toBeNull(); | |
| expect(parsePort(null)).toBeNull(); | |
| }); | |
| it("returns null for zero and negative values", () => { | |
| expect(parsePort(0)).toBeNull(); | |
| expect(parsePort(-1)).toBeNull(); | |
| expect(parsePort("0")).toBeNull(); | |
| }); | |
| it("accepts valid TCP port values", () => { | |
| expect(parsePort(1)).toBe(1); | |
| expect(parsePort(8080)).toBe(8080); | |
| expect(parsePort("8080")).toBe(8080); | |
| expect(parsePort("3000")).toBe(3000); | |
| expect(parsePort(" 65535 ")).toBe(65_535); | |
| }); | |
| it("rejects port numbers above 65535", () => { | |
| expect(parsePort(65_536)).toBeNull(); | |
| expect(parsePort(99999)).toBeNull(); | |
| expect(parsePort("100000")).toBeNull(); | |
| expect(parsePort(Number.MAX_SAFE_INTEGER + 1)).toBeNull(); | |
| // Largest 16-bit value is the inclusive boundary. | |
| expect(parsePort(65_535)).toBe(65_535); | |
| }); | |
| it("rejects non-integer and non-finite inputs", () => { | |
| expect(parsePort(1.5)).toBeNull(); | |
| expect(parsePort("1.5")).toBeNull(); | |
| expect(parsePort(Number.NaN)).toBeNull(); | |
| expect(parsePort(Number.POSITIVE_INFINITY)).toBeNull(); | |
| expect(parsePort("abc")).toBeNull(); | |
| expect(parsePort("8080ms")).toBeNull(); | |
| expect(parsePort("0x10")).toBeNull(); | |
| expect(parsePort("1e3")).toBeNull(); | |
| }); | |
| }); | |