Merge pull request #1756 from github/test-for-grammars

Test that all languages have grammars
This commit is contained in:
Adam Roben
2014-11-21 11:54:46 -05:00
2 changed files with 92 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
require 'linguist/language'
require 'test/unit'
require 'yaml'
class TestLanguage < Test::Unit::TestCase
include Linguist
@@ -359,4 +360,15 @@ class TestLanguage < Test::Unit::TestCase
def test_by_type
assert !Language.by_type(:prose).nil?
end
def test_all_languages_have_grammars
scopes = YAML.load(File.read(File.expand_path("../../grammars.yml", __FILE__))).values.flatten
missing = Language.all.reject { |language| language.tm_scope == "none" || scopes.include?(language.tm_scope) }
message = "The following languages' scopes are not listed in grammars.yml. Please add grammars for all new languages.\n"
message << "If no grammar exists for a language, mark the language with `tm_scope: none` in lib/linguist/languages.yml.\n"
width = missing.map { |language| language.name.length }.max
message << missing.map { |language| sprintf("%-#{width}s %s", language.name, language.tm_scope) }.sort.join("\n")
assert missing.empty?, message
end
end