Increase test coverage

This commit is contained in:
Timothy Warren 2023-11-21 16:36:13 -05:00
parent 3d98eefc65
commit a7f5fed9a3
2 changed files with 61 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import Editor from './editor.ts';
import Row from './row.ts';
import { getTestRunner } from './runtime.ts';
import { defaultTerminalSize } from './termios.ts';
import { Position } from './types.ts';
import * as Util from './utils.ts';
const {
@ -39,6 +40,16 @@ testSuite({
assertEquals(readKey(KeyCommand.Home), KeyCommand.Home);
assertEquals(readKey(KeyCommand.Delete), KeyCommand.Delete);
},
'readKey Esc': () => {
['\x1b', Util.ctrlKey('l')].forEach((code) => {
assertEquals(readKey(code), KeyCommand.Escape);
});
},
'readKey Backspace': () => {
[Util.ctrlKey('h'), String.fromCodePoint(127)].forEach((code) => {
assertEquals(readKey(code), KeyCommand.Backspace);
});
},
'readKey Home': () => {
['\x1b[1~', '\x1b[7~', '\x1b[H', '\x1bOH'].forEach((code) => {
assertEquals(readKey(code), KeyCommand.Home);
@ -103,6 +114,29 @@ testSuite({
assertFalse(doc.isEmpty());
assertInstanceOf(doc.row(0), Row);
},
'Document.insert': () => {
const doc = Document.empty();
assertFalse(doc.dirty);
doc.insert(Position.at(0, 0), 'foobar');
assertEquals(doc.numRows, 1);
assertTrue(doc.dirty);
doc.insert(Position.at(2, 0), 'baz');
assertEquals(doc.numRows, 1);
assertTrue(doc.dirty);
doc.insert(Position.at(9, 0), 'buzz');
assertEquals(doc.numRows, 1);
assertTrue(doc.dirty);
const row0 = doc.row(0);
assertEquals(row0?.toString(), 'foobazbarbuzz');
assertEquals(row0?.rstring(), 'foobazbarbuzz');
assertEquals(row0?.rsize, 13);
doc.insert(Position.at(0, 1), 'Lorem Ipsum');
assertEquals(doc.numRows, 2);
assertTrue(doc.dirty);
},
},
Editor: {
'new Editor': () => {
@ -110,19 +144,43 @@ testSuite({
assertInstanceOf(e, Editor);
},
},
Position: {
'default': () => {
const p = Position.default();
assertEquals(p.x, 0);
assertEquals(p.y, 0);
},
'at': () => {
const p = Position.at(5, 7);
assertEquals(p.x, 5);
assertEquals(p.y, 7);
},
},
Row: {
'new Row': () => {
const row = new Row();
assertEquals(row.toString(), '');
},
},
'Util::Misc fns': {
'Util misc fns': {
'noop fn': () => {
assertExists(Util.noop);
assertEquals(Util.noop(), undefined);
},
'posSub()': () => {
assertEquals(Util.posSub(14, 15), 0);
assertEquals(Util.posSub(15, 1), 14);
},
'Util::String fns': {
'minSub()': () => {
assertEquals(Util.minSub(13, 25, -1), -1);
assertEquals(Util.minSub(25, 13, 0), 12);
},
'maxAdd()': () => {
assertEquals(Util.maxAdd(99, 99, 75), 75);
assertEquals(Util.maxAdd(25, 74, 101), 99);
},
},
'Util string fns': {
'ord()': () => {
// Invalid output
assertEquals(Util.ord(''), 256);

View File

@ -75,7 +75,7 @@ export function readKey(parsed: string): string {
case '\x1b':
return KeyCommand.Escape;
case ctrlKey('H'):
case ctrlKey('h'):
case String.fromCodePoint(127):
return KeyCommand.Backspace;