mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Start towards pl heuristics
This commit is contained in:
@@ -14,7 +14,10 @@ module Linguist
|
||||
def self.find_by_heuristics(data, languages)
|
||||
if active?
|
||||
if languages.all? { |l| ["Objective-C", "C++"].include?(l) }
|
||||
disambiguate_h(data, languages)
|
||||
disambiguate_c(data, languages)
|
||||
end
|
||||
if languages.all? { |l| ["Perl", "Prolog"].include?(l) }
|
||||
disambiguate_pl(data, languages)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -23,14 +26,19 @@ module Linguist
|
||||
# We want to shortcut look for Objective-C _and_ now C++ too!
|
||||
#
|
||||
# Returns an array of Languages or []
|
||||
# TODO rename this method as we're not strictly disambiguating between .h files here.
|
||||
def self.disambiguate_h(data, languages)
|
||||
def self.disambiguate_c(data, languages)
|
||||
matches = []
|
||||
matches << Language["Objective-C"] if data.include?("@interface")
|
||||
matches << Language["C++"] if data.include?("#include <cstdint>")
|
||||
matches
|
||||
end
|
||||
|
||||
def self_disambiguate_pl(data, languages)
|
||||
matches = []
|
||||
matches << Language["Prolog"] if data.include?(":-")
|
||||
matches
|
||||
end
|
||||
|
||||
def self.active?
|
||||
!!ACTIVE
|
||||
end
|
||||
|
||||
@@ -23,14 +23,14 @@ class TestHeuristcs < Test::Unit::TestCase
|
||||
def test_obj_c_by_heuristics
|
||||
languages = ["C++", "Objective-C"]
|
||||
all_h_fixtures("Objective-C").each do |fixture|
|
||||
results = Heuristics.disambiguate_h(fixture("Objective-C/#{File.basename(fixture)}"), languages)
|
||||
results = Heuristics.disambiguate_c(fixture("Objective-C/#{File.basename(fixture)}"), languages)
|
||||
assert_equal Language["Objective-C"], results.first
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_cpp_by_heuristics
|
||||
languages = ["C++", "Objective-C"]
|
||||
results = Heuristics.disambiguate_h(fixture("C++/render_adapter.cpp"), languages)
|
||||
results = Heuristics.disambiguate_c(fixture("C++/render_adapter.cpp"), languages)
|
||||
assert_equal Language["C++"], results.first
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user