Improve tests
This commit is contained in:
parent
a9de23d321
commit
3a87cea73d
|
@ -192,15 +192,11 @@ export interface ITokensStore {
|
|||
getBeginState(lineIndex: number): IState | null;
|
||||
|
||||
applyEdits(range: Range, eolCount: number, firstLineLength: number): void;
|
||||
|
||||
_getAllStates(linesLength: number): (IState | null)[];
|
||||
_getAllInvalid(linesLength: number): number[];
|
||||
}
|
||||
|
||||
export class TokensStore implements ITokensStore {
|
||||
private _tokens: ModelLineTokens[];
|
||||
private _invalidLineStartIndex: number;
|
||||
private _lastState: IState | null;
|
||||
|
||||
constructor(initialState: IState | null) {
|
||||
this._reset(initialState);
|
||||
|
@ -209,7 +205,6 @@ export class TokensStore implements ITokensStore {
|
|||
private _reset(initialState: IState | null): void {
|
||||
this._tokens = [];
|
||||
this._invalidLineStartIndex = 0;
|
||||
this._lastState = null;
|
||||
|
||||
if (initialState) {
|
||||
this._setBeginState(0, initialState);
|
||||
|
@ -310,7 +305,6 @@ export class TokensStore implements ITokensStore {
|
|||
|
||||
// Check if this was the last line
|
||||
if (lineIndex === linesLength - 1) {
|
||||
this._lastState = r.endState;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -423,25 +417,6 @@ export class TokensStore implements ITokensStore {
|
|||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
_getAllStates(linesLength: number): (IState | null)[] {
|
||||
const r: (IState | null)[] = [];
|
||||
for (let i = 0; i < linesLength; i++) {
|
||||
r[i] = this.getBeginState(i);
|
||||
}
|
||||
r[linesLength] = this._lastState;
|
||||
return r;
|
||||
}
|
||||
|
||||
_getAllInvalid(linesLength: number): number[] {
|
||||
const r: number[] = [];
|
||||
for (let i = 0; i < linesLength; i++) {
|
||||
if (!this._isValid(i)) {
|
||||
r.push(i);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
export interface IModelLinesTokens {
|
||||
|
|
|
@ -170,30 +170,23 @@ suite('Editor Model - Model Modes 2', () => {
|
|||
}
|
||||
}
|
||||
|
||||
let calledFor: string[] = [];
|
||||
|
||||
function checkAndClear(arr: string[]): void {
|
||||
assert.deepEqual(calledFor, arr);
|
||||
calledFor = [];
|
||||
}
|
||||
|
||||
const tokenizationSupport: modes.ITokenizationSupport = {
|
||||
getInitialState: () => new ModelState2(''),
|
||||
tokenize: undefined!,
|
||||
tokenize2: (line: string, state: modes.IState): TokenizationResult2 => {
|
||||
calledFor.push(line);
|
||||
(<ModelState2>state).prevLineContent = line;
|
||||
return new TokenizationResult2(null!, state);
|
||||
}
|
||||
};
|
||||
|
||||
function invalidEqual(model: TextModel, expected: number[]): void {
|
||||
assert.deepEqual(model._tokens._getAllInvalid(model.getLineCount()), expected);
|
||||
}
|
||||
|
||||
function stateEqual(state: modes.IState, content: string): void {
|
||||
assert.equal((<ModelState2>state).prevLineContent, content);
|
||||
}
|
||||
|
||||
function statesEqual(model: TextModel, expectedStates: string[]): void {
|
||||
const actualStates = model._tokens._getAllStates(model.getLineCount());
|
||||
for (let i = 0, len = expectedStates.length; i < len; i++) {
|
||||
stateEqual(actualStates[i]!, expectedStates[i]);
|
||||
}
|
||||
}
|
||||
|
||||
let thisModel: TextModel;
|
||||
let languageRegistration: IDisposable;
|
||||
|
||||
|
@ -216,64 +209,54 @@ suite('Editor Model - Model Modes 2', () => {
|
|||
|
||||
test('getTokensForInvalidLines one text insert', () => {
|
||||
thisModel.forceTokenization(5);
|
||||
statesEqual(thisModel, ['', 'Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
checkAndClear(['Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
thisModel.applyEdits([EditOperation.insert(new Position(1, 6), '-')]);
|
||||
invalidEqual(thisModel, [0]);
|
||||
statesEqual(thisModel, ['', 'Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
thisModel.forceTokenization(5);
|
||||
statesEqual(thisModel, ['', 'Line1-', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
checkAndClear(['Line1-', 'Line2']);
|
||||
});
|
||||
|
||||
test('getTokensForInvalidLines two text insert', () => {
|
||||
thisModel.forceTokenization(5);
|
||||
statesEqual(thisModel, ['', 'Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
checkAndClear(['Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
thisModel.applyEdits([
|
||||
EditOperation.insert(new Position(1, 6), '-'),
|
||||
EditOperation.insert(new Position(3, 6), '-')
|
||||
]);
|
||||
|
||||
invalidEqual(thisModel, [0, 2]);
|
||||
thisModel.forceTokenization(5);
|
||||
statesEqual(thisModel, ['', 'Line1-', 'Line2', 'Line3-', 'Line4', 'Line5']);
|
||||
checkAndClear(['Line1-', 'Line2', 'Line3-', 'Line4']);
|
||||
});
|
||||
|
||||
test('getTokensForInvalidLines one multi-line text insert, one small text insert', () => {
|
||||
thisModel.forceTokenization(5);
|
||||
statesEqual(thisModel, ['', 'Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
checkAndClear(['Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
thisModel.applyEdits([EditOperation.insert(new Position(1, 6), '\nNew line\nAnother new line')]);
|
||||
invalidEqual(thisModel, [0, 1, 2]);
|
||||
thisModel.applyEdits([EditOperation.insert(new Position(5, 6), '-')]);
|
||||
invalidEqual(thisModel, [0, 1, 2, 4]);
|
||||
thisModel.forceTokenization(7);
|
||||
statesEqual(thisModel, ['', 'Line1', 'New line', 'Another new line', 'Line2', 'Line3-', 'Line4', 'Line5']);
|
||||
checkAndClear(['Line1', 'New line', 'Another new line', 'Line2', 'Line3-', 'Line4']);
|
||||
});
|
||||
|
||||
test('getTokensForInvalidLines one delete text', () => {
|
||||
thisModel.forceTokenization(5);
|
||||
statesEqual(thisModel, ['', 'Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
checkAndClear(['Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
thisModel.applyEdits([EditOperation.delete(new Range(1, 1, 1, 5))]);
|
||||
invalidEqual(thisModel, [0]);
|
||||
thisModel.forceTokenization(5);
|
||||
statesEqual(thisModel, ['', '1', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
checkAndClear(['1', 'Line2']);
|
||||
});
|
||||
|
||||
test('getTokensForInvalidLines one line delete text', () => {
|
||||
thisModel.forceTokenization(5);
|
||||
statesEqual(thisModel, ['', 'Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
checkAndClear(['Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
thisModel.applyEdits([EditOperation.delete(new Range(1, 1, 2, 1))]);
|
||||
invalidEqual(thisModel, [0]);
|
||||
statesEqual(thisModel, ['', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
thisModel.forceTokenization(4);
|
||||
statesEqual(thisModel, ['', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
checkAndClear(['Line2']);
|
||||
});
|
||||
|
||||
test('getTokensForInvalidLines multiple lines delete text', () => {
|
||||
thisModel.forceTokenization(5);
|
||||
statesEqual(thisModel, ['', 'Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
checkAndClear(['Line1', 'Line2', 'Line3', 'Line4', 'Line5']);
|
||||
thisModel.applyEdits([EditOperation.delete(new Range(1, 1, 3, 3))]);
|
||||
invalidEqual(thisModel, [0]);
|
||||
statesEqual(thisModel, ['', 'Line3', 'Line4', 'Line5']);
|
||||
thisModel.forceTokenization(3);
|
||||
statesEqual(thisModel, ['', 'ne3', 'Line4', 'Line5']);
|
||||
checkAndClear(['ne3', 'Line4']);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue