mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Merge branch 'master' of https://github.com/github/linguist
This commit is contained in:
@@ -11,6 +11,17 @@ class TestBlob < Test::Unit::TestCase
|
||||
|
||||
Lexer = Pygments::Lexer
|
||||
|
||||
def setup
|
||||
# git blobs are normally loaded as ASCII-8BIT since they may contain data
|
||||
# with arbitrary encoding not known ahead of time
|
||||
@original_external = Encoding.default_external
|
||||
Encoding.default_external = Encoding.find("ASCII-8BIT")
|
||||
end
|
||||
|
||||
def teardown
|
||||
Encoding.default_external = @original_external
|
||||
end
|
||||
|
||||
def samples_path
|
||||
File.expand_path("../../samples", __FILE__)
|
||||
end
|
||||
@@ -67,6 +78,14 @@ class TestBlob < Test::Unit::TestCase
|
||||
assert_equal 475, blob("Emacs Lisp/ess-julia.el").lines.length
|
||||
end
|
||||
|
||||
def test_lines_maintains_original_encoding
|
||||
# Even if the file's encoding is detected as something like UTF-16LE,
|
||||
# earlier versions of the gem made implicit guarantees that the encoding of
|
||||
# each `line` is in the same encoding as the file was originally read (in
|
||||
# practice, UTF-8 or ASCII-8BIT)
|
||||
assert_equal Encoding.default_external, blob("Text/utf16le.txt").lines.first.encoding
|
||||
end
|
||||
|
||||
def test_size
|
||||
assert_equal 15, blob("Ruby/foo.rb").size
|
||||
end
|
||||
@@ -77,13 +96,27 @@ class TestBlob < Test::Unit::TestCase
|
||||
|
||||
def test_sloc
|
||||
assert_equal 2, blob("Ruby/foo.rb").sloc
|
||||
assert_equal 3, blob("Text/utf16le-windows.txt").sloc
|
||||
assert_equal 1, blob("Text/iso8859-8-i.txt").sloc
|
||||
end
|
||||
|
||||
def test_encoding
|
||||
assert_equal "ISO-8859-2", blob("Text/README").encoding
|
||||
assert_equal "ISO-8859-2", blob("Text/README").ruby_encoding
|
||||
assert_equal "ISO-8859-1", blob("Text/dump.sql").encoding
|
||||
assert_equal "ISO-8859-1", blob("Text/dump.sql").ruby_encoding
|
||||
assert_equal "UTF-8", blob("Text/foo.txt").encoding
|
||||
assert_equal "UTF-8", blob("Text/foo.txt").ruby_encoding
|
||||
assert_equal "UTF-16LE", blob("Text/utf16le.txt").encoding
|
||||
assert_equal "UTF-16LE", blob("Text/utf16le.txt").ruby_encoding
|
||||
assert_equal "UTF-16LE", blob("Text/utf16le-windows.txt").encoding
|
||||
assert_equal "UTF-16LE", blob("Text/utf16le-windows.txt").ruby_encoding
|
||||
assert_equal "ISO-2022-KR", blob("Text/ISO-2022-KR.txt").encoding
|
||||
assert_equal "binary", blob("Text/ISO-2022-KR.txt").ruby_encoding
|
||||
assert_nil blob("Binary/dog.o").encoding
|
||||
|
||||
assert_equal "windows-1252", blob("Text/Visual_Battlers.rb").encoding
|
||||
assert_equal "Windows-1252", blob("Text/Visual_Battlers.rb").ruby_encoding
|
||||
end
|
||||
|
||||
def test_binary
|
||||
@@ -214,6 +247,13 @@ class TestBlob < Test::Unit::TestCase
|
||||
# Generated VCR
|
||||
assert blob("YAML/vcr_cassette.yml").generated?
|
||||
|
||||
# Generated by Zephir
|
||||
assert blob("Zephir/filenames/exception.zep.c").generated?
|
||||
assert blob("Zephir/filenames/exception.zep.h").generated?
|
||||
assert blob("Zephir/filenames/exception.zep.php").generated?
|
||||
assert !blob("Zephir/Router.zep").generated?
|
||||
|
||||
|
||||
assert Linguist::Generated.generated?("node_modules/grunt/lib/grunt.js", nil)
|
||||
end
|
||||
|
||||
@@ -237,6 +277,10 @@ 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?
|
||||
|
||||
# C deps
|
||||
assert blob("deps/http_parser/http_parser.c").vendored?
|
||||
@@ -306,6 +350,14 @@ class TestBlob < Test::Unit::TestCase
|
||||
assert blob("public/javascripts/angular.js").vendored?
|
||||
assert blob("public/javascripts/angular.min.js").vendored?
|
||||
|
||||
# D3.js
|
||||
assert blob("public/javascripts/d3.v3.js").vendored?
|
||||
assert blob("public/javascripts/d3.v3.min.js").vendored?
|
||||
|
||||
# Modernizr
|
||||
assert blob("public/javascripts/modernizr-2.7.1.js").vendored?
|
||||
assert blob("public/javascripts/modernizr.custom.01009.js").vendored?
|
||||
|
||||
# Fabric
|
||||
assert blob("fabfile.py").vendored?
|
||||
|
||||
@@ -334,6 +386,10 @@ class TestBlob < Test::Unit::TestCase
|
||||
# NuGet Packages
|
||||
assert blob("packages/Modernizr.2.0.6/Content/Scripts/modernizr-2.0.6-development-only.js").vendored?
|
||||
|
||||
# Html5shiv
|
||||
assert blob("Scripts/html5shiv.js").vendored?
|
||||
assert blob("Scripts/html5shiv.min.js").vendored?
|
||||
|
||||
# Test fixtures
|
||||
assert blob("test/fixtures/random.rkt").vendored?
|
||||
assert blob("Test/fixtures/random.rkt").vendored?
|
||||
@@ -354,6 +410,11 @@ class TestBlob < Test::Unit::TestCase
|
||||
assert blob("subproject/gradlew").vendored?
|
||||
assert blob("subproject/gradlew.bat").vendored?
|
||||
assert blob("subproject/gradle/wrapper/gradle-wrapper.properties").vendored?
|
||||
|
||||
# Octicons
|
||||
assert blob("octicons.css").vendored?
|
||||
assert blob("public/octicons.min.css").vendored?
|
||||
assert blob("public/octicons/sprockets-octicons.scss").vendored?
|
||||
end
|
||||
|
||||
def test_language
|
||||
|
||||
@@ -10,6 +10,7 @@ class TestLanguage < Test::Unit::TestCase
|
||||
|
||||
def test_lexer
|
||||
assert_equal Lexer['ActionScript 3'], Language['ActionScript'].lexer
|
||||
assert_equal Lexer['AspectJ'], Language['AspectJ'].lexer
|
||||
assert_equal Lexer['Bash'], Language['Gentoo Ebuild'].lexer
|
||||
assert_equal Lexer['Bash'], Language['Gentoo Eclass'].lexer
|
||||
assert_equal Lexer['Bash'], Language['Shell'].lexer
|
||||
@@ -213,7 +214,7 @@ class TestLanguage < Test::Unit::TestCase
|
||||
def test_searchable
|
||||
assert Language['Ruby'].searchable?
|
||||
assert !Language['Gettext Catalog'].searchable?
|
||||
assert !Language['SQL'].searchable?
|
||||
assert Language['SQL'].searchable?
|
||||
end
|
||||
|
||||
def test_find_by_name
|
||||
@@ -322,7 +323,7 @@ class TestLanguage < Test::Unit::TestCase
|
||||
def test_color
|
||||
assert_equal '#701516', Language['Ruby'].color
|
||||
assert_equal '#3581ba', Language['Python'].color
|
||||
assert_equal '#f15501', Language['JavaScript'].color
|
||||
assert_equal '#f1e05a', Language['JavaScript'].color
|
||||
assert_equal '#31859c', Language['TypeScript'].color
|
||||
end
|
||||
|
||||
@@ -385,6 +386,15 @@ class TestLanguage < Test::Unit::TestCase
|
||||
<div class="highlight"><pre><span class="k">def</span> <span class="nf">foo</span>
|
||||
<span class="s1">'foo'</span>
|
||||
<span class="k">end</span>
|
||||
</pre></div>
|
||||
HTML
|
||||
end
|
||||
|
||||
def test_colorize_with_options
|
||||
assert_equal <<-HTML.chomp, Language['Ruby'].colorize("def foo\n 'foo'\nend\n", :options => { :cssclass => "highlight highlight-ruby" })
|
||||
<div class="highlight highlight-ruby"><pre><span class="k">def</span> <span class="nf">foo</span>
|
||||
<span class="s1">'foo'</span>
|
||||
<span class="k">end</span>
|
||||
</pre></div>
|
||||
HTML
|
||||
end
|
||||
|
||||
@@ -22,10 +22,10 @@ class TestPedantic < Test::Unit::TestCase
|
||||
file("languages.yml").lines.each do |line|
|
||||
if line =~ /^ extensions:$/
|
||||
extensions = []
|
||||
elsif extensions && line =~ /^ - \.(\w+)$/
|
||||
elsif extensions && line =~ /^ - \.([\w-]+)( *#.*)?$/
|
||||
extensions << $1
|
||||
else
|
||||
assert_sorted extensions if extensions
|
||||
assert_sorted extensions[1..-1] if extensions
|
||||
extensions = nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'linguist/samples'
|
||||
require 'linguist/language'
|
||||
require 'tempfile'
|
||||
require 'yajl'
|
||||
|
||||
require 'test/unit'
|
||||
|
||||
class TestSamples < Test::Unit::TestCase
|
||||
@@ -35,4 +35,22 @@ 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|
|
||||
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
|
||||
if language_matches.length > 1
|
||||
language_matches.each do |language|
|
||||
assert File.directory?("samples/#{language.name}"), "#{language.name} is missing a samples directory"
|
||||
assert Dir.glob("samples/#{language.name}/*#{extension}").any?, "#{language.name} is missing samples for extension #{extension}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user