2013-01-09 04:15:24 +04:00
|
|
|
fs = require 'fs'
|
|
|
|
|
2012-12-23 23:50:58 +04:00
|
|
|
describe "the `syntax` global", ->
|
2013-01-01 04:11:11 +04:00
|
|
|
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"
|
|
|
|
|
2013-01-09 04:15:24 +04:00
|
|
|
it "doesn't read the file when the file contents are specified", ->
|
|
|
|
filePath = require.resolve("fixtures/shebang")
|
|
|
|
filePathContents = fs.read(filePath)
|
|
|
|
spyOn(fs, 'read').andCallThrough()
|
|
|
|
expect(syntax.grammarForFilePath(filePath, filePathContents).name).toBe "Ruby"
|
|
|
|
expect(fs.read).not.toHaveBeenCalled()
|
|
|
|
|
2013-01-01 04:11:11 +04:00
|
|
|
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", ->
|
2013-02-01 03:14:47 +04:00
|
|
|
expect(syntax.grammarForFilePath("this-is-not-a-real-file").name).toBe "Plain Text"
|
2013-01-01 04:11:11 +04:00
|
|
|
|
2012-12-23 23:50:58 +04:00
|
|
|
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)
|
|
|
|
syntax.addProperties(".source .string.quoted.double", foo: bar: baz: 22)
|
|
|
|
syntax.addProperties(".source", foo: bar: baz: 11)
|
|
|
|
syntax.addProperties(foo: bar: baz: 1)
|
|
|
|
|
|
|
|
expect(syntax.getProperty([".source.coffee", ".string.quoted.double.coffee"], "foo.bar.baz")).toBe 42
|
|
|
|
expect(syntax.getProperty([".source.js", ".string.quoted.double.js"], "foo.bar.baz")).toBe 22
|
|
|
|
expect(syntax.getProperty([".source.js", ".variable.assignment.js"], "foo.bar.baz")).toBe 11
|
|
|
|
expect(syntax.getProperty([".text"], "foo.bar.baz")).toBe 1
|
2012-12-24 00:19:20 +04:00
|
|
|
|
|
|
|
it "favors the most recently added properties in the event of a specificity tie", ->
|
|
|
|
syntax.addProperties(".source.coffee .string.quoted.single", foo: bar: baz: 42)
|
|
|
|
syntax.addProperties(".source.coffee .string.quoted.double", foo: bar: baz: 22)
|
|
|
|
|
|
|
|
expect(syntax.getProperty([".source.coffee", ".string.quoted.single"], "foo.bar.baz")).toBe 42
|
|
|
|
expect(syntax.getProperty([".source.coffee", ".string.quoted.single.double"], "foo.bar.baz")).toBe 22
|