diff --git a/src/common/services/DecorationService.test.ts b/src/common/services/DecorationService.test.ts index 71299d330e..7a617a276e 100644 --- a/src/common/services/DecorationService.test.ts +++ b/src/common/services/DecorationService.test.ts @@ -12,27 +12,18 @@ import { MockLogService, MockBufferService, MockOptionsService } from '../TestUt import { Buffer } from '../buffer/Buffer'; import { DEFAULT_ATTR_DATA } from '../buffer/BufferLine'; -function createFakeMarker(line: number): IMarker { - return Object.freeze(new class extends Disposable { - public readonly id = 1; - public readonly line = line; - public readonly isDisposed = false; - public readonly onDispose = new Emitter().event; - }()); -} - -function createDecorationService(): DecorationService { - const bufferService = new MockBufferService(80, 24, new MockOptionsService()); - return new DecorationService(new MockLogService(), bufferService); -} - -const fakeMarker: IMarker = createFakeMarker(1); - describe('DecorationService', () => { + let bufferService: MockBufferService; + let service: DecorationService; + + beforeEach(() => { + bufferService = new MockBufferService(80, 24, new MockOptionsService()); + service = new DecorationService(new MockLogService(), bufferService); + }); + it('should set isDisposed to true after dispose', () => { - const service = createDecorationService(); const decoration = service.registerDecoration({ - marker: fakeMarker + marker: bufferService.buffer.addMarker(1) }); assert.ok(decoration); assert.isFalse(decoration!.isDisposed); @@ -42,22 +33,19 @@ describe('DecorationService', () => { describe('forEachDecorationAtCell', () => { it('should find decoration at its marker line', () => { - const service = createDecorationService(); const decoration = service.registerDecoration({ - marker: createFakeMarker(5), + marker: bufferService.buffer.addMarker(5), width: 10 }); assert.ok(decoration); - const found: typeof decoration[] = []; service.forEachDecorationAtCell(0, 5, undefined, d => found.push(d)); assert.strictEqual(found.length, 1); }); it('should find decoration with height > 1 on subsequent lines', () => { - const service = createDecorationService(); const decoration = service.registerDecoration({ - marker: createFakeMarker(5), + marker: bufferService.buffer.addMarker(5), width: 10, height: 3 }); @@ -81,15 +69,13 @@ describe('DecorationService', () => { }); it('should not find decoration outside its x range', () => { - const service = createDecorationService(); const decoration = service.registerDecoration({ - marker: createFakeMarker(5), + marker: bufferService.buffer.addMarker(5), x: 5, width: 3, height: 2 }); assert.ok(decoration); - const foundAtX4: typeof decoration[] = []; service.forEachDecorationAtCell(4, 5, undefined, d => foundAtX4.push(d)); assert.strictEqual(foundAtX4.length, 0); @@ -108,18 +94,16 @@ describe('DecorationService', () => { }); it('should find multi-line decoration when single-line decorations exist on other lines', () => { - const bufferService = new MockBufferService(80, 24, new MockOptionsService()); - const serviceWithBuffer = new DecorationService(new MockLogService(), bufferService); const buffer = bufferService.buffer; (buffer as Buffer).fillViewportRows(); - for (let i = 0; i < 100; i++) { - serviceWithBuffer.registerDecoration({ + for (let i = 0; i < buffer.lines.length; i++) { + service.registerDecoration({ marker: buffer.addMarker(i), width: 5 }); } - const multiLine = serviceWithBuffer.registerDecoration({ + const multiLine = service.registerDecoration({ marker: buffer.addMarker(10), width: 10, height: 3 @@ -127,16 +111,15 @@ describe('DecorationService', () => { assert.ok(multiLine); const found: typeof multiLine[] = []; - serviceWithBuffer.forEachDecorationAtCell(0, 11, undefined, d => found.push(d)); + service.forEachDecorationAtCell(0, 11, undefined, d => found.push(d)); assert.include(found, multiLine); }); }); describe('getDecorationsAtCell', () => { it('should find decoration with height > 1 on subsequent lines', () => { - const service = createDecorationService(); const decoration = service.registerDecoration({ - marker: createFakeMarker(5), + marker: bufferService.buffer.addMarker(5), width: 10, height: 3 }); @@ -158,8 +141,6 @@ describe('DecorationService', () => { describe('line index maintenance', () => { it('should keep lookups correct after buffer trim', () => { - const bufferService = new MockBufferService(80, 5, new MockOptionsService({ scrollback: 0 })); - const service = new DecorationService(new MockLogService(), bufferService); const buffer = bufferService.buffer; (buffer as Buffer).fillViewportRows(); @@ -175,8 +156,6 @@ describe('DecorationService', () => { }); it('should remove decoration from line index when marker is trimmed off buffer', () => { - const bufferService = new MockBufferService(80, 5, new MockOptionsService({ scrollback: 0 })); - const service = new DecorationService(new MockLogService(), bufferService); const buffer = bufferService.buffer; (buffer as Buffer).fillViewportRows(); @@ -194,8 +173,6 @@ describe('DecorationService', () => { }); it('should keep multi-line decoration indexed after line insert', async () => { - const bufferService = new MockBufferService(80, 10, new MockOptionsService({ scrollback: 100 })); - const service = new DecorationService(new MockLogService(), bufferService); const buffer = bufferService.buffer; (buffer as Buffer).fillViewportRows();