diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 007f5622..200e83f2 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -19,6 +19,9 @@ module Linguist if languages.all? { |l| ["Perl", "Prolog"].include?(l) } disambiguate_pl(data, languages) end + if languages.all? { |l| ["TypeScript", "XML"].include?(l) } + disambiguate_ts(data, languages) + end end end @@ -40,6 +43,16 @@ module Linguist matches end + def self.disambiguate_ts(data, languages) + matches = [] + if (data.include?("")) + matches << Language["XML"] + else + matches << Language["TypeScript"] + end + matches + end + def self.active? !!ACTIVE end diff --git a/samples/XML/pt_BR.xml b/samples/XML/pt_BR.xml new file mode 100644 index 00000000..bfaf0015 --- /dev/null +++ b/samples/XML/pt_BR.xml @@ -0,0 +1,47 @@ + + + + + MainWindow + + + United Kingdom + Reino Unido + + + + God save the Queen + Deus salve a Rainha + + + + England + Inglaterra + + + + Wales + Gales + + + + Scotland + Escócia + + + + Northern Ireland + Irlanda Norte + + + + Portuguese + Português + + + + English + Inglês + + + diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index a7847173..148f49c5 100644 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -50,4 +50,16 @@ class TestHeuristcs < Test::Unit::TestCase results = Heuristics.disambiguate_pl(fixture("Perl/perl-test.t"), languages) assert_equal Language["Perl"], results.first end + + def test_ts_typescript_by_heuristics + languages = ["TypeScript", "XML"] + results = Heuristics.disambiguate_ts(fixture("TypeScript/classes.ts"), languages) + assert_equal Language["TypeScript"], results.first + end + + def test_ts_xml_by_heuristics + languages = ["TypeScript", "XML"] + results = Heuristics.disambiguate_ts(fixture("XML/pt_BR.xml"), languages) + assert_equal Language["XML"], results.first + end end