mirror of
https://github.com/atom/atom.git
synced 2026-01-15 01:48:15 -05:00
Add spec for grammar score tie-breaking
This commit is contained in:
11
spec/fixtures/packages/package-with-rb-filetype/grammars/rb.cson
vendored
Normal file
11
spec/fixtures/packages/package-with-rb-filetype/grammars/rb.cson
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
'name': 'Test Ruby'
|
||||
'scopeName': 'test.rb'
|
||||
'fileTypes': [
|
||||
'rb'
|
||||
]
|
||||
'patterns': [
|
||||
{
|
||||
'match': 'ruby'
|
||||
'name': 'meta.class.ruby'
|
||||
}
|
||||
]
|
||||
4
spec/fixtures/packages/package-with-rb-filetype/package.json
vendored
Normal file
4
spec/fixtures/packages/package-with-rb-filetype/package.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "package-with-rb-filetype",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
@@ -94,6 +94,16 @@ describe "the `grammars` global", ->
|
||||
grammar2 = atom.grammars.loadGrammarSync(grammarPath2)
|
||||
expect(atom.grammars.selectGrammar('more.test', '')).toBe grammar2
|
||||
|
||||
it "favors non-bundled packages when breaking scoring ties", ->
|
||||
waitsForPromise ->
|
||||
atom.packages.activatePackage(path.join(__dirname, 'fixtures', 'packages', 'package-with-rb-filetype'))
|
||||
|
||||
runs ->
|
||||
atom.grammars.grammarForScopeName('source.ruby').bundledPackage = true
|
||||
atom.grammars.grammarForScopeName('test.rb').bundledPackage = false
|
||||
|
||||
expect(atom.grammars.selectGrammar('test.rb').scopeName).toBe 'test.rb'
|
||||
|
||||
describe "when there is no file path", ->
|
||||
it "does not throw an exception (regression)", ->
|
||||
expect(-> atom.grammars.selectGrammar(null, '#!/usr/bin/ruby')).not.toThrow()
|
||||
|
||||
@@ -42,6 +42,7 @@ class GrammarRegistry extends FirstMate.GrammarRegistry
|
||||
score = grammar.getScore(filePath, fileContents)
|
||||
if score > highestScore or not bestMatch?
|
||||
bestMatch = grammar
|
||||
highestScore = score
|
||||
else if score is highestScore and bestMatch?.bundledPackage
|
||||
bestMatch = grammar unless grammar.bundledPackage
|
||||
bestMatch
|
||||
|
||||
Reference in New Issue
Block a user