Adding test to check that languages.yml includes all extensions represented in samples folder

This commit is contained in:
Arfon Smith
2014-08-11 14:16:25 -07:00
parent 41c880afc7
commit 43923976c2
4 changed files with 30636 additions and 30457 deletions

View File

@@ -35,15 +35,33 @@ class TestSamples < Test::Unit::TestCase
assert_equal data['tokens_total'], data['language_tokens'].inject(0) { |n, (_, c)| n += c }
assert_equal data['tokens_total'], data['tokens'].inject(0) { |n, (_, ts)| n += ts.inject(0) { |m, (_, c)| m += c } }
end
# Check that there aren't samples with extensions that aren't explicitly defined in languages.yml
def test_parity
extensions = Samples::DATA['extnames']
languages_yml = File.expand_path("../../lib/linguist/languages.yml", __FILE__)
languages = YAML.load_file(languages_yml)
languages.each do |name, options|
options['extensions'] ||= []
if extnames = extensions[name]
extnames.each do |extname|
next if extname == '.script!'
assert options['extensions'].include?(extname), "#{name} has a sample with extension (#{extname}) that isn't explicitly defined in languages.yml"
end
end
end
end
# If a language extension isn't globally unique then make sure there are samples
def test_presence
Linguist::Language.all.each do |language|
language.all_extensions.each do |extension|
language_matches = Language.find_by_filename("foo#{extension}")
# If there is more than one language match for a given extension
# then check that there are examples for that language with the extension
# then check that there are examples for that language with the extension
if language_matches.length > 1
language_matches.each do |language|
assert File.directory?("samples/#{language.name}"), "#{language.name} is missing a samples directory"