diff --git a/spec/app/syntax-spec.coffee b/spec/app/syntax-spec.coffee index c3117fb46..60b65b0e9 100644 --- a/spec/app/syntax-spec.coffee +++ b/spec/app/syntax-spec.coffee @@ -1,4 +1,22 @@ describe "the `syntax` global", -> + describe ".grammarForFilePath(filePath)", -> + it "uses the filePath's extension to load the correct grammar", -> + expect(syntax.grammarForFilePath("file.js").name).toBe "JavaScript" + + it "uses the filePath's base name if there is no extension", -> + expect(syntax.grammarForFilePath("Rakefile").name).toBe "Ruby" + + it "uses the filePath's shebang line if the grammar cannot be determined by the extension or basename", -> + filePath = require.resolve("fixtures/shebang") + expect(syntax.grammarForFilePath(filePath).name).toBe "Ruby" + + it "uses the grammar's fileType as a suffix of the full filePath if the grammar cannot be determined by shebang line", -> + expect(syntax.grammarForFilePath("/tmp/.git/config").name).toBe "Git Config" + + it "uses plain text if no grammar can be found", -> + filePath = require.resolve("this-is-not-a-real-file") + expect(syntax.grammarForFilePath(filePath).name).toBe "Plain Text" + 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) diff --git a/spec/app/text-mate-bundle-spec.coffee b/spec/app/text-mate-bundle-spec.coffee index c67bc50cc..f2d89e882 100644 --- a/spec/app/text-mate-bundle-spec.coffee +++ b/spec/app/text-mate-bundle-spec.coffee @@ -2,14 +2,6 @@ fs = require('fs') TextMateBundle = require 'text-mate-bundle' describe "TextMateBundle", -> - describe ".getPreferencesByScopeSelector()", -> - it "logs warning, but does not raise errors if a preference can't be parsed", -> - bundlePath = fs.join(require.resolve('fixtures'), "test.tmbundle") - spyOn(console, 'warn') - bundle = new TextMateBundle(bundlePath) - expect(-> bundle.getPreferencesByScopeSelector()).not.toThrow() - expect(console.warn).toHaveBeenCalled() - describe ".constructor(bundlePath)", -> it "logs warning, but does not raise errors if a grammar can't be parsed", -> bundlePath = fs.join(require.resolve('fixtures'), "test.tmbundle") @@ -17,20 +9,3 @@ describe "TextMateBundle", -> expect(-> new TextMateBundle(bundlePath)).not.toThrow() expect(console.warn).toHaveBeenCalled() - describe ".grammarForFilePath(filePath)", -> - it "uses the filePath's extension to load the correct grammar", -> - expect(TextMateBundle.grammarForFilePath("file.js").name).toBe "JavaScript" - - it "uses the filePath's base name if there is no extension", -> - expect(TextMateBundle.grammarForFilePath("Rakefile").name).toBe "Ruby" - - it "uses the filePath's shebang line if the grammar cannot be determined by the extension or basename", -> - filePath = require.resolve("fixtures/shebang") - expect(TextMateBundle.grammarForFilePath(filePath).name).toBe "Ruby" - - it "uses the grammar's fileType as a suffix of the full filePath if the grammar cannot be determined by shebang line", -> - expect(TextMateBundle.grammarForFilePath("/tmp/.git/config").name).toBe "Git Config" - - it "uses plain text if no grammar can be found", -> - filePath = require.resolve("this-is-not-a-real-file") - expect(TextMateBundle.grammarForFilePath(filePath).name).toBe "Plain Text" diff --git a/spec/app/text-mate-grammar-spec.coffee b/spec/app/text-mate-grammar-spec.coffee index 96c860306..97e1ead87 100644 --- a/spec/app/text-mate-grammar-spec.coffee +++ b/spec/app/text-mate-grammar-spec.coffee @@ -1,5 +1,4 @@ TextMateGrammar = require 'text-mate-grammar' -TextMateBundle = require 'text-mate-bundle' plist = require 'plist' fs = require 'fs' _ = require 'underscore' @@ -8,7 +7,7 @@ describe "TextMateGrammar", -> grammar = null beforeEach -> - grammar = TextMateBundle.grammarForFilePath("hello.coffee") + grammar = syntax.grammarForFilePath("hello.coffee") describe ".tokenizeLine(line, ruleStack)", -> describe "when the entire line matches a single pattern with no capture groups", -> @@ -31,7 +30,7 @@ describe "TextMateGrammar", -> describe "when the line doesn't match any patterns", -> it "returns the entire line as a single simple token with the grammar's scope", -> - textGrammar = TextMateBundle.grammarForFilePath('foo.txt') + textGrammar = syntax.grammarForFilePath('foo.txt') {tokens} = textGrammar.tokenizeLine("abc def") expect(tokens.length).toBe 1 @@ -108,20 +107,20 @@ describe "TextMateGrammar", -> describe "when the line matches no patterns", -> it "does not infinitely loop", -> - grammar = TextMateBundle.grammarForFilePath("sample.txt") + grammar = syntax.grammarForFilePath("sample.txt") {tokens} = grammar.tokenizeLine('hoo') expect(tokens.length).toBe 1 expect(tokens[0]).toEqual value: 'hoo', scopes: ["text.plain", "meta.paragraph.text"] describe "when the line matches a pattern with a 'contentName'", -> it "creates tokens using the content of contentName as the token name", -> - grammar = TextMateBundle.grammarForFilePath("sample.txt") + grammar = syntax.grammarForFilePath("sample.txt") {tokens} = grammar.tokenizeLine('ok, cool') expect(tokens[0]).toEqual value: 'ok, cool', scopes: ["text.plain", "meta.paragraph.text"] describe "when the line matches a pattern with no `name` or `contentName`", -> it "creates tokens without adding a new scope", -> - grammar = TextMateBundle.grammarsByFileType["rb"] + grammar = syntax.grammarsByFileType["rb"] {tokens} = grammar.tokenizeLine('%w|oh \\look|') expect(tokens.length).toBe 5 expect(tokens[0]).toEqual value: '%w|', scopes: ["source.ruby", "string.quoted.other.literal.lower.ruby", "punctuation.definition.string.begin.ruby"] @@ -166,7 +165,7 @@ describe "TextMateGrammar", -> describe "when the end pattern contains a back reference", -> it "constructs the end rule based on its back-references to captures in the begin rule", -> - grammar = TextMateBundle.grammarsByFileType["rb"] + grammar = syntax.grammarsByFileType["rb"] {tokens} = grammar.tokenizeLine('%w|oh|,') expect(tokens.length).toBe 4 expect(tokens[0]).toEqual value: '%w|', scopes: ["source.ruby", "string.quoted.other.literal.lower.ruby", "punctuation.definition.string.begin.ruby"] @@ -175,7 +174,7 @@ describe "TextMateGrammar", -> expect(tokens[3]).toEqual value: ',', scopes: ["source.ruby", "punctuation.separator.object.ruby"] it "allows the rule containing that end pattern to be pushed to the stack multiple times", -> - grammar = TextMateBundle.grammarsByFileType["rb"] + grammar = syntax.grammarsByFileType["rb"] {tokens} = grammar.tokenizeLine('%Q+matz had some #{%Q-crazy ideas-} for ruby syntax+ # damn.') expect(tokens[0]).toEqual value: '%Q+', scopes: ["source.ruby","string.quoted.other.literal.upper.ruby","punctuation.definition.string.begin.ruby"] expect(tokens[1]).toEqual value: 'matz had some ', scopes: ["source.ruby","string.quoted.other.literal.upper.ruby"] @@ -192,7 +191,7 @@ 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", -> - grammar = TextMateBundle.grammarsByFileType["html.erb"] + grammar = syntax.grammarsByFileType["html.erb"] {tokens} = grammar.tokenizeLine("