Files
oh-my-pi/packages/coding-agent/test/visual-truncate.test.ts
T
can1357 8ef11355e7 perf(tui,natives): added native text utilities with JS fast path for short strings
- Added native text utilities in pi-natives (visible width, truncation, slicing, segment extraction)
- Wired pi-tui to use native implementations with short-string JS fast path
- Optimized key matching via cached parsed key ids
- Refactored visual truncation to reuse Text instances
- Reduced theme color lookups by switching from Map to plain records
- Regenerated WASM artifacts

Benchmarks (after vs before, lower is better):
- truncateToWidth/ansi: 20.37ms vs 38.13ms (2000 iters)
- sliceWithWidth/ansi: 5.12ms vs 20.39ms
- extractSegments/ansi: 8.92ms vs 27.60ms
- truncateToVisualLines: 3.51ms vs 411.55ms (500 iters)
- visibleWidth/ansi: 0.24ms vs 0.31ms
2026-01-29 10:47:55 +01:00

28 lines
875 B
TypeScript

import { describe, expect, it } from "bun:test";
import { truncateToVisualLines } from "@oh-my-pi/pi-coding-agent/modes/components/visual-truncate";
describe("truncateToVisualLines", () => {
it("returns empty output for empty text", () => {
const result = truncateToVisualLines("", 3, 10);
expect(result.visualLines).toEqual([]);
expect(result.skippedCount).toBe(0);
});
it("truncates to the last visual lines after wrapping", () => {
const text = "one two three four";
const result = truncateToVisualLines(text, 1, 10, 0);
expect(result.visualLines).toEqual(["three four"]);
expect(result.skippedCount).toBe(1);
});
it("applies horizontal padding to rendered lines", () => {
const text = "one";
const result = truncateToVisualLines(text, 1, 5, 1);
expect(result.visualLines).toEqual([" one "]);
expect(result.skippedCount).toBe(0);
});
});