Skip to content

Commit 2d9b21f

Browse files
committed
Move extendedAttributes function to TestUtils so it can be used by InputHandler.test.ts.
This is a followup to pull request #5748. It removes the remaining test uses of internal _extendedAttrs.
1 parent 1432e20 commit 2d9b21f

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/common/InputHandler.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { CellData } from 'common/buffer/CellData';
1111
import { Attributes, BgFlags, UnderlineStyle } from 'common/buffer/Constants';
1212
import { AttributeData, ExtendedAttrs } from 'common/buffer/AttributeData';
1313
import { Params } from 'common/parser/Params';
14-
import { MockCoreService, MockBufferService, MockOptionsService, MockLogService, MockMouseStateService, MockCharsetService, MockUnicodeService, MockOscLinkService } from 'common/TestUtils.test';
14+
import { MockCoreService, MockBufferService, MockOptionsService, MockLogService, MockMouseStateService, MockCharsetService, MockUnicodeService, MockOscLinkService, extendedAttributes } from 'common/TestUtils.test';
1515
import { IBufferService, ICoreService, type IOscLinkService } from 'common/services/Services';
1616
import { DEFAULT_OPTIONS } from 'common/services/OptionsService';
1717
import { clone } from 'common/Clone';
@@ -2002,15 +2002,15 @@ describe('InputHandler', () => {
20022002

20032003
// eAttrs in buffer pos 0 and 1 should be the same object
20042004
assert.equal(
2005-
(bufferService.buffer!.lines.get(0)! as any)._extendedAttrs[0],
2006-
(bufferService.buffer!.lines.get(0)! as any)._extendedAttrs[1]
2005+
extendedAttributes(bufferService.buffer!.lines.get(0)!, 0),
2006+
extendedAttributes(bufferService.buffer!.lines.get(0)!, 1)
20072007
);
20082008
// should not have written eAttr for pos 2 in the buffer
2009-
assert.equal((bufferService.buffer!.lines.get(0)! as any)._extendedAttrs[2], undefined);
2009+
assert.equal(extendedAttributes(bufferService.buffer!.lines.get(0)!, 2), undefined);
20102010
// eAttrs in buffer pos 1 and pos 3 must be different objs
20112011
assert.notEqual(
2012-
(bufferService.buffer!.lines.get(0)! as any)._extendedAttrs[1],
2013-
(bufferService.buffer!.lines.get(0)! as any)._extendedAttrs[3]
2012+
extendedAttributes(bufferService.buffer!.lines.get(0)!, 1),
2013+
extendedAttributes(bufferService.buffer!.lines.get(0)!, 3)
20142014
);
20152015
});
20162016
});

src/common/TestUtils.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { IBufferService, ICoreService, ILogService, IOptionsService, ITerminalOp
77
import { UnicodeService } from 'common/services/UnicodeService';
88
import { clone } from 'common/Clone';
99
import { DEFAULT_OPTIONS } from 'common/services/OptionsService';
10-
import { IBufferSet, IBuffer } from 'common/buffer/Types';
10+
import { IBufferSet, IBuffer, IExtendedAttrs } from 'common/buffer/Types';
1111
import { BufferSet } from 'common/buffer/BufferSet';
12-
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEventType, ICharset, IModes, IAttributeData, IOscLinkData, IDisposable } from 'common/Types';
12+
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEventType, ICharset, IModes, IAttributeData, IOscLinkData, IDisposable, IBufferLine } from 'common/Types';
1313
import { UnicodeV6 } from 'common/input/UnicodeV6';
1414
import { IDecorationOptions, IDecoration } from '@xterm/xterm';
1515
import { Emitter, type IEvent } from 'common/Event';
@@ -20,6 +20,12 @@ export function createCellData(attr: number, char: string, width: number): CellD
2020
return CellData.fromCharData([attr, char, width, char.length === 0 ? 0 : char.charCodeAt(0)]);
2121
}
2222

23+
export function extendedAttributes(line: IBufferLine, index: number): IExtendedAttrs | undefined {
24+
const cell = new CellData();
25+
line.loadCell(index, cell);
26+
return cell.hasExtendedAttrs() !== 0 ? cell.extended : undefined;
27+
}
28+
2329
export const NULL_CELL_DATA = Object.freeze(createCellData(DEFAULT_ATTR, NULL_CELL_CHAR, NULL_CELL_WIDTH));
2430

2531
export class MockBufferService implements IBufferService {

src/common/buffer/BufferLine.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import { NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, DEFAULT_ATTR, Content, UnderlineStyle, BgFlags, Attributes, FgFlags } from 'common/buffer/Constants';
66
import { BufferLine } from 'common/buffer//BufferLine';
77
import { CellData } from 'common/buffer/CellData';
8-
import { CharData, IBufferLine, IExtendedAttrs } from '../Types';
8+
import { CharData, IBufferLine } from '../Types';
99
import { assert } from 'chai';
1010
import { AttributeData } from 'common/buffer/AttributeData';
11-
import { createCellData, NULL_CELL_DATA } from 'common/TestUtils.test';
11+
import { createCellData, NULL_CELL_DATA, extendedAttributes } from 'common/TestUtils.test';
1212

1313

1414
class TestBufferLine extends BufferLine {
@@ -25,12 +25,6 @@ class TestBufferLine extends BufferLine {
2525
}
2626
}
2727

28-
function extendedAttributes(line: IBufferLine, index: number): IExtendedAttrs | undefined {
29-
const cell = new CellData();
30-
line.loadCell(index, cell);
31-
return cell.hasExtendedAttrs() !== 0 ? cell.extended : undefined;
32-
}
33-
3428
describe('AttributeData', () => {
3529
describe('extended attributes', () => {
3630
it('hasExtendedAttrs', () => {

0 commit comments

Comments
 (0)