Narrow test and set ACTIVE flag for heuristics

This commit is contained in:
Ted Nyman
2013-12-22 15:25:56 -08:00
parent 51195290b8
commit c8761d39d7
2 changed files with 12 additions and 4 deletions

View File

@@ -1,6 +1,8 @@
module Linguist module Linguist
# A collection of simple heuristics that can be used to better analyze languages. # A collection of simple heuristics that can be used to better analyze languages.
class Heuristics class Heuristics
ACTIVE = false
# Public: Given an array of String language names, # Public: Given an array of String language names,
# apply heuristics against the given data and return an array # apply heuristics against the given data and return an array
# of matching languages, or nil. # of matching languages, or nil.
@@ -10,8 +12,10 @@ module Linguist
# #
# Returns an array of Languages or [] # Returns an array of Languages or []
def self.find_by_heuristics(data, languages) def self.find_by_heuristics(data, languages)
if languages.all? { |l| ["Objective-C", "C++"].include?(l) } if active?
disambiguate_h(data, languages) if languages.all? { |l| ["Objective-C", "C++"].include?(l) }
disambiguate_h(data, languages)
end
end end
end end
@@ -24,5 +28,9 @@ module Linguist
matches << Language["Objective-C"] if data.include?("@interface") matches << Language["Objective-C"] if data.include?("@interface")
matches matches
end end
def self.active?
!!ACTIVE
end
end end
end end

View File

@@ -23,7 +23,7 @@ class TestHeuristcs < Test::Unit::TestCase
def test_obj_c_by_heuristics def test_obj_c_by_heuristics
languages = ["C++", "Objective-C"] languages = ["C++", "Objective-C"]
all_h_fixtures("Objective-C").each do |fixture| all_h_fixtures("Objective-C").each do |fixture|
results = Heuristics.find_by_heuristics(fixture("Objective-C/#{File.basename(fixture)}"), languages) results = Heuristics.disambiguate_h(fixture("Objective-C/#{File.basename(fixture)}"), languages)
assert_equal Language["Objective-C"], results.first assert_equal Language["Objective-C"], results.first
end end
end end