tests for CellData

This commit is contained in:
Jörg Breitbart
2019-01-12 18:44:10 +01:00
parent 35a6aa8326
commit 40b231edd1
2 changed files with 31 additions and 2 deletions
+27 -1
View File
@@ -3,7 +3,7 @@
* @license MIT
*/
import * as chai from 'chai';
import { BufferLine, CellData } from './BufferLine';
import { BufferLine, CellData, Content } from './BufferLine';
import { CharData, IBufferLine } from './Types';
import { NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, DEFAULT_ATTR } from './Buffer';
@@ -18,6 +18,32 @@ class TestBufferLine extends BufferLine {
}
}
describe('CellData', () => {
it('CharData <--> CellData equality', () => {
const cell = new CellData();
// ASCII
cell.setFromCharData([123, 'a', 1, 'a'.charCodeAt(0)]);
chai.assert.deepEqual(cell.asCharData, [123, 'a', 1, 'a'.charCodeAt(0)]);
chai.assert.equal(cell.combined, 0);
// combining
cell.setFromCharData([123, 'e\u0301', 1, '\u0301'.charCodeAt(0)]);
chai.assert.deepEqual(cell.asCharData, [123, 'e\u0301', 1, '\u0301'.charCodeAt(0)]);
chai.assert.equal(cell.combined, Content.IS_COMBINED);
// surrogate
cell.setFromCharData([123, '𝄞', 1, 0x1D11E]);
chai.assert.deepEqual(cell.asCharData, [123, '𝄞', 1, 0x1D11E]);
chai.assert.equal(cell.combined, 0);
// surrogate + combining
cell.setFromCharData([123, '𓂀\u0301', 1, '𓂀\u0301'.charCodeAt(2)]);
chai.assert.deepEqual(cell.asCharData, [123, '𓂀\u0301', 1, '𓂀\u0301'.charCodeAt(2)]);
chai.assert.equal(cell.combined, Content.IS_COMBINED);
// wide char
cell.setFromCharData([123, '', 2, ''.charCodeAt(0)]);
chai.assert.deepEqual(cell.asCharData, [123, '', 2, ''.charCodeAt(0)]);
chai.assert.equal(cell.combined, 0);
});
});
describe('BufferLine', function(): void {
it('ctor', function(): void {
let line: IBufferLine = new TestBufferLine(0);
+4 -1
View File
@@ -78,6 +78,8 @@ export const enum Content {
/**
* CellData - represents a single Cell in the terminal buffer.
*
* TODO: attr getter
*/
export class CellData implements ICellData {
@@ -136,8 +138,9 @@ export class CellData implements ICellData {
} else {
combined = true;
}
} else {
combined = true;
}
combined = true;
} else {
this.content = value[CHAR_DATA_CHAR_INDEX].charCodeAt(0) | (value[CHAR_DATA_WIDTH_INDEX] << Content.WIDTH_SHIFT);
}