Mess with function imports
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
This commit is contained in:
parent
f19fc1d2e0
commit
b3177cbd48
@ -223,24 +223,28 @@ testSuite({
|
|||||||
},
|
},
|
||||||
'fns': {
|
'fns': {
|
||||||
'arrayInsert() strings': () => {
|
'arrayInsert() strings': () => {
|
||||||
|
const { arrayInsert } = Fn;
|
||||||
|
|
||||||
const a = ['😺', '😸', '😹'];
|
const a = ['😺', '😸', '😹'];
|
||||||
const b = Fn.arrayInsert(a, 1, 'x');
|
const b = arrayInsert(a, 1, 'x');
|
||||||
const c = ['😺', 'x', '😸', '😹'];
|
const c = ['😺', 'x', '😸', '😹'];
|
||||||
assertEquals(b, c);
|
assertEquals(b, c);
|
||||||
|
|
||||||
const d = Fn.arrayInsert(c, 17, 'y');
|
const d = arrayInsert(c, 17, 'y');
|
||||||
const e = ['😺', 'x', '😸', '😹', 'y'];
|
const e = ['😺', 'x', '😸', '😹', 'y'];
|
||||||
assertEquals(d, e);
|
assertEquals(d, e);
|
||||||
|
|
||||||
assertEquals(Fn.arrayInsert([], 0, 'foo'), ['foo']);
|
assertEquals(arrayInsert([], 0, 'foo'), ['foo']);
|
||||||
},
|
},
|
||||||
'arrayInsert() numbers': () => {
|
'arrayInsert() numbers': () => {
|
||||||
|
const { arrayInsert } = Fn;
|
||||||
|
|
||||||
const a = [1, 3, 5];
|
const a = [1, 3, 5];
|
||||||
const b = [1, 3, 4, 5];
|
const b = [1, 3, 4, 5];
|
||||||
assertEquals(Fn.arrayInsert(a, 2, 4), b);
|
assertEquals(arrayInsert(a, 2, 4), b);
|
||||||
|
|
||||||
const c = [1, 2, 3, 4, 5];
|
const c = [1, 2, 3, 4, 5];
|
||||||
assertEquals(Fn.arrayInsert(b, 1, 2), c);
|
assertEquals(arrayInsert(b, 1, 2), c);
|
||||||
},
|
},
|
||||||
'noop fn': () => {
|
'noop fn': () => {
|
||||||
assertExists(Fn.noop);
|
assertExists(Fn.noop);
|
||||||
@ -259,54 +263,68 @@ testSuite({
|
|||||||
assertEquals(Fn.maxAdd(25, 74, 101), 99);
|
assertEquals(Fn.maxAdd(25, 74, 101), 99);
|
||||||
},
|
},
|
||||||
'ord()': () => {
|
'ord()': () => {
|
||||||
|
const { ord } = Fn;
|
||||||
|
|
||||||
// Invalid output
|
// Invalid output
|
||||||
assertEquals(Fn.ord(''), 256);
|
assertEquals(ord(''), 256);
|
||||||
|
|
||||||
// Valid output
|
// Valid output
|
||||||
assertEquals(Fn.ord('a'), 97);
|
assertEquals(ord('a'), 97);
|
||||||
},
|
},
|
||||||
'strChars() properly splits strings into unicode characters': () => {
|
'strChars() properly splits strings into unicode characters': () => {
|
||||||
assertEquals(Fn.strChars('😺😸😹'), ['😺', '😸', '😹']);
|
const { strChars } = Fn;
|
||||||
|
|
||||||
|
assertEquals(strChars('😺😸😹'), ['😺', '😸', '😹']);
|
||||||
},
|
},
|
||||||
'ctrlKey()': () => {
|
'ctrlKey()': () => {
|
||||||
const ctrl_a = Fn.ctrlKey('a');
|
const { ctrlKey, isControl } = Fn;
|
||||||
assertTrue(Fn.isControl(ctrl_a));
|
|
||||||
|
const ctrl_a = ctrlKey('a');
|
||||||
|
assertTrue(isControl(ctrl_a));
|
||||||
assertEquals(ctrl_a, String.fromCodePoint(0x01));
|
assertEquals(ctrl_a, String.fromCodePoint(0x01));
|
||||||
|
|
||||||
const invalid = Fn.ctrlKey('😺');
|
const invalid = ctrlKey('😺');
|
||||||
assertFalse(Fn.isControl(invalid));
|
assertFalse(isControl(invalid));
|
||||||
assertEquals(invalid, '😺');
|
assertEquals(invalid, '😺');
|
||||||
},
|
},
|
||||||
'isAscii()': () => {
|
'isAscii()': () => {
|
||||||
assertTrue(Fn.isAscii('asjyverkjhsdf1928374'));
|
const { isAscii } = Fn;
|
||||||
assertFalse(Fn.isAscii('😺acalskjsdf'));
|
|
||||||
assertFalse(Fn.isAscii('ab😺ac'));
|
assertTrue(isAscii('asjyverkjhsdf1928374'));
|
||||||
|
assertFalse(isAscii('😺acalskjsdf'));
|
||||||
|
assertFalse(isAscii('ab😺ac'));
|
||||||
},
|
},
|
||||||
'isControl()': () => {
|
'isControl()': () => {
|
||||||
assertFalse(Fn.isControl('abc'));
|
const { isControl } = Fn;
|
||||||
assertTrue(Fn.isControl(String.fromCodePoint(0x01)));
|
|
||||||
assertFalse(Fn.isControl('😺'));
|
assertFalse(isControl('abc'));
|
||||||
|
assertTrue(isControl(String.fromCodePoint(0x01)));
|
||||||
|
assertFalse(isControl('😺'));
|
||||||
},
|
},
|
||||||
'strlen()': () => {
|
'strlen()': () => {
|
||||||
|
const { strlen } = Fn;
|
||||||
|
|
||||||
// Ascii length
|
// Ascii length
|
||||||
assertEquals(Fn.strlen('abc'), 'abc'.length);
|
assertEquals(strlen('abc'), 'abc'.length);
|
||||||
|
|
||||||
// Get number of visible unicode characters
|
// Get number of visible unicode characters
|
||||||
assertEquals(Fn.strlen('😺😸😹'), 3);
|
assertEquals(strlen('😺😸😹'), 3);
|
||||||
assertNotEquals('😺😸😹'.length, Fn.strlen('😺😸😹'));
|
assertNotEquals('😺😸😹'.length, strlen('😺😸😹'));
|
||||||
|
|
||||||
// Skin tone modifier + base character
|
// Skin tone modifier + base character
|
||||||
assertEquals(Fn.strlen('🤰🏼'), 2);
|
assertEquals(strlen('🤰🏼'), 2);
|
||||||
assertNotEquals('🤰🏼'.length, Fn.strlen('🤰🏼'));
|
assertNotEquals('🤰🏼'.length, strlen('🤰🏼'));
|
||||||
|
|
||||||
// This has 4 sub-characters, and 3 zero-width-joiners
|
// This has 4 sub-characters, and 3 zero-width-joiners
|
||||||
assertEquals(Fn.strlen('👨👩👧👦'), 7);
|
assertEquals(strlen('👨👩👧👦'), 7);
|
||||||
assertNotEquals('👨👩👧👦'.length, Fn.strlen('👨👩👧👦'));
|
assertNotEquals('👨👩👧👦'.length, strlen('👨👩👧👦'));
|
||||||
},
|
},
|
||||||
'truncate()': () => {
|
'truncate()': () => {
|
||||||
assertEquals(Fn.truncate('😺😸😹', 1), '😺');
|
const { truncate } = Fn;
|
||||||
assertEquals(Fn.truncate('😺😸😹', 5), '😺😸😹');
|
|
||||||
assertEquals(Fn.truncate('👨👩👧👦', 5), '👨👩👧');
|
assertEquals(truncate('😺😸😹', 1), '😺');
|
||||||
|
assertEquals(truncate('😺😸😹', 5), '😺😸😹');
|
||||||
|
assertEquals(truncate('👨👩👧👦', 5), '👨👩👧');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'readKey()': {
|
'readKey()': {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { SCROLL_TAB_SIZE } from './config.ts';
|
import { SCROLL_TAB_SIZE } from './config.ts';
|
||||||
import * as Util from './fns.ts';
|
import { arrayInsert, strChars } from './fns.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One row of text in the current document
|
* One row of text in the current document
|
||||||
@ -17,7 +17,7 @@ export class Row {
|
|||||||
render: string[] = [];
|
render: string[] = [];
|
||||||
|
|
||||||
private constructor(s: string | string[] = '') {
|
private constructor(s: string | string[] = '') {
|
||||||
this.chars = Array.isArray(s) ? s : Util.strChars(s);
|
this.chars = Array.isArray(s) ? s : strChars(s);
|
||||||
this.render = [];
|
this.render = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,16 +46,16 @@ export class Row {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public append(s: string): void {
|
public append(s: string): void {
|
||||||
this.chars = this.chars.concat(Util.strChars(s));
|
this.chars = this.chars.concat(strChars(s));
|
||||||
this.updateRender();
|
this.updateRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
public insertChar(at: number, c: string): void {
|
public insertChar(at: number, c: string): void {
|
||||||
const newSlice = Util.strChars(c);
|
const newSlice = strChars(c);
|
||||||
if (at >= this.size) {
|
if (at >= this.size) {
|
||||||
this.chars = this.chars.concat(newSlice);
|
this.chars = this.chars.concat(newSlice);
|
||||||
} else {
|
} else {
|
||||||
this.chars = Util.arrayInsert(this.chars, at + 1, newSlice);
|
this.chars = arrayInsert(this.chars, at + 1, newSlice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ export class Row {
|
|||||||
' '.repeat(SCROLL_TAB_SIZE),
|
' '.repeat(SCROLL_TAB_SIZE),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.render = Util.strChars(newString);
|
this.render = strChars(newString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user