Fixes https://github.com/xtermjs/xterm.js/issues/5896 TypeScript path mappings for common/*, browser/*, and headless/* were not rewritten in emitted JavaScript, which forced webpack resolve aliases and NODE_PATH workarounds so runtime could resolve modules. That added build complexity and broke tooling such as ESLint import/no-cycle. Changes: - Convert ~750 imports across src/, addons/, and test/ to relative paths - Remove common/browser/headless paths and src catch-all mappings from tsconfigs (keep @xterm/addon-* demo and addon typings paths) - Remove webpack resolve.alias for common, browser, headless, and vs - Drop NODE_PATH from unit tests, benchmarks, and VS Code launch config - Fix addon-image IIPImageStorage to import ./Types after removing catch-all * Verified: npm run build, esbuild, package, package-headless Co-authored-by: Cursor <cursoragent@cursor.com>
123 lines
3.2 KiB
TypeScript
123 lines
3.2 KiB
TypeScript
/**
|
|
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
|
|
* @license MIT
|
|
*/
|
|
|
|
import { assert } from 'chai';
|
|
import { SortedList } from './SortedList';
|
|
import { MockLogService } from './TestUtils.test';
|
|
|
|
const deepStrictEqual = assert.deepStrictEqual;
|
|
|
|
describe('SortedList', () => {
|
|
let list: SortedList<number>;
|
|
function assertList(expected: number[]): void {
|
|
deepStrictEqual(Array.from(list.values()), expected);
|
|
}
|
|
|
|
beforeEach(() => {
|
|
list = new SortedList<number>(e => e, new MockLogService());
|
|
});
|
|
|
|
describe('insert', () => {
|
|
it('should maintain sorted values', () => {
|
|
list.insert(10);
|
|
assertList([10]);
|
|
list.insert(8);
|
|
assertList([8, 10]);
|
|
list.insert(15);
|
|
assertList([8, 10, 15]);
|
|
list.insert(2);
|
|
assertList([2, 8, 10, 15]);
|
|
list.insert(1);
|
|
assertList([1, 2, 8, 10, 15]);
|
|
list.insert(6);
|
|
assertList([1, 2, 6, 8, 10, 15]);
|
|
});
|
|
it('should allow duplicates of the same key', () => {
|
|
list.insert(5);
|
|
assertList([5]);
|
|
list.insert(5);
|
|
assertList([5, 5]);
|
|
list.insert(8);
|
|
assertList([5, 5, 8]);
|
|
list.insert(5);
|
|
assertList([5, 5, 5, 8]);
|
|
list.insert(8);
|
|
assertList([5, 5, 5, 8, 8]);
|
|
list.insert(6);
|
|
assertList([5, 5, 5, 6, 8, 8]);
|
|
});
|
|
});
|
|
it('delete', () => {
|
|
list.insert(1);
|
|
list.insert(2);
|
|
list.insert(4);
|
|
list.insert(3);
|
|
list.insert(5);
|
|
assertList([1, 2, 3, 4, 5]);
|
|
list.delete(1);
|
|
assertList([2, 3, 4, 5]);
|
|
list.delete(3);
|
|
assertList([2, 4, 5]);
|
|
list.delete(4);
|
|
assertList([2, 5]);
|
|
list.delete(5);
|
|
assertList([2]);
|
|
list.delete(2);
|
|
assertList([]);
|
|
});
|
|
it('getKeyIterator', () => {
|
|
list.insert(5);
|
|
list.insert(5);
|
|
list.insert(8);
|
|
list.insert(5);
|
|
list.insert(8);
|
|
list.insert(6);
|
|
assertList([5, 5, 5, 6, 8, 8]);
|
|
deepStrictEqual(Array.from(list.getKeyIterator(1)), []);
|
|
deepStrictEqual(Array.from(list.getKeyIterator(5)), [5, 5, 5]);
|
|
deepStrictEqual(Array.from(list.getKeyIterator(6)), [6]);
|
|
deepStrictEqual(Array.from(list.getKeyIterator(8)), [8, 8]);
|
|
deepStrictEqual(Array.from(list.getKeyIterator(9)), []);
|
|
});
|
|
it('clear', () => {
|
|
list.insert(1);
|
|
list.insert(2);
|
|
list.insert(4);
|
|
list.insert(3);
|
|
list.insert(5);
|
|
list.clear();
|
|
assertList([]);
|
|
});
|
|
it('custom key', () => {
|
|
const customList = new SortedList<{ key: number }>(e => e.key, new MockLogService());
|
|
customList.insert({ key: 5 });
|
|
customList.insert({ key: 2 });
|
|
customList.insert({ key: 10 });
|
|
customList.insert({ key: 5 });
|
|
customList.insert({ key: 6 });
|
|
deepStrictEqual(Array.from(customList.values()), [
|
|
{ key: 2 },
|
|
{ key: 5 },
|
|
{ key: 5 },
|
|
{ key: 6 },
|
|
{ key: 10 }
|
|
]);
|
|
});
|
|
describe('values', () => {
|
|
it('should iterate correctly when list items change during iteration', () => {
|
|
list.insert(1);
|
|
list.insert(2);
|
|
list.insert(3);
|
|
list.insert(4);
|
|
const visited: number[] = [];
|
|
for (const item of list.values()) {
|
|
visited.push(item);
|
|
list.delete(item);
|
|
}
|
|
deepStrictEqual(visited, [1, 2, 3, 4]);
|
|
});
|
|
});
|
|
});
|