diff options
| author | Joshua Peek <josh@joshpeek.com> | 2012-06-21 11:47:32 -0500 |
|---|---|---|
| committer | Joshua Peek <josh@joshpeek.com> | 2012-06-21 11:47:32 -0500 |
| commit | 2b712dc79082687c678f8b5d43b3f836b7c53753 (patch) | |
| tree | cd0e8f87350d5a8fc6c8682cb2debc077a29b26d | |
| parent | 3d7364877d6794f6cc2a86b493e893968a597332 (diff) | |
Guard against classify nil data
| -rw-r--r-- | lib/linguist/classifier.rb | 1 | ||||
| -rw-r--r-- | test/test_classifier.rb | 4 |
2 files changed, 5 insertions, 0 deletions
diff --git a/lib/linguist/classifier.rb b/lib/linguist/classifier.rb index dd3fe04..30fb7c4 100644 --- a/lib/linguist/classifier.rb +++ b/lib/linguist/classifier.rb @@ -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 = {} diff --git a/test/test_classifier.rb b/test/test_classifier.rb index b39fb20..508aa08 100644 --- a/test/test_classifier.rb +++ b/test/test_classifier.rb @@ -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 |
