Make TokenizedBuffer behave consistently when tokenizeInBackground is mocked

This commit is contained in:
Max Brunsfeld
2017-11-22 15:30:28 -08:00
parent 4810d13094
commit afc4245971

View File

@@ -7,6 +7,7 @@ fs = require 'fs-plus'
Grim = require 'grim'
pathwatcher = require 'pathwatcher'
FindParentDir = require 'find-parent-dir'
{CompositeDisposable} = require 'event-kit'
TextEditor = require '../src/text-editor'
TextEditorElement = require '../src/text-editor-element'
@@ -102,6 +103,18 @@ beforeEach ->
TokenizedBuffer.prototype.chunkSize = Infinity
spyOn(TokenizedBuffer.prototype, "tokenizeInBackground").andCallFake -> @tokenizeNextChunk()
# Without this spy, TextEditor.onDidTokenize callbacks would not be called
# after the buffer's language mode changed, because by the time the editor
# called its new language mode's onDidTokenize method, the language mode
# would already be fully tokenized.
spyOn(TextEditor.prototype, "onDidTokenize").andCallFake (callback) ->
new CompositeDisposable(
@emitter.on("did-tokenize", callback),
@onDidChangeGrammar =>
if @buffer.getLanguageMode().tokenizeInBackground.originalValue
callback()
)
clipboardContent = 'initial clipboard content'
spyOn(clipboard, 'writeText').andCallFake (text) -> clipboardContent = text
spyOn(clipboard, 'readText').andCallFake -> clipboardContent