Files
xterm.js/src/common/services/UnicodeService.test.ts
T
Daniel ImmsandCursor 56a7195487 Add oxlint import/no-cycle and break existing src/common cycles
Enable oxlint's import/no-cycle rule (import plugin) so circular module
dependencies are caught in CI, similar to eslint-plugin-import/no-cycle
and biome no-import-cycles discussed in the issue.

Relocate shared types and dependencies to remove cycles under src/common:

- Types.ts: host IInsertEvent, IDeleteEvent, IParams, UnderlineStyle,
  IBuffer, and IBufferSet; drop imports from CircularList, buffer/Types,
  parser/Types, and Services
- CoreTerminal.ts: define and export ICoreTerminal
- ServiceRegistry.ts: define IServiceIdentifier (break Services registry loop)
- UnicodeService: stop constructing UnicodeV6; CoreTerminal registers the
  default v6 provider after service creation
- buffer/Types.ts and parser/Types.ts: re-export moved types for callers

Fixes https://github.com/xtermjs/xterm.js/issues/5897

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-31 10:08:04 -07:00

56 lines
1.8 KiB
TypeScript

/**
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/
import { assert } from 'chai';
import { UnicodeV6 } from '../input/UnicodeV6';
import { UnicodeService } from './UnicodeService';
import { IUnicodeVersionProvider } from './Services';
class DummyProvider implements IUnicodeVersionProvider {
public version = '123';
public wcwidth(n: number): 0 | 1 | 2 {
return 2;
}
public charProperties(codepoint: number): number {
return UnicodeService.createPropertyValue(0, this.wcwidth(codepoint));
}
}
describe('unicode provider', () => {
let us: UnicodeService;
beforeEach(() => {
us = new UnicodeService();
us.register(new UnicodeV6());
});
it('default to V6', () => {
assert.equal(us.activeVersion, '6');
assert.deepEqual(us.versions, ['6']);
assert.doesNotThrow(() => { us.activeVersion = '6'; }, `unknown Unicode version "6"`);
assert.equal(us.getStringCellWidth('hello'), 5);
});
it('activate should throw for unknown version', () => {
assert.throws(() => { us.activeVersion = '55'; }, 'unknown Unicode version "55"');
});
it('should notify about version change', () => {
const notes: string[] = [];
us.onChange(version => notes.push(version));
const dummyProvider = new DummyProvider();
us.register(dummyProvider);
us.activeVersion = dummyProvider.version;
assert.deepEqual(notes, [dummyProvider.version]);
});
it('correctly changes provider impl', () => {
assert.equal(us.getStringCellWidth('hello'), 5);
const dummyProvider = new DummyProvider();
us.register(dummyProvider);
us.activeVersion = dummyProvider.version;
assert.equal(us.getStringCellWidth('hello'), 2 * 5);
});
it('wcwidth V6 emoji test', () => {
const widthV6 = us.getStringCellWidth('🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣');
assert.equal(widthV6, 10);
});
});