From c8761d39d759610f21d4dc207f1191567e1472c7 Mon Sep 17 00:00:00 2001 From: Ted Nyman Date: Sun, 22 Dec 2013 15:25:56 -0800 Subject: [PATCH] Narrow test and set ACTIVE flag for heuristics --- lib/linguist/heuristics.rb | 12 ++++++++++-- test/test_heuristics.rb | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 01e12e78..adb0eec4 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -1,6 +1,8 @@ module Linguist # A collection of simple heuristics that can be used to better analyze languages. class Heuristics + ACTIVE = false + # Public: Given an array of String language names, # apply heuristics against the given data and return an array # of matching languages, or nil. @@ -10,8 +12,10 @@ module Linguist # # Returns an array of Languages or [] def self.find_by_heuristics(data, languages) - if languages.all? { |l| ["Objective-C", "C++"].include?(l) } - disambiguate_h(data, languages) + if active? + if languages.all? { |l| ["Objective-C", "C++"].include?(l) } + disambiguate_h(data, languages) + end end end @@ -24,5 +28,9 @@ module Linguist matches << Language["Objective-C"] if data.include?("@interface") matches end + + def self.active? + !!ACTIVE + end end end diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index e499cf7e..07a7565f 100644 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -14,7 +14,7 @@ class TestHeuristcs < Test::Unit::TestCase def fixture(name) File.read(File.join(samples_path, name)) end - + # Only calling out '.h' filenames as these are the ones causing issues def all_h_fixtures(language_name) Dir.glob("#{samples_path}/#{language_name}/*.h") @@ -23,7 +23,7 @@ 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.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 end end