Skip to content
This repository has been archived by the owner on May 1, 2021. It is now read-only.

Commit

Permalink
fix parsing empty suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
subosito committed Jan 22, 2014
1 parent 9b8c7a0 commit 0e069c8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lib/gingerice/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions test/test_gingerice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit 0e069c8

Please sign in to comment.