Only load TextMate packages as needed in specs

Also: when a TextMate package is deactivated, remove its grammars
This commit is contained in:
Corey Johnson & Nathan Sobo
2013-03-25 17:31:01 -06:00
committed by Nathan Sobo
parent 8340a084d3
commit 8437f3ff7f
14 changed files with 70 additions and 20 deletions

View File

@@ -6,6 +6,7 @@ describe "DisplayBuffer", ->
[editSession, displayBuffer, buffer, changeHandler, tabLength] = []
beforeEach ->
tabLength = 2
atom.activatePackage('javascript.tmbundle', sync: true)
editSession = project.buildEditSession('sample.js', { tabLength })
{ buffer, displayBuffer } = editSession
changeHandler = jasmine.createSpy 'changeHandler'

View File

@@ -9,6 +9,7 @@ describe "EditSession", ->
buffer.setText(buffer.getText().replace(/[ ]{2}/g, "\t"))
beforeEach ->
atom.activatePackage('javascript.tmbundle', sync: true)
editSession = project.buildEditSession('sample.js', autoIndent: false)
buffer = editSession.buffer
lineLengths = buffer.getLines().map (line) -> line.length
@@ -2048,13 +2049,14 @@ describe "EditSession", ->
describe "when the 'grammars-loaded' event is triggered on the syntax global", ->
it "reloads the edit session's grammar and re-tokenizes the buffer if it changes", ->
editSession.destroy()
grammarToReturn = syntax.grammarByPath('a.txt')
jsGrammar = syntax.selectGrammar('a.js')
grammarToReturn = syntax.nullGrammar
spyOn(syntax, 'selectGrammar').andCallFake -> grammarToReturn
editSession = project.buildEditSession('sample.js', autoIndent: false)
expect(editSession.lineForScreenRow(0).tokens.length).toBe 1
grammarToReturn = syntax.grammarByPath('a.js')
grammarToReturn = jsGrammar
syntax.trigger 'grammars-loaded'
expect(editSession.lineForScreenRow(0).tokens.length).toBeGreaterThan 1

View File

@@ -12,6 +12,8 @@ describe "Editor", ->
[buffer, editor, editSession, cachedLineHeight, cachedCharWidth] = []
beforeEach ->
atom.activatePackage('text.tmbundle', sync: true)
atom.activatePackage('javascript.tmbundle', sync: true)
editSession = project.buildEditSession('sample.js')
buffer = editSession.buffer
editor = new Editor(editSession)

View File

@@ -6,6 +6,8 @@ describe "GrammarView", ->
[editor, textGrammar, jsGrammar] = []
beforeEach ->
atom.activatePackage('text.tmbundle', sync: true)
atom.activatePackage('javascript.tmbundle', sync: true)
window.rootView = new RootView
rootView.open('sample.js')
editor = rootView.getActiveView()

View File

@@ -10,6 +10,7 @@ describe "LanguageMode", ->
describe "common behavior", ->
beforeEach ->
atom.activatePackage('javascript.tmbundle', sync: true)
editSession = project.buildEditSession('sample.js', autoIndent: false)
{ buffer, languageMode } = editSession
@@ -21,6 +22,7 @@ describe "LanguageMode", ->
describe "javascript", ->
beforeEach ->
atom.activatePackage('javascript.tmbundle', sync: true)
editSession = project.buildEditSession('sample.js', autoIndent: false)
{ buffer, languageMode } = editSession
@@ -60,9 +62,9 @@ describe "LanguageMode", ->
expect(languageMode.suggestedIndentForBufferRow(2)).toBe 2
expect(languageMode.suggestedIndentForBufferRow(9)).toBe 1
describe "coffeescript", ->
beforeEach ->
atom.activatePackage('coffee-script-tmbundle', sync: true)
editSession = project.buildEditSession('coffee.coffee', autoIndent: false)
{ buffer, languageMode } = editSession
@@ -98,6 +100,7 @@ describe "LanguageMode", ->
describe "css", ->
beforeEach ->
atom.activatePackage('css.tmbundle', sync: true)
editSession = project.buildEditSession('css.css', autoIndent: false)
{ buffer, languageMode } = editSession

View File

