Merge pull request #2203 from Tyriar/char_width
Move CharWidth into common and move API tests into ./test
This commit is contained in:
Vendored
+6
-3
@@ -13,10 +13,13 @@
|
|||||||
"runtimeArgs": [
|
"runtimeArgs": [
|
||||||
"--colors",
|
"--colors",
|
||||||
"--recursive",
|
"--recursive",
|
||||||
"${workspaceRoot}/lib/**/*.test.js"
|
"${workspaceRoot}/out/**/*.test.js"
|
||||||
],
|
],
|
||||||
|
"env": {
|
||||||
|
"NODE_PATH": "${workspaceRoot}/out"
|
||||||
|
},
|
||||||
"sourceMaps": true,
|
"sourceMaps": true,
|
||||||
"outFiles": [ "${workspaceRoot}/lib/**/*.js" ],
|
"outFiles": [ "${workspaceRoot}/out/**/*.js" ],
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -31,7 +34,7 @@
|
|||||||
"runtimeArgs": [
|
"runtimeArgs": [
|
||||||
"--colors",
|
"--colors",
|
||||||
"--recursive",
|
"--recursive",
|
||||||
"${workspaceRoot}/lib/**/*.api.js"
|
"${workspaceRoot}/out/**/*.api.js"
|
||||||
],
|
],
|
||||||
"sourceMaps": true,
|
"sourceMaps": true,
|
||||||
"outFiles": [ "${workspaceRoot}/lib/**/*.js" ],
|
"outFiles": [ "${workspaceRoot}/lib/**/*.js" ],
|
||||||
|
|||||||
+1
-3
@@ -12,9 +12,7 @@ env.NODE_PATH = path.resolve(__dirname, '../out');
|
|||||||
|
|
||||||
let testFiles = [
|
let testFiles = [
|
||||||
'./out/*test.js',
|
'./out/*test.js',
|
||||||
'./out/**/*test.js',
|
'./out/**/*test.js'
|
||||||
'./out/*integration.js',
|
|
||||||
'./out/**/*integration.js'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// ability to inject particular test files via
|
// ability to inject particular test files via
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
import { IInputHandler, IInputHandlingTerminal } from './Types';
|
import { IInputHandler, IInputHandlingTerminal } from './Types';
|
||||||
import { C0, C1 } from 'common/data/EscapeSequences';
|
import { C0, C1 } from 'common/data/EscapeSequences';
|
||||||
import { CHARSETS, DEFAULT_CHARSET } from 'core/data/Charsets';
|
import { CHARSETS, DEFAULT_CHARSET } from 'core/data/Charsets';
|
||||||
import { wcwidth } from './CharWidth';
|
import { wcwidth } from './common/CharWidth';
|
||||||
import { EscapeSequenceParser } from 'core/parser/EscapeSequenceParser';
|
import { EscapeSequenceParser } from 'core/parser/EscapeSequenceParser';
|
||||||
import { IDisposable } from 'xterm';
|
import { IDisposable } from 'xterm';
|
||||||
import { Disposable } from 'common/Lifecycle';
|
import { Disposable } from 'common/Lifecycle';
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import { ILinkifierEvent, ILinkMatcher, LinkMatcherHandler, ILinkMatcherOptions, ILinkifier, ITerminal, IBufferStringIteratorResult, IMouseZoneManager } from './Types';
|
import { ILinkifierEvent, ILinkMatcher, LinkMatcherHandler, ILinkMatcherOptions, ILinkifier, ITerminal, IBufferStringIteratorResult, IMouseZoneManager } from './Types';
|
||||||
import { MouseZone } from './MouseZoneManager';
|
import { MouseZone } from './MouseZoneManager';
|
||||||
import { getStringCellWidth } from './CharWidth';
|
import { getStringCellWidth } from 'common/CharWidth';
|
||||||
import { EventEmitter2, IEvent } from 'common/EventEmitter2';
|
import { EventEmitter2, IEvent } from 'common/EventEmitter2';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,80 +3,8 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { TestTerminal } from './TestUtils.test';
|
|
||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
import { getStringCellWidth, wcwidth } from './CharWidth';
|
import { wcwidth } from 'common/CharWidth';
|
||||||
import { IBuffer } from './Types';
|
|
||||||
import { CellData, CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX } from 'core/buffer/BufferLine';
|
|
||||||
|
|
||||||
|
|
||||||
describe('getStringCellWidth', function(): void {
|
|
||||||
let terminal: TestTerminal;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
terminal = new TestTerminal({rows: 5, cols: 30});
|
|
||||||
});
|
|
||||||
|
|
||||||
function sumWidths(buffer: IBuffer, start: number, end: number, sentinel: string): number {
|
|
||||||
let result = 0;
|
|
||||||
for (let i = start; i < end; ++i) {
|
|
||||||
const line = buffer.lines.get(i);
|
|
||||||
for (let j = 0; j < line.length; ++j) { // TODO: change to trimBorder with multiline
|
|
||||||
const ch = line.loadCell(j, new CellData()).getAsCharData();
|
|
||||||
result += ch[CHAR_DATA_WIDTH_INDEX];
|
|
||||||
// return on sentinel
|
|
||||||
if (ch[CHAR_DATA_CHAR_INDEX] === sentinel) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
it('ASCII chars', function(): void {
|
|
||||||
const input = 'This is just ASCII text.#';
|
|
||||||
terminal.writeSync(input);
|
|
||||||
const s = terminal.buffer.iterator(true).next().content;
|
|
||||||
assert.equal(input, s);
|
|
||||||
assert.equal(getStringCellWidth(s), sumWidths(terminal.buffer, 0, 1, '#'));
|
|
||||||
});
|
|
||||||
it('combining chars', function(): void {
|
|
||||||
const input = 'e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301#';
|
|
||||||
terminal.writeSync(input);
|
|
||||||
const s = terminal.buffer.iterator(true).next().content;
|
|
||||||
assert.equal(input, s);
|
|
||||||
assert.equal(getStringCellWidth(s), sumWidths(terminal.buffer, 0, 1, '#'));
|
|
||||||
});
|
|
||||||
it('surrogate chars', function(): void {
|
|
||||||
const input = '𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞#';
|
|
||||||
terminal.writeSync(input);
|
|
||||||
const s = terminal.buffer.iterator(true).next().content;
|
|
||||||
assert.equal(input, s);
|
|
||||||
assert.equal(getStringCellWidth(s), sumWidths(terminal.buffer, 0, 1, '#'));
|
|
||||||
});
|
|
||||||
it('surrogate combining chars', function(): void {
|
|
||||||
const input = '𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301#';
|
|
||||||
terminal.writeSync(input);
|
|
||||||
const s = terminal.buffer.iterator(true).next().content;
|
|
||||||
assert.equal(input, s);
|
|
||||||
assert.equal(getStringCellWidth(s), sumWidths(terminal.buffer, 0, 1, '#'));
|
|
||||||
});
|
|
||||||
it('fullwidth chars', function(): void {
|
|
||||||
const input = '1234567890#';
|
|
||||||
terminal.writeSync(input);
|
|
||||||
const s = terminal.buffer.iterator(true).next().content;
|
|
||||||
assert.equal(input, s);
|
|
||||||
assert.equal(getStringCellWidth(s), sumWidths(terminal.buffer, 0, 1, '#'));
|
|
||||||
});
|
|
||||||
it('fullwidth chars offset 1', function(): void {
|
|
||||||
const input = 'a1234567890#';
|
|
||||||
terminal.writeSync(input);
|
|
||||||
const s = terminal.buffer.iterator(true).next().content;
|
|
||||||
assert.equal(input, s);
|
|
||||||
assert.equal(getStringCellWidth(s), sumWidths(terminal.buffer, 0, 1, '#'));
|
|
||||||
});
|
|
||||||
// TODO: multiline tests once #1685 is resolved
|
|
||||||
});
|
|
||||||
|
|
||||||
it('wcwidth should match all values from the old implementation', function(): void {
|
it('wcwidth should match all values from the old implementation', function(): void {
|
||||||
// old implementation
|
// old implementation
|
||||||
@@ -197,7 +125,7 @@ it('wcwidth should match all values from the old implementation', function(): vo
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
const control = opts.control | 0;
|
const control = opts.control | 0;
|
||||||
let table: number[] | Uint32Array = null;
|
let table: number[] | Uint32Array | undefined;
|
||||||
function initTable(): number[] | Uint32Array {
|
function initTable(): number[] | Uint32Array {
|
||||||
// lookup table for BMP
|
// lookup table for BMP
|
||||||
const CODEPOINTS = 65536; // BMP holds 65536 codepoints
|
const CODEPOINTS = 65536; // BMP holds 65536 codepoints
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
import * as puppeteer from 'puppeteer';
|
||||||
|
import { assert } from 'chai';
|
||||||
|
import { ITerminalOptions } from 'xterm';
|
||||||
|
|
||||||
|
const APP = 'http://127.0.0.1:3000/test';
|
||||||
|
|
||||||
|
let browser: puppeteer.Browser;
|
||||||
|
let page: puppeteer.Page;
|
||||||
|
const width = 800;
|
||||||
|
const height = 600;
|
||||||
|
|
||||||
|
describe('CharWidth Integration Tests', function(): void {
|
||||||
|
this.timeout(20000);
|
||||||
|
|
||||||
|
before(async function(): Promise<any> {
|
||||||
|
browser = await puppeteer.launch({
|
||||||
|
headless: process.argv.indexOf('--headless') !== -1,
|
||||||
|
slowMo: 80,
|
||||||
|
args: [`--window-size=${width},${height}`]
|
||||||
|
});
|
||||||
|
page = (await browser.pages())[0];
|
||||||
|
await page.setViewport({ width, height });
|
||||||
|
await page.goto(APP);
|
||||||
|
await openTerminal({ rows: 5, cols: 30 });
|
||||||
|
});
|
||||||
|
|
||||||
|
after(() => {
|
||||||
|
browser.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getStringCellWidth', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await page.evaluate(`window.term.reset()`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ASCII chars', async function(): Promise<void> {
|
||||||
|
const input = 'This is just ASCII text.#';
|
||||||
|
await page.evaluate(`window.term.write('${input}')`);
|
||||||
|
assert.equal(25, await sumWidths(0, 1, '#'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('combining chars', async function(): Promise<void> {
|
||||||
|
const input = 'e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301#';
|
||||||
|
await page.evaluate(`window.term.write('${input}')`);
|
||||||
|
assert.equal(10, await sumWidths(0, 1, '#'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('surrogate chars', async function(): Promise<void> {
|
||||||
|
const input = '𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞#';
|
||||||
|
await page.evaluate(`window.term.write('${input}')`);
|
||||||
|
assert.equal(28, await sumWidths(0, 1, '#'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('surrogate combining chars', async function(): Promise<void> {
|
||||||
|
const input = '𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301#';
|
||||||
|
await page.evaluate(`window.term.write('${input}')`);
|
||||||
|
assert.equal(12, await sumWidths(0, 1, '#'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fullwidth chars', async function(): Promise<void> {
|
||||||
|
const input = '1234567890#';
|
||||||
|
await page.evaluate(`window.term.write('${input}')`);
|
||||||
|
assert.equal(21, await sumWidths(0, 1, '#'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fullwidth chars offset 1', async function(): Promise<void> {
|
||||||
|
const input = 'a1234567890#';
|
||||||
|
await page.evaluate(`window.term.write('${input}')`);
|
||||||
|
assert.equal(22, await sumWidths(0, 1, '#'));
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: multiline tests once #1685 is resolved
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
async function openTerminal(options: ITerminalOptions = {}): Promise<void> {
|
||||||
|
await page.evaluate(`window.term = new Terminal(${JSON.stringify(options)})`);
|
||||||
|
await page.evaluate(`window.term.open(document.querySelector('#terminal-container'))`);
|
||||||
|
if (options.rendererType === 'dom') {
|
||||||
|
await page.waitForSelector('.xterm-rows');
|
||||||
|
} else {
|
||||||
|
await page.waitForSelector('.xterm-text-layer');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sumWidths(start: number, end: number, sentinel: string): Promise<number> {
|
||||||
|
await page.evaluate(`
|
||||||
|
(function() {
|
||||||
|
window.result = 0;
|
||||||
|
const buffer = window.term.buffer;
|
||||||
|
for (let i = ${start}; i < ${end}; i++) {
|
||||||
|
const line = buffer.getLine(i);
|
||||||
|
let j = 0;
|
||||||
|
while (true) {
|
||||||
|
const cell = line.getCell(j++);
|
||||||
|
if (!cell) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
window.result += cell.width;
|
||||||
|
if (cell.char === '${sentinel}') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
`);
|
||||||
|
return await page.evaluate(`window.result`);
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import * as puppeteer from 'puppeteer';
|
import * as puppeteer from 'puppeteer';
|
||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
import { ITerminalOptions } from './Types';
|
import { ITerminalOptions } from 'xterm';
|
||||||
|
|
||||||
const APP = 'http://127.0.0.1:3000/test';
|
const APP = 'http://127.0.0.1:3000/test';
|
||||||
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import * as puppeteer from 'puppeteer';
|
import * as puppeteer from 'puppeteer';
|
||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
import { ITerminalOptions } from '../Types';
|
import { ITerminalOptions } from 'xterm';
|
||||||
|
|
||||||
const APP = 'http://127.0.0.1:3000/test';
|
const APP = 'http://127.0.0.1:3000/test';
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"lib": [
|
||||||
|
"dom",
|
||||||
|
"es6",
|
||||||
|
],
|
||||||
|
"rootDir": ".",
|
||||||
|
"outDir": "../out/test",
|
||||||
|
"types": [
|
||||||
|
"../node_modules/@types/mocha"
|
||||||
|
],
|
||||||
|
"sourceMap": true,
|
||||||
|
"removeComments": true,
|
||||||
|
"pretty": true,
|
||||||
|
"strict": true
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"./**/*",
|
||||||
|
"../typings/xterm.d.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
"include": [],
|
"include": [],
|
||||||
"references": [
|
"references": [
|
||||||
{ "path": "./src" },
|
{ "path": "./src" },
|
||||||
|
{ "path": "./test" },
|
||||||
{ "path": "./addons/xterm-addon-attach/src" },
|
{ "path": "./addons/xterm-addon-attach/src" },
|
||||||
{ "path": "./addons/xterm-addon-fit/src" },
|
{ "path": "./addons/xterm-addon-fit/src" },
|
||||||
{ "path": "./addons/xterm-addon-search/src" },
|
{ "path": "./addons/xterm-addon-search/src" },
|
||||||
|
|||||||
Reference in New Issue
Block a user