mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
Return early in Classifier.classify if no languages supplied (#3471)
* Return early if no languages supplied There's no need to tokenise the data when attempting to classify without a limited language scope as no action will be performed when it comes to scoring anyway. * Add test for empty languages array
This commit is contained in:
@@ -95,7 +95,7 @@ module Linguist
|
||||
# Returns sorted Array of result pairs. Each pair contains the
|
||||
# String language name and a Float score.
|
||||
def classify(tokens, languages)
|
||||
return [] if tokens.nil?
|
||||
return [] if tokens.nil? || languages.empty?
|
||||
tokens = Tokenizer.tokenize(tokens) if tokens.is_a?(String)
|
||||
scores = {}
|
||||
|
||||
|
||||
@@ -53,4 +53,8 @@ class TestClassifier < Minitest::Test
|
||||
assert_equal language.name, results.first[0], "#{sample[:path]}\n#{results.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
def test_classify_empty_languages
|
||||
assert_equal [], Classifier.classify(Samples.cache, fixture("Ruby/foo.rb"), [])
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user