mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-26 19:33:31 +00:00
test: tighten byte count and file identity coverage
This commit is contained in:
@@ -2,10 +2,24 @@ import { describe, expect, it } from "vitest";
|
||||
import { jsonUtf8Bytes } from "./json-utf8-bytes.js";
|
||||
|
||||
describe("jsonUtf8Bytes", () => {
|
||||
it("returns utf8 byte length for serializable values", () => {
|
||||
expect(jsonUtf8Bytes({ a: "x", b: [1, 2, 3] })).toBe(
|
||||
Buffer.byteLength(JSON.stringify({ a: "x", b: [1, 2, 3] }), "utf8"),
|
||||
);
|
||||
it.each([
|
||||
{
|
||||
name: "object payloads",
|
||||
value: { a: "x", b: [1, 2, 3] },
|
||||
expected: Buffer.byteLength(JSON.stringify({ a: "x", b: [1, 2, 3] }), "utf8"),
|
||||
},
|
||||
{
|
||||
name: "strings",
|
||||
value: "hello",
|
||||
expected: Buffer.byteLength(JSON.stringify("hello"), "utf8"),
|
||||
},
|
||||
{
|
||||
name: "undefined via string fallback",
|
||||
value: undefined,
|
||||
expected: Buffer.byteLength("undefined", "utf8"),
|
||||
},
|
||||
])("returns utf8 byte length for $name", ({ value, expected }) => {
|
||||
expect(jsonUtf8Bytes(value)).toBe(expected);
|
||||
});
|
||||
|
||||
it("falls back to string conversion when JSON serialization throws", () => {
|
||||
@@ -13,4 +27,8 @@ describe("jsonUtf8Bytes", () => {
|
||||
circular.self = circular;
|
||||
expect(jsonUtf8Bytes(circular)).toBe(Buffer.byteLength("[object Object]", "utf8"));
|
||||
});
|
||||
|
||||
it("uses string conversion for BigInt serialization failures", () => {
|
||||
expect(jsonUtf8Bytes(12n)).toBe(Buffer.byteLength("12", "utf8"));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user