This commit is contained in:
dx-mon
2014-07-14 22:08:16 +01:00
47 changed files with 4775 additions and 10961 deletions

View File

@@ -140,6 +140,13 @@ class TestBlob < Test::Unit::TestCase
assert !blob("Perl/script.pl").binary?
end
def test_all_binary
Samples.each do |sample|
blob = blob(sample[:path])
assert ! (blob.likely_binary? || blob.binary?), "#{sample[:path]} is a binary file"
end
end
def test_text
assert blob("Text/README").text?
assert blob("Text/dump.sql").text?
@@ -277,7 +284,7 @@ class TestBlob < Test::Unit::TestCase
# 'thirdparty' directory
assert blob("thirdparty/lib/main.c").vendored?
# 'extern(al)' directory
assert blob("extern/util/__init__.py").vendored?
assert blob("external/jquery.min.js").vendored?
@@ -386,6 +393,12 @@ class TestBlob < Test::Unit::TestCase
# NuGet Packages
assert blob("packages/Modernizr.2.0.6/Content/Scripts/modernizr-2.0.6-development-only.js").vendored?
# Normalize
assert blob("some/asset/path/normalize.css").vendored?
# Cocoapods
assert blob('Pods/blah').vendored?
# Html5shiv
assert blob("Scripts/html5shiv.js").vendored?
assert blob("Scripts/html5shiv.min.js").vendored?

View File

@@ -1,6 +1,7 @@
require 'linguist/heuristics'
require 'linguist/language'
require 'linguist/samples'
require 'linguist/file_blob'
require 'test/unit'
@@ -44,7 +45,8 @@ class TestHeuristcs < Test::Unit::TestCase
end
def test_detect_still_works_if_nothing_matches
match = Language.detect("Hello.m", fixture("Objective-C/hello.m"))
blob = Linguist::FileBlob.new(File.join(samples_path, "Objective-C/hello.m"))
match = Language.detect(blob)
assert_equal Language["Objective-C"], match
end

View File

@@ -249,8 +249,7 @@ class TestLanguage < Test::Unit::TestCase
assert_equal Language['Nginx'], Language.find_by_filename('nginx.conf').first
assert_equal ['C', 'C++', 'Objective-C'], Language.find_by_filename('foo.h').map(&:name).sort
assert_equal [], Language.find_by_filename('rb')
assert_equal [], Language.find_by_filename('.rb')
assert_equal [], Language.find_by_filename('.nkt')
assert_equal [], Language.find_by_filename('.null')
assert_equal [Language['Shell']], Language.find_by_filename('.bashrc')
assert_equal [Language['Shell']], Language.find_by_filename('bash_profile')
assert_equal [Language['Shell']], Language.find_by_filename('.zshrc')

View File

@@ -3,22 +3,24 @@ require 'linguist/repository'
require 'test/unit'
class TestRepository < Test::Unit::TestCase
include Linguist
def repo(base_path)
Repository.from_directory(base_path)
def rugged_repository
@rugged ||= Rugged::Repository.new(File.expand_path("../../.git", __FILE__))
end
def linguist_repo
repo(File.expand_path("../..", __FILE__))
def master_oid
'd40b4a33deba710e2f494db357c654fbe5d4b419'
end
def linguist_repo(oid = master_oid)
Linguist::Repository.new(rugged_repository, oid)
end
def test_linguist_language
# assert_equal Language['Ruby'], linguist_repo.language
assert_equal 'Ruby', linguist_repo.language
end
def test_linguist_languages
# assert linguist_repo.languages[Language['Ruby']] > 10_000
assert linguist_repo.languages['Ruby'] > 10_000
end
def test_linguist_size
@@ -31,7 +33,18 @@ class TestRepository < Test::Unit::TestCase
assert linguist_repo.breakdown_by_file["Ruby"].include?("lib/linguist/language.rb")
end
def test_binary_override
assert_equal repo(File.expand_path("../../samples/Nimrod", __FILE__)).language, Language["Nimrod"]
def test_incremental_stats
old_commit = '3d7364877d6794f6cc2a86b493e893968a597332'
old_repo = linguist_repo(old_commit)
assert old_repo.languages['Ruby'] > 10_000
assert old_repo.size > 30_000
new_repo = Linguist::Repository.incremental(rugged_repository, master_oid, old_commit, old_repo.cache)
assert new_repo.languages['Ruby'] > old_repo.languages['Ruby']
assert new_repo.size > old_repo.size
assert_equal linguist_repo.cache, new_repo.cache
end
end