Merge pull request #1639 from pchaigno/asc

Heuristic rule to detect AsciiDoc files
This commit is contained in:
Arfon Smith
2014-11-01 09:26:49 -05:00
2 changed files with 15 additions and 0 deletions

View File

@@ -25,6 +25,9 @@ module Linguist
if languages.all? { |l| ["Common Lisp", "OpenCL"].include?(l) }
result = disambiguate_cl(data, languages)
end
if languages.all? { |l| ["AsciiDoc", "AGS Script"].include?(l) }
result = disambiguate_asc(data, languages)
end
return result
end
end
@@ -88,6 +91,12 @@ module Linguist
matches
end
def self.disambiguate_asc(data, languages)
matches = []
matches << Language["AsciiDoc"] if /^=+(\s|\n)/.match(data)
matches
end
def self.active?
!!ACTIVE
end

View File

@@ -77,6 +77,12 @@ class TestHeuristcs < Test::Unit::TestCase
assert_equal Language["IDL"], results.first
end
def test_asc_asciidoc_by_heuristics
languages = ["AGS Script", "AsciiDoc"]
results = Heuristics.disambiguate_asc(fixture("AsciiDoc/list.asc"), languages)
assert_equal Language["AsciiDoc"], results.first
end
def test_ts_typescript_by_heuristics
languages = ["TypeScript", "XML"]
results = Heuristics.disambiguate_ts(fixture("TypeScript/classes.ts"), languages)