import { describe, it, expect, beforeEach } from "vitest"; import { editorConfig, setContextStats, getContextStats, setGitInfo, getGitInfo, updateGitInfo, ContextStats, GitInfo } from "./MinimalEditor"; describe("Prompt Variables", () => { beforeEach(() => { // Reset to defaults editorConfig.prefix = "%d > "; editorConfig.cwd = "/test/project"; }); describe("Time variable %td%", () => { it("should format time as HH:MM:SS", () => { const now = new Date(); const timeStr = now.toTimeString().slice(0, 8); expect(timeStr).toMatch(/^\d{2}:\d{2}:\d{2}$/); }); }); describe("Git info functions", () => { it("should export updateGitInfo function", () => { expect(typeof updateGitInfo).toBe("function"); }); it("should export setGitInfo function", () => { expect(typeof setGitInfo).toBe("function"); }); it("should handle non-git directories gracefully", () => { editorConfig.cwd = "/tmp"; setGitInfo(null); // Reset updateGitInfo(); // Should not throw }); }); describe("Context stats", () => { it("should export setContextStats function", () => { expect(typeof setContextStats).toBe("function"); }); it("should export getContextStats function", () => { expect(typeof getContextStats).toBe("function"); }); it("should accept valid context stats", () => { const stats: ContextStats = { tokens: 50000, contextWindow: 200000, percent: 25, }; setContextStats(stats); expect(getContextStats()).toEqual(stats); }); it("should handle null stats", () => { setContextStats(null); expect(getContextStats()).toBeNull(); }); }); describe("Escape sequences", () => { it("should handle %% as literal percent", () => { editorConfig.prefix = "100%% disk used"; expect(editorConfig.prefix).toContain("%%"); }); }); }); describe("ContextStats interface", () => { it("should have correct shape", () => { const stats: ContextStats = { tokens: 100000, contextWindow: 200000, percent: 50, }; expect(stats.tokens).toBe(100000); expect(stats.contextWindow).toBe(200000); expect(stats.percent).toBe(50); }); }); describe("GitInfo interface", () => { it("should have correct shape", () => { const info: GitInfo = { branch: "main", modified: true, staged: false, untracked: true, }; expect(info.branch).toBe("main"); expect(info.modified).toBe(true); expect(info.staged).toBe(false); expect(info.untracked).toBe(true); }); });