|
|
|
@ -45,17 +45,48 @@ function runTests(languageId:string, tests:ITestItem[][]): void {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function runTest(languageId:string, test:ITestItem[]): void {
|
|
|
|
|
|
|
|
|
|
interface LineToken {
|
|
|
|
|
startOffset: number;
|
|
|
|
|
endOffset: number;
|
|
|
|
|
type: string;
|
|
|
|
|
modeId: string;
|
|
|
|
|
hasPrev: boolean;
|
|
|
|
|
hasNext: boolean;
|
|
|
|
|
|
|
|
|
|
prev(): LineToken;
|
|
|
|
|
next(): LineToken;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface LineTokens {
|
|
|
|
|
// modeTransitions:ModeTransition[];
|
|
|
|
|
|
|
|
|
|
getTokenCount(): number;
|
|
|
|
|
getTokenStartOffset(tokenIndex:number): number;
|
|
|
|
|
getTokenType(tokenIndex:number): string;
|
|
|
|
|
getTokenEndOffset(tokenIndex:number): number;
|
|
|
|
|
equals(other:LineTokens): boolean;
|
|
|
|
|
findTokenIndexAtOffset(offset:number): number;
|
|
|
|
|
findTokenAtOffset(offset:number): LineToken;
|
|
|
|
|
firstToken(): LineToken;
|
|
|
|
|
lastToken(): LineToken;
|
|
|
|
|
// inflate(): ViewLineToken[];
|
|
|
|
|
// sliceAndInflate(startOffset:number, endOffset:number, deltaStartIndex:number): ViewLineToken[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let text = test.map(t => t.line).join('\n');
|
|
|
|
|
let model = _monaco.editor.createModel(text, languageId);
|
|
|
|
|
|
|
|
|
|
for (let lineNumber = 1, lineCount = model.getLineCount(); lineNumber <= lineCount; lineNumber++) {
|
|
|
|
|
let actual: IRelaxedToken[] = [];
|
|
|
|
|
let lineTokens = (<any>model).getLineTokens(lineNumber);
|
|
|
|
|
for (let j = 0; j < lineTokens.getTokenCount(); j++) {
|
|
|
|
|
let lineTokens:LineTokens = (<any>model).getLineTokens(lineNumber);
|
|
|
|
|
let token = lineTokens.firstToken();
|
|
|
|
|
while (token) {
|
|
|
|
|
actual.push({
|
|
|
|
|
startIndex: lineTokens.getTokenStartIndex(j),
|
|
|
|
|
type: lineTokens.getTokenType(j)
|
|
|
|
|
startIndex: token.startOffset,
|
|
|
|
|
type: token.type
|
|
|
|
|
});
|
|
|
|
|
token = token.next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let expected = test[lineNumber - 1].tokens;
|
|
|
|
|