Add tests for Perl and Turning detection

This commit is contained in:
Joshua Peek
2011-11-21 10:42:39 -06:00
parent 0b5a265644
commit e4fe1d17e7
5 changed files with 48 additions and 4 deletions

View File

@@ -470,12 +470,20 @@ module Linguist
# Internal: Guess language of .t files.
#
# Makes fairly sure that it is Turing.
# Turing is not very popular so it would not be good to have perl users' files being confused.
#
# Returns a Language.
def guess_t_language
if lines.grep(/:=/).any? && lines.grep(/proc |procedure |fcn |function /).any? && lines.grep(/var/).any?
score = 0
score += 1 if lines.grep(/^% /).any?
score += data.gsub(/ := /).count
score += data.gsub(/proc |procedure |fcn |function /).count
score += data.gsub(/var \w+: \w+/).count
# Tell-tale signs its gotta be Perl
if lines.grep(/^(my )?(sub |\$|@|%)\w+/).any?
score = 0
end
if score >= 3
Language['Turing']
else
Language['Perl']