diff --git a/spec/atom-spec.coffee b/spec/atom-spec.coffee index a0b8ff458..82795d3b9 100644 --- a/spec/atom-spec.coffee +++ b/spec/atom-spec.coffee @@ -240,24 +240,24 @@ describe "the `atom` global", -> describe "grammar loading", -> it "loads the package's grammars", -> atom.activatePackage('package-with-grammars') - expect(syntax.selectGrammar('a.alot').name).toBe 'Alot' - expect(syntax.selectGrammar('a.alittle').name).toBe 'Alittle' + expect(atom.syntax.selectGrammar('a.alot').name).toBe 'Alot' + expect(atom.syntax.selectGrammar('a.alittle').name).toBe 'Alittle' describe "scoped-property loading", -> it "loads the scoped properties", -> atom.activatePackage("package-with-scoped-properties") - expect(syntax.getProperty ['.source.omg'], 'editor.increaseIndentPattern').toBe '^a' + expect(atom.syntax.getProperty ['.source.omg'], 'editor.increaseIndentPattern').toBe '^a' describe "textmate packages", -> it "loads the package's grammars", -> - expect(syntax.selectGrammar("file.rb").name).toBe "Null Grammar" + expect(atom.syntax.selectGrammar("file.rb").name).toBe "Null Grammar" atom.activatePackage('language-ruby', sync: true) - expect(syntax.selectGrammar("file.rb").name).toBe "Ruby" + expect(atom.syntax.selectGrammar("file.rb").name).toBe "Ruby" it "translates the package's scoped properties to Atom terms", -> - expect(syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBeUndefined() + expect(atom.syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBeUndefined() atom.activatePackage('language-ruby', sync: true) - expect(syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBe '# ' + expect(atom.syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBe '# ' describe "when the package has no grammars but does have preferences", -> it "loads the package's preferences as scoped properties", -> @@ -267,9 +267,9 @@ describe "the `atom` global", -> atom.activatePackage('package-with-preferences-tmbundle') waitsFor -> - syntax.addProperties.callCount > 0 + atom.syntax.addProperties.callCount > 0 runs -> - expect(syntax.getProperty(['.source.pref'], 'editor.increaseIndentPattern')).toBe '^abc$' + expect(atom.syntax.getProperty(['.source.pref'], 'editor.increaseIndentPattern')).toBe '^abc$' describe ".deactivatePackage(id)", -> describe "atom packages", -> @@ -311,8 +311,8 @@ describe "the `atom` global", -> it "removes the package's grammars", -> atom.activatePackage('package-with-grammars') atom.deactivatePackage('package-with-grammars') - expect(syntax.selectGrammar('a.alot').name).toBe 'Null Grammar' - expect(syntax.selectGrammar('a.alittle').name).toBe 'Null Grammar' + expect(atom.syntax.selectGrammar('a.alot').name).toBe 'Null Grammar' + expect(atom.syntax.selectGrammar('a.alittle').name).toBe 'Null Grammar' it "removes the package's keymaps", -> atom.activatePackage('package-with-keymaps') @@ -332,22 +332,22 @@ describe "the `atom` global", -> it "removes the package's scoped-properties", -> atom.activatePackage("package-with-scoped-properties") - expect(syntax.getProperty ['.source.omg'], 'editor.increaseIndentPattern').toBe '^a' + expect(atom.syntax.getProperty ['.source.omg'], 'editor.increaseIndentPattern').toBe '^a' atom.deactivatePackage("package-with-scoped-properties") - expect(syntax.getProperty ['.source.omg'], 'editor.increaseIndentPattern').toBeUndefined() + expect(atom.syntax.getProperty ['.source.omg'], 'editor.increaseIndentPattern').toBeUndefined() describe "textmate packages", -> it "removes the package's grammars", -> - expect(syntax.selectGrammar("file.rb").name).toBe "Null Grammar" + expect(atom.syntax.selectGrammar("file.rb").name).toBe "Null Grammar" atom.activatePackage('language-ruby', sync: true) - expect(syntax.selectGrammar("file.rb").name).toBe "Ruby" + expect(atom.syntax.selectGrammar("file.rb").name).toBe "Ruby" atom.deactivatePackage('language-ruby') - expect(syntax.selectGrammar("file.rb").name).toBe "Null Grammar" + expect(atom.syntax.selectGrammar("file.rb").name).toBe "Null Grammar" it "removes the package's scoped properties", -> atom.activatePackage('language-ruby', sync: true) atom.deactivatePackage('language-ruby') - expect(syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBeUndefined() + expect(atom.syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBeUndefined() describe ".activate()", -> packageActivator = null diff --git a/spec/edit-session-spec.coffee b/spec/edit-session-spec.coffee index afb990ddf..03ebbf406 100644 --- a/spec/edit-session-spec.coffee +++ b/spec/edit-session-spec.coffee @@ -2390,14 +2390,14 @@ describe "EditSession", -> describe "when a better-matched grammar is added to syntax", -> it "switches to the better-matched grammar and re-tokenizes the buffer", -> editSession.destroy() - jsGrammar = syntax.selectGrammar('a.js') - syntax.removeGrammar(jsGrammar) + jsGrammar = atom.syntax.selectGrammar('a.js') + atom.syntax.removeGrammar(jsGrammar) editSession = project.openSync('sample.js', autoIndent: false) - expect(editSession.getGrammar()).toBe syntax.nullGrammar + expect(editSession.getGrammar()).toBe atom.syntax.nullGrammar expect(editSession.lineForScreenRow(0).tokens.length).toBe 1 - syntax.addGrammar(jsGrammar) + atom.syntax.addGrammar(jsGrammar) expect(editSession.getGrammar()).toBe jsGrammar expect(editSession.lineForScreenRow(0).tokens.length).toBeGreaterThan 1 diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 6d2c83fca..35bdea5fa 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -1925,7 +1925,7 @@ describe "Editor", -> miniEditor = new Editor(mini: true) miniEditor.setText("var something") previousTokens = miniEditor.lineForScreenRow(0).tokens - miniEditor.setGrammar(syntax.selectGrammar('something.js')) + miniEditor.setGrammar(atom.syntax.selectGrammar('something.js')) expect(miniEditor.getGrammar().name).toBe "JavaScript" expect(previousTokens).not.toEqual miniEditor.lineForScreenRow(0).tokens @@ -2357,7 +2357,7 @@ describe "Editor", -> it "updates all the rendered lines when the grammar changes", -> editor.edit(project.openSync(filePath)) expect(editor.getGrammar().name).toBe 'Plain Text' - syntax.setGrammarOverrideForPath(filePath, 'source.js') + atom.syntax.setGrammarOverrideForPath(filePath, 'source.js') editor.reloadGrammar() expect(editor.getGrammar().name).toBe 'JavaScript' @@ -2383,7 +2383,7 @@ describe "Editor", -> expect(eventHandler).not.toHaveBeenCalled() - syntax.setGrammarOverrideForPath(filePath, 'source.js') + atom.syntax.setGrammarOverrideForPath(filePath, 'source.js') editor.reloadGrammar() expect(eventHandler).toHaveBeenCalled() diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 9316ebd77..95f6618c9 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -126,7 +126,7 @@ afterEach -> delete atom.windowState jasmine.unspy(atom, 'saveWindowState') ensureNoPathSubscriptions() - syntax.off() + atom.syntax.off() waits(0) # yield to ui thread to make screen update more frequently ensureNoPathSubscriptions = -> diff --git a/spec/syntax-spec.coffee b/spec/syntax-spec.coffee index 3bf598dd2..8cc7ed73b 100644 --- a/spec/syntax-spec.coffee +++ b/spec/syntax-spec.coffee @@ -13,52 +13,52 @@ describe "the `syntax` global", -> describe "serialization", -> it "remembers grammar overrides by path", -> filePath = '/foo/bar/file.js' - expect(syntax.selectGrammar(filePath).name).not.toBe 'Ruby' - syntax.setGrammarOverrideForPath(filePath, 'source.ruby') - syntax2 = deserialize(syntax.serialize()) - syntax2.addGrammar(grammar) for grammar in syntax.grammars when grammar isnt syntax.nullGrammar + expect(atom.syntax.selectGrammar(filePath).name).not.toBe 'Ruby' + atom.syntax.setGrammarOverrideForPath(filePath, 'source.ruby') + syntax2 = deserialize(atom.syntax.serialize()) + syntax2.addGrammar(grammar) for grammar in atom.syntax.grammars when grammar isnt atom.syntax.nullGrammar expect(syntax2.selectGrammar(filePath).name).toBe 'Ruby' describe ".selectGrammar(filePath)", -> it "can use the filePath to load the correct grammar based on the grammar's filetype", -> atom.activatePackage('language-git', sync: true) - expect(syntax.selectGrammar("file.js").name).toBe "JavaScript" # based on extension (.js) - expect(syntax.selectGrammar(path.join(temp.dir, '.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) - expect(syntax.selectGrammar("curb").name).toBe "Null Grammar" - expect(syntax.selectGrammar("/hu.git/config").name).toBe "Null Grammar" + expect(atom.syntax.selectGrammar("file.js").name).toBe "JavaScript" # based on extension (.js) + expect(atom.syntax.selectGrammar(path.join(temp.dir, '.git', 'config')).name).toBe "Git Config" # based on end of the path (.git/config) + expect(atom.syntax.selectGrammar("Rakefile").name).toBe "Ruby" # based on the file's basename (Rakefile) + expect(atom.syntax.selectGrammar("curb").name).toBe "Null Grammar" + expect(atom.syntax.selectGrammar("/hu.git/config").name).toBe "Null Grammar" 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.selectGrammar(filePath).name).toBe "Ruby" + expect(atom.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('language-property-list', sync: true) fileContent = "first-line\n" - expect(syntax.selectGrammar("dummy.coffee", fileContent).name).toBe "CoffeeScript" + expect(atom.syntax.selectGrammar("dummy.coffee", fileContent).name).toBe "CoffeeScript" fileContent = '' - expect(syntax.selectGrammar("grammar.tmLanguage", fileContent).name).toBe "Null Grammar" + expect(atom.syntax.selectGrammar("grammar.tmLanguage", fileContent).name).toBe "Null Grammar" fileContent += '\n' - expect(syntax.selectGrammar("grammar.tmLanguage", fileContent).name).toBe "Property List (XML)" + expect(atom.syntax.selectGrammar("grammar.tmLanguage", fileContent).name).toBe "Property List (XML)" it "doesn't read the file when the file contents are specified", -> filePath = require.resolve("./fixtures/shebang") filePathContents = fs.readFileSync(filePath, 'utf8') spyOn(fs, 'read').andCallThrough() - expect(syntax.selectGrammar(filePath, filePathContents).name).toBe "Ruby" + expect(atom.syntax.selectGrammar(filePath, filePathContents).name).toBe "Ruby" expect(fs.read).not.toHaveBeenCalled() it "allows the default grammar to be overridden for a path", -> filePath = '/foo/bar/file.js' - expect(syntax.selectGrammar(filePath).name).not.toBe 'Ruby' - syntax.setGrammarOverrideForPath(filePath, 'source.ruby') - expect(syntax.selectGrammar(filePath).name).toBe 'Ruby' - syntax.clearGrammarOverrideForPath(filePath) - expect(syntax.selectGrammar(filePath).name).not.toBe 'Ruby' + expect(atom.syntax.selectGrammar(filePath).name).not.toBe 'Ruby' + atom.syntax.setGrammarOverrideForPath(filePath, 'source.ruby') + expect(atom.syntax.selectGrammar(filePath).name).toBe 'Ruby' + atom.syntax.clearGrammarOverrideForPath(filePath) + expect(atom.syntax.selectGrammar(filePath).name).not.toBe 'Ruby' describe "when multiple grammars have matching fileTypes", -> it "selects the grammar with the longest fileType match", -> @@ -72,46 +72,46 @@ describe "the `syntax` global", -> scopeName: 'source2' fileTypes: ['test'] - syntax.addGrammar(grammar1) - syntax.addGrammar(grammar2) + atom.syntax.addGrammar(grammar1) + atom.syntax.addGrammar(grammar2) - expect(syntax.selectGrammar('more.test', '')).toBe grammar1 + expect(atom.syntax.selectGrammar('more.test', '')).toBe grammar1 describe "when there is no file path", -> it "does not throw an exception (regression)", -> - expect(-> syntax.selectGrammar(null, '#!/usr/bin/ruby')).not.toThrow() - expect(-> syntax.selectGrammar(null, '')).not.toThrow() - expect(-> syntax.selectGrammar(null, null)).not.toThrow() + expect(-> atom.syntax.selectGrammar(null, '#!/usr/bin/ruby')).not.toThrow() + expect(-> atom.syntax.selectGrammar(null, '')).not.toThrow() + expect(-> atom.syntax.selectGrammar(null, null)).not.toThrow() 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 + grammar = atom.syntax.selectGrammar('foo.js') + atom.syntax.removeGrammar(grammar) + expect(atom.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) - syntax.addProperties(".source .string.quoted.double", foo: bar: baz: 22) - syntax.addProperties(".source", foo: bar: baz: 11) + atom.syntax.addProperties(".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42) + atom.syntax.addProperties(".source .string.quoted.double", foo: bar: baz: 22) + atom.syntax.addProperties(".source", foo: bar: baz: 11) - 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")).toBeUndefined() + expect(atom.syntax.getProperty([".source.coffee", ".string.quoted.double.coffee"], "foo.bar.baz")).toBe 42 + expect(atom.syntax.getProperty([".source.js", ".string.quoted.double.js"], "foo.bar.baz")).toBe 22 + expect(atom.syntax.getProperty([".source.js", ".variable.assignment.js"], "foo.bar.baz")).toBe 11 + expect(atom.syntax.getProperty([".text"], "foo.bar.baz")).toBeUndefined() 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) + atom.syntax.addProperties(".source.coffee .string.quoted.single", foo: bar: baz: 42) + atom.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 + expect(atom.syntax.getProperty([".source.coffee", ".string.quoted.single"], "foo.bar.baz")).toBe 42 + expect(atom.syntax.getProperty([".source.coffee", ".string.quoted.single.double"], "foo.bar.baz")).toBe 22 describe ".removeProperties(name)", -> it "allows properties to be removed by name", -> - syntax.addProperties("a", ".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42) - syntax.addProperties("b", ".source .string.quoted.double", foo: bar: baz: 22) + atom.syntax.addProperties("a", ".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42) + atom.syntax.addProperties("b", ".source .string.quoted.double", foo: bar: baz: 22) - syntax.removeProperties("b") - expect(syntax.getProperty([".source.js", ".string.quoted.double.js"], "foo.bar.baz")).toBeUndefined() - expect(syntax.getProperty([".source.coffee", ".string.quoted.double.coffee"], "foo.bar.baz")).toBe 42 + atom.syntax.removeProperties("b") + expect(atom.syntax.getProperty([".source.js", ".string.quoted.double.js"], "foo.bar.baz")).toBeUndefined() + expect(atom.syntax.getProperty([".source.coffee", ".string.quoted.double.coffee"], "foo.bar.baz")).toBe 42 diff --git a/spec/text-mate-grammar-spec.coffee b/spec/text-mate-grammar-spec.coffee index 2c76a9796..00198afff 100644 --- a/spec/text-mate-grammar-spec.coffee +++ b/spec/text-mate-grammar-spec.coffee @@ -13,7 +13,7 @@ describe "TextMateGrammar", -> atom.activatePackage('language-html', sync: true) atom.activatePackage('language-php', sync: true) atom.activatePackage('language-python', sync: true) - grammar = syntax.selectGrammar("hello.coffee") + grammar = atom.syntax.selectGrammar("hello.coffee") describe "@loadSync(path)", -> it "loads grammars from plists", -> @@ -49,7 +49,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 = syntax.selectGrammar('foo.txt') + textGrammar = atom.syntax.selectGrammar('foo.txt') {tokens} = textGrammar.tokenizeLine("abc def") expect(tokens.length).toBe 1 @@ -126,20 +126,20 @@ describe "TextMateGrammar", -> describe "when the line matches no patterns", -> it "does not infinitely loop", -> - grammar = syntax.selectGrammar("sample.txt") + grammar = atom.syntax.selectGrammar("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 = syntax.selectGrammar("sample.txt") + grammar = atom.syntax.selectGrammar("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 = syntax.selectGrammar('foo.rb') + grammar = atom.syntax.selectGrammar('foo.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"] @@ -184,7 +184,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 = syntax.selectGrammar('foo.rb') + grammar = atom.syntax.selectGrammar('foo.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"] @@ -193,7 +193,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 = syntax.selectGrammar('foo.rb') + grammar = atom.syntax.selectGrammar('foo.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"] @@ -214,7 +214,7 @@ describe "TextMateGrammar", -> atom.activatePackage('language-html', sync: true) atom.activatePackage('language-ruby-on-rails', sync: true) - grammar = syntax.grammarForScopeName('text.html.ruby') + grammar = atom.syntax.grammarForScopeName('text.html.ruby') {tokens} = grammar.tokenizeLine("