Move common primitives to src/common/primitives/
Phase 1 of #5963: reorganize building blocks (buffer, parser, input, data, and shared utilities) under common/primitives/. Runtime code (services, public API, CoreTerminal, InputHandler) stays in place. Update import paths across browser, headless, addons, and tests. Add TypeScript path mappings so common/* aliases resolve primitives first, then the common root. Co-authored-by: Daniel Imms <Tyriar@users.noreply.github.com>
This commit is contained in:
co-authored by
Daniel Imms
parent
3cdbc77386
commit
701c0affd5
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* 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]);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user