Add tests for ColorZoneStore
This commit is contained in:
@@ -0,0 +1,88 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { assert } from 'chai';
|
||||||
|
import { ColorZoneStore } from 'browser/Decorations/ColorZoneStore';
|
||||||
|
|
||||||
|
const optionsRedFull = {
|
||||||
|
overviewRulerOptions: {
|
||||||
|
color: 'red',
|
||||||
|
position: 'full' as 'full'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('ColorZoneStore', () => {
|
||||||
|
let store: ColorZoneStore;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
store = new ColorZoneStore();
|
||||||
|
store.setPadding({
|
||||||
|
full: 1,
|
||||||
|
left: 1,
|
||||||
|
center: 1,
|
||||||
|
right: 1
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should merge adjacent zones', () => {
|
||||||
|
store.addDecoration({
|
||||||
|
marker: { line: 0 },
|
||||||
|
options: optionsRedFull
|
||||||
|
});
|
||||||
|
store.addDecoration({
|
||||||
|
marker: { line: 1 },
|
||||||
|
options: optionsRedFull
|
||||||
|
});
|
||||||
|
assert.deepStrictEqual(store.zones, [
|
||||||
|
{
|
||||||
|
color: 'red',
|
||||||
|
position: 'full',
|
||||||
|
startBufferLine: 0,
|
||||||
|
endBufferLine: 1
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not merge non-adjacent zones', () => {
|
||||||
|
store.addDecoration({
|
||||||
|
marker: { line: 0 },
|
||||||
|
options: optionsRedFull
|
||||||
|
});
|
||||||
|
store.addDecoration({
|
||||||
|
marker: { line: 2 },
|
||||||
|
options: optionsRedFull
|
||||||
|
});
|
||||||
|
assert.deepStrictEqual(store.zones, [
|
||||||
|
{
|
||||||
|
color: 'red',
|
||||||
|
position: 'full',
|
||||||
|
startBufferLine: 0,
|
||||||
|
endBufferLine: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'red',
|
||||||
|
position: 'full',
|
||||||
|
startBufferLine: 2,
|
||||||
|
endBufferLine: 2
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reuse zone objects', () => {
|
||||||
|
const obj = {
|
||||||
|
marker: { line: 0 },
|
||||||
|
options: optionsRedFull
|
||||||
|
};
|
||||||
|
store.addDecoration(obj);
|
||||||
|
const zone = store.zones[0];
|
||||||
|
store.clear();
|
||||||
|
store.addDecoration({
|
||||||
|
marker: { line: 1 },
|
||||||
|
options: optionsRedFull
|
||||||
|
});
|
||||||
|
// The object reference should be the same
|
||||||
|
assert.equal(zone, store.zones[0]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -24,6 +24,11 @@ export interface IColorZone {
|
|||||||
endBufferLine: number;
|
endBufferLine: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IMinimalDecorationForColorZone {
|
||||||
|
marker: Pick<IInternalDecoration['marker'], 'line'>;
|
||||||
|
options: Pick<IInternalDecoration['options'], 'overviewRulerOptions'>;
|
||||||
|
}
|
||||||
|
|
||||||
export class ColorZoneStore implements IColorZoneStore {
|
export class ColorZoneStore implements IColorZoneStore {
|
||||||
private _zones: IColorZone[] = [];
|
private _zones: IColorZone[] = [];
|
||||||
|
|
||||||
@@ -51,7 +56,7 @@ export class ColorZoneStore implements IColorZoneStore {
|
|||||||
this._zonePoolIndex = 0;
|
this._zonePoolIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public addDecoration(decoration: IInternalDecoration): void {
|
public addDecoration(decoration: IMinimalDecorationForColorZone): void {
|
||||||
if (!decoration.options.overviewRulerOptions) {
|
if (!decoration.options.overviewRulerOptions) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -62,7 +67,6 @@ export class ColorZoneStore implements IColorZoneStore {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this._lineAdjacentToZone(z, decoration.marker.line, decoration.options.overviewRulerOptions.position)) {
|
if (this._lineAdjacentToZone(z, decoration.marker.line, decoration.options.overviewRulerOptions.position)) {
|
||||||
console.log('add line to zone');
|
|
||||||
this._addLineToZone(z, decoration.marker.line);
|
this._addLineToZone(z, decoration.marker.line);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user