💄 Move specs for Editor::reloadGrammar to editor-spec

This commit is contained in:
Nathan Sobo 2014-03-05 13:01:32 -07:00
parent 5d9cd662fc
commit 23a40fe051
2 changed files with 14 additions and 43 deletions

View File

@ -2733,6 +2733,17 @@ describe "Editor", ->
editor.setIndentationForBufferRow(0, 2)
expect(editor.getText()).toBe(" 1\n 2")
describe ".reloadGrammar()", ->
beforeEach ->
waitsForPromise ->
atom.packages.activatePackage('language-coffee-script')
it "updates the grammar based on grammar overrides", ->
expect(editor.getGrammar().name).toBe 'JavaScript'
atom.syntax.setGrammarOverrideForPath(editor.getPath(), 'source.coffee')
editor.reloadGrammar()
expect(editor.getGrammar().name).toBe 'CoffeeScript'
describe "when the editor's grammar has an injection selector", ->
beforeEach ->

View File

@ -2430,51 +2430,11 @@ describe "EditorView", ->
editorView.underlayer.trigger event
expect(editor.getSelection().getScreenRange()).toEqual [[0,0], [12,2]]
# TODO: Move to editor-spec
describe ".reloadGrammar()", ->
[filePath] = []
beforeEach ->
tmpdir = fs.absolute(temp.dir)
filePath = path.join(tmpdir, "grammar-change.txt")
fs.writeFileSync(filePath, "var i;")
afterEach ->
fs.removeSync(filePath) if fs.existsSync(filePath)
it "updates all the rendered lines when the grammar changes", ->
editor = atom.project.openSync(filePath)
editorView.edit(editor)
expect(editor.getGrammar().name).toBe 'Plain Text'
atom.syntax.setGrammarOverrideForPath(filePath, 'source.js')
editor.reloadGrammar()
expect(editor.getGrammar().name).toBe 'JavaScript'
tokenizedBuffer = editorView.editor.displayBuffer.tokenizedBuffer
line0 = tokenizedBuffer.lineForScreenRow(0)
expect(line0.tokens.length).toBe 3
expect(line0.tokens[0]).toEqual(value: 'var', scopes: ['source.js', 'storage.modifier.js'])
it "doesn't update the rendered lines when the grammar doesn't change", ->
expect(editor.getGrammar().name).toBe 'JavaScript'
spyOn(editorView, 'updateDisplay').andCallThrough()
editor.reloadGrammar()
expect(editor.reloadGrammar()).toBeFalsy()
expect(editorView.updateDisplay).not.toHaveBeenCalled()
expect(editor.getGrammar().name).toBe 'JavaScript'
it "emits an editor:grammar-changed event when updated", ->
editor = atom.project.openSync(filePath)
editorView.edit(editor)
describe "when the editor's grammar is changed", ->
it "emits an editor:grammar-changed event", ->
eventHandler = jasmine.createSpy('eventHandler')
editorView.on('editor:grammar-changed', eventHandler)
editor.reloadGrammar()
expect(eventHandler).not.toHaveBeenCalled()
atom.syntax.setGrammarOverrideForPath(filePath, 'source.js')
editor.reloadGrammar()
editor.setGrammar(atom.syntax.selectGrammar('.coffee'))
expect(eventHandler).toHaveBeenCalled()
describe ".replaceSelectedText()", ->