textui/ui.test.ts

42 lines
1 KiB
TypeScript
Raw Normal View History

2021-06-24 22:41:34 +00:00
import { BufferLocation, BufferSize, Char, Color, SPACE } from "./base.ts";
import { describe, expect, it } from "./testing.ts";
import { Display } from "./display.ts";
import { TextUI } from "./ui.ts";
describe(TextUI, () => {
it("maps a full RGB color palette directly", async () => {
const palette = [
{ r: 0.0, g: 0.0, b: 0.0 },
{ r: 1.0, g: 0.0, b: 0.0 },
];
const display = new PaletteTestDisplay(palette);
const ui = new TextUI(display);
await ui.init(palette);
ui.drawing.color(1, 0).text("x", { x: 0, y: 0 });
await ui.flush();
expect(display.last).toEqual({ ch: "x", bg: 0, fg: 1 });
});
});
class PaletteTestDisplay implements Display {
last = SPACE;
constructor(public palette: Color[]) {
}
async getSize(): Promise<BufferSize> {
return { w: 1, h: 1 };
}
async setupPalette(colors: readonly Color[]): Promise<readonly Color[]> {
return this.palette;
}
async clear(): Promise<void> {
}
async setChar(at: BufferLocation, char: Char): Promise<void> {
this.last = char;
}
}