diff --git a/lib/gingerice/parser.rb b/lib/gingerice/parser.rb index 209bdad..9f97809 100644 --- a/lib/gingerice/parser.rb +++ b/lib/gingerice/parser.rb @@ -91,22 +91,24 @@ def process_suggestions(i, data) to = data['To'] if i <= from - @result += text[i..from-1] unless from.zero? - @result += data['Suggestions'][0]['Text'] - - definition = data['Suggestions'][0]['Definition'] - - if definition.respond_to? :empty? - definition = nil if definition.empty? + @result += text[i..from-1] unless from.zero? + suggestion = data['Suggestions'].first + + if suggestion + suggestion_text = suggestion['Text'] + @result += suggestion_text + + definition = suggestion['Definition'] + definition = nil if definition.respond_to?(:empty?) && definition.empty? + + @corrections << { + 'text' => text[from..to], + 'correct' => suggestion_text, + 'definition' => definition, + 'start' => from, + 'length' => to - from + 1 + } end - - @corrections << { - 'text' => text[from..to], - 'correct' => data['Suggestions'][0]['Text'], - 'definition' => definition, - 'start' => from, - 'length' => to - from + 1 - } end end diff --git a/test/test_gingerice.rb b/test/test_gingerice.rb index 3a1e3b7..46a6c4c 100644 --- a/test/test_gingerice.rb +++ b/test/test_gingerice.rb @@ -69,6 +69,14 @@ def test_command_simple_output assert_equal "Edwards was sick yesterday\n", output.string end + def test_command_simple_output_cryptic + output = capture_stdout do + command = Gingerice::Command.new([":tco"]) + command.execute + end + assert_equal ": \n", output.string + end + def test_command_verbose_output output = capture_stdout do command = Gingerice::Command.new(["-v", "He flyed to Jakarta"])