Guard against classify nil data

This commit is contained in:
Joshua Peek
2012-06-21 11:47:32 -05:00
parent 3d7364877d
commit 2b712dc790
2 changed files with 5 additions and 0 deletions

View File

@@ -97,6 +97,7 @@ module Linguist
# Returns sorted Array of result pairs. Each pair contains the
# Language and a Float score.
def classify(tokens, languages = @languages.keys)
return [] if tokens.nil?
tokens = Tokenizer.new(tokens).tokens if tokens.is_a?(String)
scores = {}

View File

@@ -55,6 +55,10 @@ class TestClassifier < Test::Unit::TestCase
assert results.first[1] < 0.5, results.first.inspect
end
def test_instance_classify_nil
assert_equal [], Classifier.instance.classify(nil)
end
def test_verify
assert Classifier.instance.verify
end