Files
llmx/codex-cli/tests/text-buffer-copy-paste.test.ts
Ilan Bigio 59a180ddec Initial commit
Signed-off-by: Ilan Bigio <ilan@openai.com>
2025-04-16 12:56:08 -04:00

51 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import TextBuffer from "../src/lib/text-buffer.js";
import { describe, it, expect } from "vitest";
// These tests ensure that the TextBuffer copy&paste logic keeps parity with
// the Rust reference implementation (`textarea.rs`). When a multiline
// string *without* a trailing newline is pasted at the beginning of a line,
// the final pasted line should be merged with the text that originally
// followed the caret exactly how most editors behave.
function setupBuffer(): TextBuffer {
return new TextBuffer("ab\ncd\nef");
}
describe("TextBuffer copy/paste multiline", () => {
it("copies a multiline selection without the trailing newline", () => {
const buf = setupBuffer();
// Select from (0,0) → (1,2) ["ab", "cd"]
buf.startSelection(); // anchor at 0,0
buf.move("down"); // 1,0
buf.move("right");
buf.move("right"); // 1,2
const copied = buf.copy();
expect(copied).toBe("ab\ncd");
});
it("pastes the multiline clipboard as separate lines (does not merge with following text)", () => {
const buf = setupBuffer();
// Make the same selection and copy
buf.startSelection();
buf.move("down");
buf.move("right");
buf.move("right");
buf.copy();
// Move caret to the start of the last line and paste
buf.move("down");
buf.move("home"); // (2,0)
const ok = buf.paste();
expect(ok).toBe(true);
// Desired final buffer behaviour should match the Rust reference:
// the final pasted line is *merged* with the original text on the
// insertion row.
expect(buf.getLines()).toEqual(["ab", "cd", "ab", "cdef"]);
});
});