From 3c6218f20eba8eec014160ec90a04adfa01f985f Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Sun, 4 Jan 2015 22:07:29 +0100 Subject: [PATCH] Heuristics for .cs files: Smalltalk and C# --- lib/linguist/heuristics.rb | 8 ++++++++ test/test_heuristics.rb | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 97c1015a..33df8958 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -69,6 +69,14 @@ module Linguist end end + disambiguate "C#", "Smalltalk" do |data| + if /![\w\s]+methodsFor: /.match(data) + Language["Smalltalk"] + elsif /^\s*namespace\s*[\w\.]+\s*{/.match(data) || /^\s*using\s*[\w\.]+\s*;/.match(data) + Language["C#"] + end + end + disambiguate "Objective-C", "C++", "C" do |data| if (/^[ \t]*@(interface|class|protocol|property|end|synchronised|selector|implementation)\b/.match(data)) Language["Objective-C"] diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index 7520e828..785fe58e 100644 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -133,6 +133,13 @@ class TestHeuristcs < Minitest::Test }) end + def test_cs_by_heuristics + assert_heuristics({ + "C#" => all_fixtures("C#", "*.cs"), + "Smalltalk" => all_fixtures("Smalltalk", "*.cs") + }) + end + def assert_heuristics(hash) candidates = hash.keys.map { |l| Language[l] }