From 23a40fe05108f8aff18ebeb1f7db3d8b5c07fc26 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 5 Mar 2014 13:01:32 -0700 Subject: [PATCH] :lipstick: Move specs for Editor::reloadGrammar to editor-spec --- spec/editor-spec.coffee | 11 +++++++++ spec/editor-view-spec.coffee | 46 +++--------------------------------- 2 files changed, 14 insertions(+), 43 deletions(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index d8ec6cbf1..5bdb7858a 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -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 -> diff --git a/spec/editor-view-spec.coffee b/spec/editor-view-spec.coffee index 60a014e47..45b474156 100644 --- a/spec/editor-view-spec.coffee +++ b/spec/editor-view-spec.coffee @@ -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()", ->