UNPKG

malwoden

Version:

![alt text](./coverage/badge-lines.svg) ![alt text](./coverage/badge-statements.svg) ![alt text](./coverage/badge-functions.svg) ![alt text](./coverage/badge-branches.svg)

107 lines 4.81 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var struct_1 = require("../struct"); var color_1 = require("./color"); var glyph_1 = require("./glyph"); var terminal_1 = require("./terminal"); var TestTerminal = /** @class */ (function (_super) { __extends(TestTerminal, _super); function TestTerminal(config) { var _this = _super.call(this, config) || this; _this.table = new struct_1.Table(config.width, config.height); return _this; } TestTerminal.prototype.windowToTilePoint = function (pixel) { throw new Error("Method not implemented."); }; TestTerminal.prototype.delete = function () { throw new Error("Method not implemented."); }; TestTerminal.prototype.drawGlyph = function (pos, glyph) { this.table.set(pos, glyph); }; return TestTerminal; }(terminal_1.BaseTerminal)); describe("BaseTerminal", function () { it("Can create a new base terminal", function () { var t = new TestTerminal({ width: 10, height: 10, foreColor: color_1.Color.Yellow, backColor: color_1.Color.Green, }); expect(t.width).toEqual(10); expect(t.height).toEqual(10); expect(t.foreColor.isEqual(color_1.Color.Yellow)).toBeTruthy(); expect(t.backColor.isEqual(color_1.Color.Green)).toBeTruthy(); }); it("Can draw a charCode", function () { var t = new TestTerminal({ width: 10, height: 10, }); t.drawCharCode({ x: 1, y: 2 }, 102); var glyph = t.table.get({ x: 1, y: 2 }); expect(glyph === null || glyph === void 0 ? void 0 : glyph.char).toEqual(102); expect(glyph === null || glyph === void 0 ? void 0 : glyph.fore.isEqual(color_1.Color.White)).toBeTruthy(); expect(glyph === null || glyph === void 0 ? void 0 : glyph.back.isEqual(color_1.Color.Black)).toBeTruthy(); t.drawCharCode({ x: 1, y: 2 }, 102, color_1.Color.Green, color_1.Color.Yellow); glyph = t.table.get({ x: 1, y: 2 }); expect(glyph === null || glyph === void 0 ? void 0 : glyph.char).toEqual(102); expect(glyph === null || glyph === void 0 ? void 0 : glyph.fore.isEqual(color_1.Color.Green)).toBeTruthy(); expect(glyph === null || glyph === void 0 ? void 0 : glyph.back.isEqual(color_1.Color.Yellow)).toBeTruthy(); }); it("Can get the size", function () { var t = new TestTerminal({ width: 10, height: 20 }); expect(t.size()).toEqual({ x: 10, y: 20 }); }); it("Can clear", function () { var _a; var t = new TestTerminal({ width: 10, height: 10 }); t.clear(); for (var x = 0; x < 10; x++) { for (var y = 0; y < 10; y++) { expect((_a = t.table.get({ x: x, y: y })) === null || _a === void 0 ? void 0 : _a.isEqual(new glyph_1.Glyph(" "))); } } }); it("Can writeAt", function () { var t = new TestTerminal({ width: 10, height: 10, }); t.writeAt({ x: 1, y: 1 }, "abc"); var a = t.table.get({ x: 1, y: 1 }); var b = t.table.get({ x: 2, y: 1 }); var c = t.table.get({ x: 3, y: 1 }); expect(a.char).toEqual("a".charCodeAt(0)); expect(b.char).toEqual("b".charCodeAt(0)); expect(c.char).toEqual("c".charCodeAt(0)); t.writeAt({ x: 1, y: 1 }, "abc", color_1.Color.Green, color_1.Color.Blue); var a2 = t.table.get({ x: 1, y: 1 }); var b2 = t.table.get({ x: 2, y: 1 }); var c2 = t.table.get({ x: 3, y: 1 }); expect(a2.isEqual(new glyph_1.Glyph("a", color_1.Color.Green, color_1.Color.Blue))); expect(b2.isEqual(new glyph_1.Glyph("b", color_1.Color.Green, color_1.Color.Blue))); expect(c2.isEqual(new glyph_1.Glyph("c", color_1.Color.Green, color_1.Color.Blue))); }); it("Will truncate writeAt if too long", function () { var t = new TestTerminal({ width: 5, height: 5 }); t.writeAt({ x: 0, y: 0 }, "Hello!"); expect(t.table.get({ x: 5, y: 0 })).toEqual(undefined); }); }); //# sourceMappingURL=terminal.spec.js.map