|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | +'use strict'; |
| 6 | + |
| 7 | +import * as assert from 'assert'; |
| 8 | +import {Model} from 'vs/editor/common/model/model'; |
| 9 | +import {ViewLineToken} from 'vs/editor/common/core/viewLineToken'; |
| 10 | +import {ITokenizationSupport} from 'vs/editor/common/modes'; |
| 11 | +import {MockMode} from 'vs/editor/test/common/mocks/mockMode'; |
| 12 | + |
| 13 | +suite('TextModelWithTokens', () => { |
| 14 | + |
| 15 | + function assertViewLineTokens(model:Model, lineNumber:number, forceTokenization:boolean, expected:ViewLineToken[]): void { |
| 16 | + let actual = model.getLineTokens(lineNumber, !forceTokenization).inflate(); |
| 17 | + assert.deepEqual(actual, expected); |
| 18 | + } |
| 19 | + |
| 20 | + test('Microsoft/monaco-editor#122: Unhandled Exception: TypeError: Unable to get property \'replace\' of undefined or null reference', () => { |
| 21 | + let _tokenId = 0; |
| 22 | + class IndicisiveMode extends MockMode { |
| 23 | + public tokenizationSupport:ITokenizationSupport; |
| 24 | + |
| 25 | + constructor() { |
| 26 | + super(); |
| 27 | + this.tokenizationSupport = { |
| 28 | + getInitialState: () => { |
| 29 | + return null; |
| 30 | + }, |
| 31 | + tokenize: (line, state, offsetDelta, stopAtOffset) => { |
| 32 | + let myId = ++_tokenId; |
| 33 | + return { |
| 34 | + tokens: [{ startIndex: 0, type: 'custom.'+myId }], |
| 35 | + actualStopOffset: line.length, |
| 36 | + endState: null, |
| 37 | + modeTransitions: [], |
| 38 | + retokenize: null |
| 39 | + }; |
| 40 | + } |
| 41 | + }; |
| 42 | + } |
| 43 | + } |
| 44 | + let model = Model.createFromString('A model with\ntwo lines'); |
| 45 | + |
| 46 | + assertViewLineTokens(model, 1, true, [new ViewLineToken(0, '')]); |
| 47 | + assertViewLineTokens(model, 2, true, [new ViewLineToken(0, '')]); |
| 48 | + |
| 49 | + model.setMode(new IndicisiveMode()); |
| 50 | + |
| 51 | + assertViewLineTokens(model, 1, true, [new ViewLineToken(0, 'custom.1')]); |
| 52 | + assertViewLineTokens(model, 2, true, [new ViewLineToken(0, 'custom.2')]); |
| 53 | + |
| 54 | + model.setMode(new IndicisiveMode()); |
| 55 | + |
| 56 | + assertViewLineTokens(model, 1, false, [new ViewLineToken(0, '')]); |
| 57 | + assertViewLineTokens(model, 2, false, [new ViewLineToken(0, '')]); |
| 58 | + |
| 59 | + model.dispose(); |
| 60 | + }); |
| 61 | + |
| 62 | +}); |
0 commit comments