// cell-size buffer drain — behaviour matches legacy TUI.parseCellSizeResponse

import assert from "node:assert/strict";
import { describe, it } from "vitest";
import { drainCellSizeQueryBuffer } from "../cell-size.js";

describe("drainCellSizeQueryBuffer", () => {
	it("waits_on_incomplete_escape_tail", () => {
		const r = drainCellSizeQueryBuffer("\x1b[6;10;10");
		assert.equal(r.wait, true);
		assert.equal(r.nextBuffer, "\x1b[6;10;10");
		assert.equal(r.forwardInput, "");
	});

	it("forwards_bare_escape_after_pending_buffer", () => {
		const r = drainCellSizeQueryBuffer("\x1b");
		assert.equal(r.wait, false);
		assert.equal(r.forwardInput, "\x1b");
		assert.equal(r.nextBuffer, "");
	});

	it("strips_reported_cell_size_and_emits_cellPixels", () => {
		const buf = "\x1b[6;20;40trest";
		const r = drainCellSizeQueryBuffer(buf);
		assert.ok(r.cellPixels);
		assert.equal(r.cellPixels?.widthPx, 40);
		assert.equal(r.cellPixels?.heightPx, 20);
		assert.equal(r.forwardInput, "rest");
		assert.equal(r.wait, false);
	});
});
