Towards testing for presence of sample files

This commit is contained in:
Arfon Smith
2014-04-22 15:47:49 -05:00
parent 20f858c305
commit 536800f9f5

View File

@@ -1,7 +1,8 @@
require 'linguist/samples'
require 'linguist/language'
require 'tempfile'
require 'yajl'
require 'pry'
require 'test/unit'
class TestSamples < Test::Unit::TestCase
@@ -35,4 +36,25 @@ 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
# If a language extension isn't globally unique then make sure there are samples
def test_presence
Linguist::Language.all.each do |language|
# TODO - feels like there should be a better way to do this.
extensions = [language.primary_extension] + language.extensions
extensions.uniq.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
if language_matches.length > 1
language_matches.each do |language|
assert File.directory?("samples/#{language.name}")
assert Dir.glob("samples/#{language.name}/*#{extension}").any?
end
end
end
end
end
end