Merge branch 'master' into 1036-local

Conflicts:
	lib/linguist/heuristics.rb
	lib/linguist/samples.json
This commit is contained in:
Arfon Smith
2014-10-23 12:05:18 +01:00
85 changed files with 59180 additions and 73601 deletions

View File

@@ -262,6 +262,10 @@ class TestBlob < Test::Unit::TestCase
assert Linguist::Generated.generated?("node_modules/grunt/lib/grunt.js", nil)
# Godep saved dependencies
assert blob("Godeps/Godeps.json").generated?
assert blob("Godeps/_workspace/src/github.com/kr/s3/sign.go").generated?
end
def test_vendored
@@ -279,6 +283,10 @@ class TestBlob < Test::Unit::TestCase
assert blob("app/bower_components/custom/custom.js").vendored?
assert blob("vendor/assets/bower_components/custom/custom.js").vendored?
# Go dependencies
assert !blob("Godeps/Godeps.json").vendored?
assert blob("Godeps/_workspace/src/github.com/kr/s3/sign.go").vendored?
# Rails vendor/
assert blob("vendor/plugins/will_paginate/lib/will_paginate.rb").vendored?
@@ -437,6 +445,12 @@ class TestBlob < Test::Unit::TestCase
assert blob("octicons.css").vendored?
assert blob("public/octicons.min.css").vendored?
assert blob("public/octicons/sprockets-octicons.scss").vendored?
# Typesafe Activator
assert blob("activator").vendored?
assert blob("activator.bat").vendored?
assert blob("subproject/activator").vendored?
assert blob("subproject/activator.bat").vendored?
end
def test_language

View File

@@ -44,12 +44,12 @@ class TestClassifier < Test::Unit::TestCase
end
def test_instance_classify_empty
results = Classifier.classify(Samples::DATA, "")
results = Classifier.classify(Samples.cache, "")
assert results.first[1] < 0.5, results.first.inspect
end
def test_instance_classify_nil
assert_equal [], Classifier.classify(Samples::DATA, nil)
assert_equal [], Classifier.classify(Samples.cache, nil)
end
def test_classify_ambiguous_languages
@@ -58,7 +58,7 @@ class TestClassifier < Test::Unit::TestCase
languages = Language.find_by_filename(sample[:path]).map(&:name)
next unless languages.length > 1
results = Classifier.classify(Samples::DATA, File.read(sample[:path]), languages)
results = Classifier.classify(Samples.cache, File.read(sample[:path]), languages)
assert_equal language.name, results.first[0], "#{sample[:path]}\n#{results.inspect}"
end
end

View File

@@ -74,6 +74,18 @@ class TestHeuristcs < Test::Unit::TestCase
assert_equal Language["ECL"], results.first
end
def test_pro_prolog_by_heuristics
languages = ["IDL", "Prolog"]
results = Heuristics.disambiguate_pro(fixture("Prolog/logic-problem.pro"), languages)
assert_equal Language["Prolog"], results.first
end
def test_pro_idl_by_heuristics
languages = ["IDL", "Prolog"]
results = Heuristics.disambiguate_pro(fixture("IDL/mg_acosh.pro"), languages)
assert_equal Language["IDL"], results.first
end
def test_ts_typescript_by_heuristics
languages = ["TypeScript", "XML"]
results = Heuristics.disambiguate_ts(fixture("TypeScript/classes.ts"), languages)

View File

