mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Merge branch 'master' into blob_in_memory
This commit is contained in:
3
test/fixtures/Data/Modelines/ruby2
vendored
Normal file
3
test/fixtures/Data/Modelines/ruby2
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/* vim: set ts=8 sw=4 filetype=ruby tw=0: */
|
||||
|
||||
# Please help how do I into setting vim modlines
|
||||
3
test/fixtures/Data/Modelines/ruby3
vendored
Normal file
3
test/fixtures/Data/Modelines/ruby3
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/* vim: set ft=ruby ts=8 sw=4 tw=0: */
|
||||
|
||||
# I am not good at humor
|
||||
@@ -308,6 +308,12 @@ class TestBlob < Minitest::Test
|
||||
# Erlang
|
||||
assert sample_blob("rebar").vendored?
|
||||
|
||||
# git config files
|
||||
|
||||
assert_predicate fixture_blob("some/path/.gitattributes"), :vendored?
|
||||
assert_predicate fixture_blob(".gitignore"), :vendored?
|
||||
assert_predicate fixture_blob("special/path/.gitmodules"), :vendored?
|
||||
|
||||
# Minified JavaScript and CSS
|
||||
assert sample_blob("foo.min.js").vendored?
|
||||
assert sample_blob("foo.min.css").vendored?
|
||||
@@ -326,9 +332,6 @@ class TestBlob < Minitest::Test
|
||||
assert sample_blob("public/javascripts/controls.js").vendored?
|
||||
assert sample_blob("public/javascripts/dragdrop.js").vendored?
|
||||
|
||||
# Samples
|
||||
assert sample_blob("Samples/Ruby/foo.rb").vendored?
|
||||
|
||||
# jQuery
|
||||
assert sample_blob("jquery.js").vendored?
|
||||
assert sample_blob("public/javascripts/jquery.js").vendored?
|
||||
@@ -511,15 +514,36 @@ class TestBlob < Minitest::Test
|
||||
assert_predicate fixture_blob("README"), :documentation?
|
||||
assert_predicate fixture_blob("README.md"), :documentation?
|
||||
assert_predicate fixture_blob("README.txt"), :documentation?
|
||||
assert_predicate fixture_blob("Readme"), :documentation?
|
||||
assert_predicate fixture_blob("readme"), :documentation?
|
||||
assert_predicate fixture_blob("foo/README"), :documentation?
|
||||
|
||||
assert_predicate fixture_blob("CHANGE"), :documentation?
|
||||
assert_predicate fixture_blob("CHANGE.md"), :documentation?
|
||||
assert_predicate fixture_blob("CHANGE.txt"), :documentation?
|
||||
assert_predicate fixture_blob("foo/CHANGE"), :documentation?
|
||||
|
||||
assert_predicate fixture_blob("CHANGELOG"), :documentation?
|
||||
assert_predicate fixture_blob("CHANGELOG.md"), :documentation?
|
||||
assert_predicate fixture_blob("CHANGELOG.txt"), :documentation?
|
||||
assert_predicate fixture_blob("foo/CHANGELOG"), :documentation?
|
||||
|
||||
assert_predicate fixture_blob("CHANGES"), :documentation?
|
||||
assert_predicate fixture_blob("CHANGES.md"), :documentation?
|
||||
assert_predicate fixture_blob("CHANGES.txt"), :documentation?
|
||||
assert_predicate fixture_blob("foo/CHANGES"), :documentation?
|
||||
|
||||
assert_predicate fixture_blob("CONTRIBUTING"), :documentation?
|
||||
assert_predicate fixture_blob("CONTRIBUTING.md"), :documentation?
|
||||
assert_predicate fixture_blob("CONTRIBUTING.txt"), :documentation?
|
||||
assert_predicate fixture_blob("foo/CONTRIBUTING"), :documentation?
|
||||
|
||||
assert_predicate fixture_blob("examples/some-file.pl"), :documentation?
|
||||
assert_predicate fixture_blob("Examples/some-example-file.rb"), :documentation?
|
||||
|
||||
assert_predicate fixture_blob("LICENSE"), :documentation?
|
||||
assert_predicate fixture_blob("LICENCE.md"), :documentation?
|
||||
assert_predicate fixture_blob("License.txt"), :documentation?
|
||||
assert_predicate fixture_blob("LICENSE.txt"), :documentation?
|
||||
assert_predicate fixture_blob("foo/LICENSE"), :documentation?
|
||||
|
||||
@@ -534,6 +558,11 @@ class TestBlob < Minitest::Test
|
||||
assert_predicate fixture_blob("foo/INSTALL"), :documentation?
|
||||
|
||||
refute_predicate fixture_blob("foo.md"), :documentation?
|
||||
|
||||
# Samples
|
||||
assert sample_blob("Samples/Ruby/foo.rb").documentation?
|
||||
|
||||
assert_predicate fixture_blob("INSTALL.txt"), :documentation?
|
||||
end
|
||||
|
||||
def test_language
|
||||
|
||||
@@ -22,42 +22,55 @@ class TestHeuristcs < Minitest::Test
|
||||
assert_equal [], results
|
||||
end
|
||||
|
||||
def assert_heuristics(hash)
|
||||
candidates = hash.keys.map { |l| Language[l] }
|
||||
|
||||
hash.each do |language, blobs|
|
||||
Array(blobs).each do |blob|
|
||||
result = Heuristics.call(file_blob(blob), candidates)
|
||||
assert_equal [Language[language]], result, "Failed for #{blob}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Candidate languages = ["C++", "Objective-C"]
|
||||
def test_obj_c_by_heuristics
|
||||
# Only calling out '.h' filenames as these are the ones causing issues
|
||||
assert_heuristics({
|
||||
"Objective-C" => all_fixtures("Objective-C", "*.h"),
|
||||
"C++" => ["C++/render_adapter.cpp", "C++/ThreadedQueue.h"],
|
||||
"C++" => ["C++/scanner.h", "C++/qscicommand.h", "C++/v8.h", "C++/gdsdbreader.h"],
|
||||
"C" => nil
|
||||
})
|
||||
end
|
||||
|
||||
def test_c_by_heuristics
|
||||
languages = [Language["C++"], Language["Objective-C"], Language["C"]]
|
||||
results = Heuristics.call(file_blob("C/ArrowLeft.h"), languages)
|
||||
assert_equal [], results
|
||||
end
|
||||
|
||||
def test_detect_still_works_if_nothing_matches
|
||||
blob = Linguist::FileBlob.new(File.join(samples_path, "Objective-C/hello.m"))
|
||||
match = Language.detect(blob)
|
||||
assert_equal Language["Objective-C"], match
|
||||
end
|
||||
|
||||
# Candidate languages = ["Perl", "Prolog"]
|
||||
# Candidate languages = ["Perl", "Perl6", "Prolog"]
|
||||
def test_pl_prolog_perl_by_heuristics
|
||||
assert_heuristics({
|
||||
"Prolog" => all_fixtures("Prolog/*.pl"),
|
||||
"Perl" => all_fixtures("Perl/*.pl") + ["Perl/perl-test.t"],
|
||||
"Perl6" => all_fixtures("Perl6/*.pl")
|
||||
"Prolog" => all_fixtures("Prolog", "*.pl"),
|
||||
"Perl" => ["Perl/oo1.pl", "Perl/oo2.pl", "Perl/oo3.pl", "Perl/fib.pl", "Perl/use5.pl"],
|
||||
"Perl6" => all_fixtures("Perl6", "*.pl")
|
||||
})
|
||||
end
|
||||
|
||||
# Candidate languages = ["Perl", "Perl6"]
|
||||
def test_pm_perl_by_heuristics
|
||||
assert_heuristics({
|
||||
"Perl" => all_fixtures("Perl", "*.pm"),
|
||||
"Perl6" => all_fixtures("Perl6", "*.pm")
|
||||
})
|
||||
end
|
||||
|
||||
# Candidate languages = ["ECL", "Prolog"]
|
||||
def test_ecl_prolog_by_heuristics
|
||||
assert_heuristics({
|
||||
"ECL" => "ECL/sample.ecl",
|
||||
"Prolog" => "Prolog/or-constraint.ecl"
|
||||
"ECL" => all_fixtures("ECL", "*.ecl"),
|
||||
"Prolog" => all_fixtures("Prolog", "*.ecl")
|
||||
})
|
||||
end
|
||||
|
||||
@@ -74,69 +87,69 @@ class TestHeuristcs < Minitest::Test
|
||||
# Candidate languages = ["AGS Script", "AsciiDoc", "Public Key"]
|
||||
def test_asc_by_heuristics
|
||||
assert_heuristics({
|
||||
"AsciiDoc" => "AsciiDoc/list.asc",
|
||||
"AGS Script" => "AGS Script/GlobalScript.asc",
|
||||
"AsciiDoc" => all_fixtures("AsciiDoc", "*.asc"),
|
||||
"AGS Script" => all_fixtures("AGS Script", "*.asc"),
|
||||
"Public Key" => all_fixtures("Public Key", "*.asc")
|
||||
})
|
||||
end
|
||||
|
||||
def test_cl_by_heuristics
|
||||
assert_heuristics({
|
||||
"Common Lisp" => all_fixtures("Common Lisp"),
|
||||
"OpenCL" => all_fixtures("OpenCL")
|
||||
"Common Lisp" => all_fixtures("Common Lisp", "*.cl"),
|
||||
"OpenCL" => all_fixtures("OpenCL", "*.cl")
|
||||
})
|
||||
end
|
||||
|
||||
def test_f_by_heuristics
|
||||
assert_heuristics({
|
||||
"FORTRAN" => all_fixtures("FORTRAN"),
|
||||
"Forth" => all_fixtures("Forth")
|
||||
"FORTRAN" => all_fixtures("FORTRAN", "*.f") + all_fixtures("FORTRAN", "*.for"),
|
||||
"Forth" => all_fixtures("Forth", "*.f") + all_fixtures("Forth", "*.for")
|
||||
})
|
||||
end
|
||||
|
||||
# Candidate languages = ["Hack", "PHP"]
|
||||
def test_hack_by_heuristics
|
||||
assert_heuristics({
|
||||
"Hack" => "Hack/funs.php",
|
||||
"PHP" => "PHP/Model.php"
|
||||
"Hack" => all_fixtures("Hack", "*.php"),
|
||||
"PHP" => all_fixtures("PHP", "*.php")
|
||||
})
|
||||
end
|
||||
|
||||
# Candidate languages = ["Scala", "SuperCollider"]
|
||||
def test_sc_supercollider_scala_by_heuristics
|
||||
assert_heuristics({
|
||||
"SuperCollider" => "SuperCollider/WarpPreset.sc",
|
||||
"Scala" => "Scala/node11.sc"
|
||||
"SuperCollider" => all_fixtures("SuperCollider", "*.sc"),
|
||||
"Scala" => all_fixtures("Scala", "*.sc")
|
||||
})
|
||||
end
|
||||
|
||||
def test_fs_by_heuristics
|
||||
assert_heuristics({
|
||||
"F#" => all_fixtures("F#"),
|
||||
"Forth" => all_fixtures("Forth"),
|
||||
"GLSL" => all_fixtures("GLSL")
|
||||
"F#" => all_fixtures("F#", "*.fs"),
|
||||
"Forth" => all_fixtures("Forth", "*.fs"),
|
||||
"GLSL" => all_fixtures("GLSL", "*.fs")
|
||||
})
|
||||
end
|
||||
|
||||
def test_fr_by_heuristics
|
||||
assert_heuristics({
|
||||
"Frege" => all_fixtures("Frege"),
|
||||
"Forth" => all_fixtures("Forth"),
|
||||
"Text" => all_fixtures("Text")
|
||||
"Frege" => all_fixtures("Frege", "*.fr"),
|
||||
"Forth" => all_fixtures("Forth", "*.fr"),
|
||||
"Text" => all_fixtures("Text", "*.fr")
|
||||
})
|
||||
end
|
||||
|
||||
def test_bb_by_heuristics
|
||||
assert_heuristics({
|
||||
"BitBake" => all_fixtures("BitBake"),
|
||||
"BlitzBasic" => all_fixtures("BlitzBasic")
|
||||
"BitBake" => all_fixtures("BitBake", "*.bb"),
|
||||
"BlitzBasic" => all_fixtures("BlitzBasic", "*.bb")
|
||||
})
|
||||
end
|
||||
|
||||
def test_lsp_by_heuristics
|
||||
assert_heuristics({
|
||||
"Common Lisp" => all_fixtures("Common Lisp"),
|
||||
"NewLisp" => all_fixtures("NewLisp")
|
||||
"Common Lisp" => all_fixtures("Common Lisp", "*.lsp") + all_fixtures("Common Lisp", "*.lisp"),
|
||||
"NewLisp" => all_fixtures("NewLisp", "*.lsp") + all_fixtures("NewLisp", "*.lisp")
|
||||
})
|
||||
end
|
||||
|
||||
@@ -147,21 +160,10 @@ class TestHeuristcs < Minitest::Test
|
||||
})
|
||||
end
|
||||
|
||||
def assert_heuristics(hash)
|
||||
candidates = hash.keys.map { |l| Language[l] }
|
||||
|
||||
hash.each do |language, blobs|
|
||||
Array(blobs).each do |blob|
|
||||
result = Heuristics.call(file_blob(blob), candidates)
|
||||
assert_equal [Language[language]], result, "Failed for #{blob}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_ls_by_heuristics
|
||||
assert_heuristics({
|
||||
"LiveScript" => "LiveScript/hello.ls",
|
||||
"LoomScript" => "LoomScript/HelloWorld.ls"
|
||||
"LiveScript" => all_fixtures("LiveScript", "*.ls"),
|
||||
"LoomScript" => all_fixtures("LoomScript", "*.ls")
|
||||
})
|
||||
end
|
||||
|
||||
@@ -171,4 +173,17 @@ class TestHeuristcs < Minitest::Test
|
||||
"XML" => all_fixtures("XML", "*.ts")
|
||||
})
|
||||
end
|
||||
|
||||
def test_ch_by_heuristics
|
||||
assert_heuristics({
|
||||
"xBase" => all_fixtures("xBase", ".ch")
|
||||
})
|
||||
end
|
||||
|
||||
def test_r_by_heuristics
|
||||
assert_heuristics({
|
||||
"R" => all_fixtures("R", "*.r") + all_fixtures("R", "*.R"),
|
||||
"Rebol" => all_fixtures("Rebol", "*.r")
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -263,6 +263,24 @@ class TestLanguage < Minitest::Test
|
||||
assert_equal 'AGS Script', Language.find_by_alias('AGS').name
|
||||
end
|
||||
|
||||
def test_find_ignores_comma
|
||||
assert_equal 'Rust', Language['rust,no_run'].name
|
||||
end
|
||||
|
||||
def test_find_by_name_ignores_comma
|
||||
assert_equal Language['Rust'], Language.find_by_name('rust,no_run')
|
||||
end
|
||||
|
||||
def test_find_by_alias_ignores_comma
|
||||
assert_equal Language['Rust'], Language.find_by_alias('rust,no_run')
|
||||
end
|
||||
|
||||
def test_doesnt_blow_up_with_blank_lookup
|
||||
assert_equal nil, Language.find_by_alias('')
|
||||
assert_equal nil, Language.find_by_name(nil)
|
||||
assert_equal nil, Language[""]
|
||||
end
|
||||
|
||||
def test_name
|
||||
assert_equal 'Perl', Language['Perl'].name
|
||||
assert_equal 'Python', Language['Python'].name
|
||||
|
||||
@@ -9,6 +9,8 @@ class TestModelines < Minitest::Test
|
||||
|
||||
def test_modeline_strategy
|
||||
assert_modeline Language["Ruby"], fixture_blob("Data/Modelines/ruby")
|
||||
assert_modeline Language["Ruby"], fixture_blob("Data/Modelines/ruby2")
|
||||
assert_modeline Language["Ruby"], fixture_blob("Data/Modelines/ruby3")
|
||||
assert_modeline Language["C++"], fixture_blob("Data/Modelines/seeplusplus")
|
||||
assert_modeline Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs1")
|
||||
assert_modeline Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs2")
|
||||
@@ -27,6 +29,8 @@ class TestModelines < Minitest::Test
|
||||
|
||||
def test_modeline_languages
|
||||
assert_equal Language["Ruby"], fixture_blob("Data/Modelines/ruby").language
|
||||
assert_equal Language["Ruby"], fixture_blob("Data/Modelines/ruby2").language
|
||||
assert_equal Language["Ruby"], fixture_blob("Data/Modelines/ruby3").language
|
||||
assert_equal Language["C++"], fixture_blob("Data/Modelines/seeplusplus").language
|
||||
assert_equal Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs1").language
|
||||
assert_equal Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs2").language
|
||||
|
||||
@@ -25,6 +25,10 @@ class TestTokenizer < Minitest::Test
|
||||
assert_equal %w(add \( \)), tokenize('add(123, 456)')
|
||||
assert_equal %w(|), tokenize('0x01 | 0x10')
|
||||
assert_equal %w(*), tokenize('500.42 * 1.0')
|
||||
assert_equal %w(), tokenize('1.23e-04')
|
||||
assert_equal %w(), tokenize('1.0f')
|
||||
assert_equal %w(), tokenize('1234ULL')
|
||||
assert_equal %w(G1 X55 Y5 F2000), tokenize('G1 X55 Y5 F2000')
|
||||
end
|
||||
|
||||
def test_skip_comments
|
||||
|
||||
Reference in New Issue
Block a user