Skip to content

Add boundary tests for text buffer #1027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions codex-cli/tests/text-buffer-boundary.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import TextBuffer from "../src/text-buffer";
import { describe, it, expect } from "vitest";

describe("TextBuffer – boundary tests", () => {
describe("extremely long lines", () => {
it("should handle very long single line", () => {
const longLine = "a".repeat(10000);
const buf = new TextBuffer(longLine);

// Test cursor movement in long line
buf.move("end");
expect(buf.getCursor()).toEqual([0, 10000]);

// Test insert in middle of long line
buf.move("left");
buf.insert("b");
expect(buf.getText().length).toBe(10001);

// Test delete in long line
buf.del();
expect(buf.getText().length).toBe(10000);
});
});

describe("large number of lines", () => {
it("should handle buffer with many lines", () => {
const manyLines = Array(1000).fill("test").join("\n");
const buf = new TextBuffer(manyLines);

// Test cursor movement through many lines
buf.move("end");
expect(buf.getCursor()[0]).toBe(999);

// Test insert at end of many lines
buf.insert("x");
expect(buf.getLines().length).toBe(1000);

// Test newline in middle of many lines
buf.move("up");
buf.move("end");
buf.insert("\n");
expect(buf.getLines().length).toBe(1001);
});
});
});