import { describe, expect, it } from "vitest"; import { contentStats, formatBytes, MAX_INLINE_SIZE } from "$lib/api/blob"; describe("contentStats", () => { it("counts an empty string as no lines and no bytes", () => { expect(contentStats("")).toEqual({ lines: 0, bytes: 0, sizeLabel: "0 B" }); }); it("treats a trailing newline as a terminator, matching the repo blob header", () => { expect(contentStats("a\nb").lines).toBe(2); expect(contentStats("a\nb\n").lines).toBe(2); expect(contentStats("a\n").lines).toBe(1); }); it("sizes utf-8 rather than utf-16 code units", () => { expect(contentStats("é").bytes).toBe(2); expect(contentStats("hi").bytes).toBe(2); }); it("keeps the 1MiB inline cap meaningful for the string loader", () => { expect(contentStats("x".repeat(MAX_INLINE_SIZE)).bytes).toBeLessThanOrEqual( MAX_INLINE_SIZE ); expect(contentStats("x".repeat(MAX_INLINE_SIZE + 1)).bytes).toBeGreaterThan( MAX_INLINE_SIZE ); }); }); describe("formatBytes", () => { it("promotes a rounded spill into the next unit", () => { expect(formatBytes(999)).toBe("999 B"); expect(formatBytes(1000)).toBe("1.0 kB"); expect(formatBytes(999_999)).toBe("1.0 MB"); }); });