mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-08 20:38:47 +00:00
Fix test for Perl heuristic
Improve heuristic rule for Perl6 Separate heuristic rules for .pl (with Prolog) and .pm (without Prolog)
This commit is contained in:
@@ -93,15 +93,23 @@ module Linguist
|
|||||||
end
|
end
|
||||||
|
|
||||||
disambiguate ".pl" do |data|
|
disambiguate ".pl" do |data|
|
||||||
if data.include?("use v6")
|
if /^(use v6|(my )?class|module)/.match(data)
|
||||||
Language["Perl6"]
|
Language["Perl6"]
|
||||||
elsif data.match(/use strict|use\s+v?5\./)
|
elsif /use strict|use\s+v?5\./.match(data)
|
||||||
Language["Perl"]
|
Language["Perl"]
|
||||||
elsif /^[^#]+:-/.match(data)
|
elsif /^[^#]+:-/.match(data)
|
||||||
Language["Prolog"]
|
Language["Prolog"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
disambiguate ".pm" do |data|
|
||||||
|
if /^(use v6|(my )?class|module)/.match(data)
|
||||||
|
Language["Perl6"]
|
||||||
|
elsif /use strict|use\s+v?5\./.match(data)
|
||||||
|
Language["Perl"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
disambiguate ".ecl" do |data|
|
disambiguate ".ecl" do |data|
|
||||||
if /^[^#]+:-/.match(data)
|
if /^[^#]+:-/.match(data)
|
||||||
Language["Prolog"]
|
Language["Prolog"]
|
||||||
|
|||||||
@@ -49,15 +49,23 @@ class TestHeuristcs < Minitest::Test
|
|||||||
assert_equal Language["Objective-C"], match
|
assert_equal Language["Objective-C"], match
|
||||||
end
|
end
|
||||||
|
|
||||||
# Candidate languages = ["Perl", "Prolog"]
|
# Candidate languages = ["Perl", "Perl6", "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/oo1.pl", "Perl/oo2.pl", "Perl/oo3.pl", "Perl/fib.pl", "Perl/use5.pl"],
|
||||||
"Perl6" => all_fixtures("Perl6", "*.pl")
|
"Perl6" => all_fixtures("Perl6", "*.pl")
|
||||||
})
|
})
|
||||||
end
|
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"]
|
# Candidate languages = ["ECL", "Prolog"]
|
||||||
def test_ecl_prolog_by_heuristics
|
def test_ecl_prolog_by_heuristics
|
||||||
assert_heuristics({
|
assert_heuristics({
|
||||||
|
|||||||
Reference in New Issue
Block a user