mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-08 20:38:47 +00:00
Fix tests to use the correct extension in heuristic rules
Extand a few tests where only one file was tested for a language
This commit is contained in:
@@ -22,22 +22,27 @@ class TestHeuristcs < Minitest::Test
|
|||||||
assert_equal [], results
|
assert_equal [], results
|
||||||
end
|
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"]
|
# Candidate languages = ["C++", "Objective-C"]
|
||||||
def test_obj_c_by_heuristics
|
def test_obj_c_by_heuristics
|
||||||
# Only calling out '.h' filenames as these are the ones causing issues
|
# Only calling out '.h' filenames as these are the ones causing issues
|
||||||
assert_heuristics({
|
assert_heuristics({
|
||||||
"Objective-C" => all_fixtures("Objective-C", "*.h"),
|
"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
|
"C" => nil
|
||||||
})
|
})
|
||||||
end
|
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
|
def test_detect_still_works_if_nothing_matches
|
||||||
blob = Linguist::FileBlob.new(File.join(samples_path, "Objective-C/hello.m"))
|
blob = Linguist::FileBlob.new(File.join(samples_path, "Objective-C/hello.m"))
|
||||||
match = Language.detect(blob)
|
match = Language.detect(blob)
|
||||||
@@ -47,17 +52,17 @@ class TestHeuristcs < Minitest::Test
|
|||||||
# Candidate languages = ["Perl", "Prolog"]
|
# Candidate languages = ["Perl", "Prolog"]
|
||||||
def test_pl_prolog_perl_by_heuristics
|
def test_pl_prolog_perl_by_heuristics
|
||||||
assert_heuristics({
|
assert_heuristics({
|
||||||
"Prolog" => all_fixtures("Prolog/*.pl"),
|
"Prolog" => all_fixtures("Prolog", "*.pl"),
|
||||||
"Perl" => all_fixtures("Perl/*.pl") + ["Perl/perl-test.t"],
|
"Perl" => all_fixtures("Perl", "*.pl"),
|
||||||
"Perl6" => all_fixtures("Perl6/*.pl")
|
"Perl6" => all_fixtures("Perl6", "*.pl")
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
# Candidate languages = ["ECL", "Prolog"]
|
# Candidate languages = ["ECL", "Prolog"]
|
||||||
def test_ecl_prolog_by_heuristics
|
def test_ecl_prolog_by_heuristics
|
||||||
assert_heuristics({
|
assert_heuristics({
|
||||||
"ECL" => "ECL/sample.ecl",
|
"ECL" => all_fixtures("ECL", "*.ecl"),
|
||||||
"Prolog" => "Prolog/or-constraint.ecl"
|
"Prolog" => all_fixtures("Prolog", "*.ecl")
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -74,69 +79,69 @@ class TestHeuristcs < Minitest::Test
|
|||||||
# Candidate languages = ["AGS Script", "AsciiDoc", "Public Key"]
|
# Candidate languages = ["AGS Script", "AsciiDoc", "Public Key"]
|
||||||
def test_asc_by_heuristics
|
def test_asc_by_heuristics
|
||||||
assert_heuristics({
|
assert_heuristics({
|
||||||
"AsciiDoc" => "AsciiDoc/list.asc",
|
"AsciiDoc" => all_fixtures("AsciiDoc", "*.asc"),
|
||||||
"AGS Script" => "AGS Script/GlobalScript.asc",
|
"AGS Script" => all_fixtures("AGS Script", "*.asc"),
|
||||||
"Public Key" => all_fixtures("Public Key", "*.asc")
|
"Public Key" => all_fixtures("Public Key", "*.asc")
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cl_by_heuristics
|
def test_cl_by_heuristics
|
||||||
assert_heuristics({
|
assert_heuristics({
|
||||||
"Common Lisp" => all_fixtures("Common Lisp"),
|
"Common Lisp" => all_fixtures("Common Lisp", "*.cl"),
|
||||||
"OpenCL" => all_fixtures("OpenCL")
|
"OpenCL" => all_fixtures("OpenCL", "*.cl")
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_f_by_heuristics
|
def test_f_by_heuristics
|
||||||
assert_heuristics({
|
assert_heuristics({
|
||||||
"FORTRAN" => all_fixtures("FORTRAN"),
|
"FORTRAN" => all_fixtures("FORTRAN", "*.f") + all_fixtures("FORTRAN", "*.for"),
|
||||||
"Forth" => all_fixtures("Forth")
|
"Forth" => all_fixtures("Forth", "*.f") + all_fixtures("Forth", "*.for")
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
# Candidate languages = ["Hack", "PHP"]
|
# Candidate languages = ["Hack", "PHP"]
|
||||||
def test_hack_by_heuristics
|
def test_hack_by_heuristics
|
||||||
assert_heuristics({
|
assert_heuristics({
|
||||||
"Hack" => "Hack/funs.php",
|
"Hack" => all_fixtures("Hack", "*.php"),
|
||||||
"PHP" => "PHP/Model.php"
|
"PHP" => all_fixtures("PHP", "*.php")
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
# Candidate languages = ["Scala", "SuperCollider"]
|
# Candidate languages = ["Scala", "SuperCollider"]
|
||||||
def test_sc_supercollider_scala_by_heuristics
|
def test_sc_supercollider_scala_by_heuristics
|
||||||
assert_heuristics({
|
assert_heuristics({
|
||||||
"SuperCollider" => "SuperCollider/WarpPreset.sc",
|
"SuperCollider" => all_fixtures("SuperCollider", "*.sc"),
|
||||||
"Scala" => "Scala/node11.sc"
|
"Scala" => all_fixtures("Scala", "*.sc")
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_fs_by_heuristics
|
def test_fs_by_heuristics
|
||||||
assert_heuristics({
|
assert_heuristics({
|
||||||
"F#" => all_fixtures("F#"),
|
"F#" => all_fixtures("F#", "*.fs"),
|
||||||
"Forth" => all_fixtures("Forth"),
|
"Forth" => all_fixtures("Forth", "*.fs"),
|
||||||
"GLSL" => all_fixtures("GLSL")
|
"GLSL" => all_fixtures("GLSL", "*.fs")
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_fr_by_heuristics
|
def test_fr_by_heuristics
|
||||||
assert_heuristics({
|
assert_heuristics({
|
||||||
"Frege" => all_fixtures("Frege"),
|
"Frege" => all_fixtures("Frege", "*.fr"),
|
||||||
"Forth" => all_fixtures("Forth"),
|
"Forth" => all_fixtures("Forth", "*.fr"),
|
||||||
"Text" => all_fixtures("Text")
|
"Text" => all_fixtures("Text", "*.fr")
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_bb_by_heuristics
|
def test_bb_by_heuristics
|
||||||
assert_heuristics({
|
assert_heuristics({
|
||||||
"BitBake" => all_fixtures("BitBake"),
|
"BitBake" => all_fixtures("BitBake", "*.bb"),
|
||||||
"BlitzBasic" => all_fixtures("BlitzBasic")
|
"BlitzBasic" => all_fixtures("BlitzBasic", "*.bb")
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_lsp_by_heuristics
|
def test_lsp_by_heuristics
|
||||||
assert_heuristics({
|
assert_heuristics({
|
||||||
"Common Lisp" => all_fixtures("Common Lisp"),
|
"Common Lisp" => all_fixtures("Common Lisp", "*.lsp") + all_fixtures("Common Lisp", "*.lisp"),
|
||||||
"NewLisp" => all_fixtures("NewLisp")
|
"NewLisp" => all_fixtures("NewLisp", "*.lsp") + all_fixtures("NewLisp", "*.lisp")
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -147,21 +152,10 @@ class TestHeuristcs < Minitest::Test
|
|||||||
})
|
})
|
||||||
end
|
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
|
def test_ls_by_heuristics
|
||||||
assert_heuristics({
|
assert_heuristics({
|
||||||
"LiveScript" => "LiveScript/hello.ls",
|
"LiveScript" => all_fixtures("LiveScript", "*.ls"),
|
||||||
"LoomScript" => "LoomScript/HelloWorld.ls"
|
"LoomScript" => all_fixtures("LoomScript", "*.ls")
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user