@@ -33,6 +33,7 @@ class TestLanguage < Test::Unit::TestCase
assert_equal Lexer['Java'], Language['ChucK'].lexer
assert_equal Lexer['Java'], Language['Java'].lexer
assert_equal Lexer['JavaScript'], Language['JavaScript'].lexer
assert_equal Lexer['LSL'], Language['LSL'].lexer
assert_equal Lexer['MOOCode'], Language['Moocode'].lexer
assert_equal Lexer['MuPAD'], Language['mupad'].lexer
assert_equal Lexer['NASM'], Language['Assembly'].lexer
@@ -186,6 +187,7 @@ class TestLanguage < Test::Unit::TestCase
def test_programming
assert_equal :programming, Language['JavaScript'].type
assert_equal :programming, Language['LSL'].type
assert_equal :programming, Language['Perl'].type
assert_equal :programming, Language['PowerShell'].type
assert_equal :programming, Language['Python'].type
@@ -326,6 +328,7 @@ class TestLanguage < Test::Unit::TestCase
assert_equal '#3581ba', Language['Python'].color
assert_equal '#f1e05a', Language['JavaScript'].color
assert_equal '#31859c', Language['TypeScript'].color
assert_equal '#3d9970', Language['LSL'].color
end
def test_colors
@@ -338,6 +341,7 @@ class TestLanguage < Test::Unit::TestCase
assert_equal 'coffee', Language['CoffeeScript'].ace_mode
assert_equal 'csharp', Language['C#'].ace_mode
assert_equal 'css', Language['CSS'].ace_mode
assert_equal 'lsl', Language['LSL'].ace_mode
assert_equal 'javascript', Language['JavaScript'].ace_mode
end
@@ -352,6 +356,7 @@ class TestLanguage < Test::Unit::TestCase
end
def test_extensions
assert Language['LSL'].extensions.include?('.lsl')
assert Language['Perl'].extensions.include?('.pl')
assert Language['Python'].extensions.include?('.py')
assert Language['Ruby'].extensions.include?('.rb')

View File

@@ -1,5 +1,5 @@
require 'linguist/repository'
require 'linguist/lazy_blob'
require 'test/unit'
class TestRepository < Test::Unit::TestCase
@@ -47,4 +47,58 @@ class TestRepository < Test::Unit::TestCase
assert_equal linguist_repo.cache, new_repo.cache
end
def test_repo_git_attributes
# See https://github.com/github/linguist/blob/351c1cc8fd57340839bdb400d7812332af80e9bd/.gitattributes
#
# It looks like this:
# Gemfile linguist-vendored=true
# lib/linguist.rb linguist-language=Java
# test/*.rb linguist-language=Java
# Rakefile linguist-generated
# test/fixtures/* linguist-vendored=false
attr_commit = '351c1cc8fd57340839bdb400d7812332af80e9bd'
repo = linguist_repo(attr_commit)
assert repo.breakdown_by_file.has_key?("Java")
assert repo.breakdown_by_file["Java"].include?("lib/linguist.rb")
assert repo.breakdown_by_file.has_key?("Ruby")
assert !repo.breakdown_by_file["Ruby"].empty?
end
def test_commit_with_git_attributes_data
# Before we had any .gitattributes data
old_commit = '4a017d9033f91b2776eb85275463f9613cc371ef'
old_repo = linguist_repo(old_commit)
# With some .gitattributes data
attr_commit = '7ee006cbcb2d7261f9e648510a684ee9ac64126b'
# It's incremental but should bust the cache
new_repo = Linguist::Repository.incremental(rugged_repository, attr_commit, old_commit, old_repo.cache)
assert new_repo.breakdown_by_file["Java"].include?("lib/linguist.rb")
end
def test_linguist_override_vendored?
attr_commit = '351c1cc8fd57340839bdb400d7812332af80e9bd'
repo = linguist_repo(attr_commit).read_index
override_vendored = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Gemfile')
# overridden .gitattributes
assert override_vendored.vendored?
end
def test_linguist_override_unvendored?
attr_commit = '351c1cc8fd57340839bdb400d7812332af80e9bd'
repo = linguist_repo(attr_commit).read_index
# lib/linguist/vendor.yml defines this as vendored.
override_unvendored = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'test/fixtures/foo.rb')
# overridden .gitattributes
assert !override_unvendored.vendored?
end
end

View File

@@ -8,7 +8,7 @@ class TestSamples < Test::Unit::TestCase
include Linguist
def test_up_to_date
assert serialized = Samples::DATA
assert serialized = Samples.cache
assert latest = Samples.data
# Just warn, it shouldn't scare people off by breaking the build.
@@ -29,7 +29,7 @@ class TestSamples < Test::Unit::TestCase
end
def test_verify
assert data = Samples::DATA
assert data = Samples.cache
assert_equal data['languages_total'], data['languages'].inject(0) { |n, (_, c)| n += c }
assert_equal data['tokens_total'], data['language_tokens'].inject(0) { |n, (_, c)| n += c }
@@ -38,7 +38,7 @@ class TestSamples < Test::Unit::TestCase
# Check that there aren't samples with extensions that aren't explicitly defined in languages.yml
def test_parity
extensions = Samples::DATA['extnames']
extensions = Samples.cache['extnames']
languages_yml = File.expand_path("../../lib/linguist/languages.yml", __FILE__)
languages = YAML.load_file(languages_yml)