@@ -1,6 +1,12 @@
fs = require 'fs-utils'
describe "the `syntax` global", ->
beforeEach ->
atom.activatePackage('text.tmbundle', sync: true)
atom.activatePackage('javascript.tmbundle', sync: true)
atom.activatePackage('coffee-script-tmbundle', sync: true)
atom.activatePackage('ruby.tmbundle', sync: true)
describe "serialization", ->
it "remembers grammar overrides by path", ->
path = '/foo/bar/file.js'
@@ -12,6 +18,8 @@ describe "the `syntax` global", ->
describe ".selectGrammar(filePath)", ->
it "can use the filePath to load the correct grammar based on the grammar's filetype", ->
atom.activatePackage('git.tmbundle', sync: true)
expect(syntax.selectGrammar("file.js").name).toBe "JavaScript" # based on extension (.js)
expect(syntax.selectGrammar("/tmp/.git/config").name).toBe "Git Config" # based on end of the path (.git/config)
expect(syntax.selectGrammar("Rakefile").name).toBe "Ruby" # based on the file's basename (Rakefile)
@@ -23,6 +31,8 @@ describe "the `syntax` global", ->
expect(syntax.selectGrammar(filePath).name).toBe "Ruby"
it "uses the number of newlines in the first line regex to determine the number of lines to test against", ->
atom.activatePackage('property-list.tmbundle', sync: true)
fileContent = "first-line\n<html>"
expect(syntax.selectGrammar("dummy.coffee", fileContent).name).toBe "CoffeeScript"
@@ -47,6 +57,12 @@ describe "the `syntax` global", ->
syntax.clearGrammarOverrideForPath(path)
expect(syntax.selectGrammar(path).name).not.toBe 'Ruby'
describe ".removeGrammar(grammar)", ->
it "removes the grammar, so it won't be returned by selectGrammar", ->
grammar = syntax.selectGrammar('foo.js')
syntax.removeGrammar(grammar)
expect(syntax.selectGrammar('foo.js').name).not.toBe grammar.name
describe ".getProperty(scopeDescriptor)", ->
it "returns the property with the most specific scope selector", ->
syntax.addProperties(".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42)

View File

@@ -8,6 +8,10 @@ describe "TextMateGrammar", ->
grammar = null
beforeEach ->
atom.activatePackage('text.tmbundle', sync: true)
atom.activatePackage('javascript.tmbundle', sync: true)
atom.activatePackage('coffee-script-tmbundle', sync: true)
atom.activatePackage('ruby.tmbundle', sync: true)
grammar = syntax.selectGrammar("hello.coffee")
describe ".tokenizeLine(line, ruleStack)", ->
@@ -192,6 +196,9 @@ describe "TextMateGrammar", ->
describe "when the pattern includes rules from another grammar", ->
it "parses tokens inside the begin/end patterns based on the included grammar's rules", ->
atom.activatePackage('html.tmbundle', sync: true)
atom.activatePackage('ruby-on-rails-tmbundle', sync: true)
grammar = syntax.grammarsByFileType["html.erb"]
{tokens} = grammar.tokenizeLine("<div class='name'><%= User.find(2).full_name %></div>")
@@ -248,6 +255,9 @@ describe "TextMateGrammar", ->
{tokens, ruleStack} = grammar.tokenizeLine(" // second line comment with a single leading space", ruleStack)
describe "when inside a C block", ->
beforeEach ->
atom.activatePackage('c.tmbundle', sync: true)
it "correctly parses a method. (regression)", ->
grammar = syntax.selectGrammar("hello.c")
{tokens, ruleStack} = grammar.tokenizeLine("if(1){m()}")
@@ -271,6 +281,7 @@ describe "TextMateGrammar", ->
describe "when a grammar has a pattern that has back references in the match value", ->
it "does not special handle the back references and instead allows oniguruma to resolve them", ->
atom.activatePackage('sass.tmbundle', sync: true)
grammar = syntax.selectGrammar("style.scss")
{tokens} = grammar.tokenizeLine("@mixin x() { -moz-selector: whatever; }")
expect(tokens[9]).toEqual value: "-moz-selector", scopes: ["source.css.scss", "meta.property-list.scss", "meta.property-name.scss"]

View File

@@ -8,6 +8,7 @@ describe "TokenizedBuffer", ->
[editSession, tokenizedBuffer, buffer, changeHandler] = []
beforeEach ->
atom.activatePackage('javascript.tmbundle', sync: true)
# enable async tokenization
TokenizedBuffer.prototype.chunkSize = 5
jasmine.unspy(TokenizedBuffer.prototype, 'tokenizeInBackground')
@@ -298,6 +299,7 @@ describe "TokenizedBuffer", ->
describe "when the buffer contains hard-tabs", ->
beforeEach ->
atom.activatePackage('coffee-script-tmbundle', sync: true)
tabLength = 2
editSession = project.buildEditSession('sample-with-tabs.coffee', { tabLength })
buffer = editSession.buffer
@@ -328,6 +330,7 @@ describe "TokenizedBuffer", ->
describe "when a Git commit message file is tokenized", ->
beforeEach ->
atom.activatePackage('git.tmbundle', sync: true)
editSession = project.buildEditSession('COMMIT_EDITMSG', autoIndent: false)
buffer = editSession.buffer
tokenizedBuffer = editSession.displayBuffer.tokenizedBuffer
@@ -355,6 +358,7 @@ describe "TokenizedBuffer", ->
describe "when a C++ source file is tokenized", ->
beforeEach ->
atom.activatePackage('c.tmbundle', sync: true)
editSession = project.buildEditSession('includes.cc', autoIndent: false)
buffer = editSession.buffer
tokenizedBuffer = editSession.displayBuffer.tokenizedBuffer
@@ -403,6 +407,8 @@ describe "TokenizedBuffer", ->
describe "when an Objective-C source file is tokenized", ->
beforeEach ->
atom.activatePackage('c.tmbundle', sync: true)
atom.activatePackage('objective-c.tmbundle', sync: true)
editSession = project.buildEditSession('function.mm', autoIndent: false)
buffer = editSession.buffer
tokenizedBuffer = editSession.displayBuffer.tokenizedBuffer