textui/base.test.ts

25 lines
940 B
TypeScript
Raw Normal View History

2021-05-13 22:04:47 +00:00
import { BufferDrawing, CharBuffer } from "./base.ts";
import { Buffer, describe, expect, it } from "./deps.test.ts";
describe(CharBuffer, () => {
it("initializes empty, sets and gets characters", () => {
const buffer = new CharBuffer({ w: 3, h: 2 });
expect(buffer.toString()).toEqual(" ");
buffer.set({ x: 2, y: 0 }, { ch: "x", fg: 1, bg: 4 });
buffer.set({ x: 1, y: 1 }, { ch: "y", fg: 2, bg: 5 });
expect(buffer.toString()).toEqual(" x y ");
expect(buffer.get({ x: 0, y: 0 })).toEqual({ ch: " ", fg: 0, bg: 0 });
expect(buffer.get({ x: 1, y: 1 })).toEqual({ ch: "y", fg: 2, bg: 5 });
});
});
describe(BufferDrawing, () => {
it("draws text", () => {
const buffer = new CharBuffer({ w: 4, h: 2 });
const drawing = new BufferDrawing(buffer);
drawing.text("testing", { x: -1, y: 0 });
drawing.text("so", { x: 1, y: 1 });
expect(buffer.toString()).toEqual("esti so ");
});
});