Skip to content

Commit

Permalink
Refactored misspelling output from #generate into #suggestion_text
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Apr 5, 2012
1 parent e92ba75 commit a4b2790
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
30 changes: 17 additions & 13 deletions lib/rdoc/generator/spellcheck.rb
Expand Up @@ -90,23 +90,27 @@ def generate files
puts "#{mod.definition} in #{location.full_name}:"
puts
misspelled.each do |word, offset|
comment.text =~ /.{#{offset - 10}}(.{0,10})#{Regexp.escape word}(.{0,10})/
puts suggestion_text(comment.text, word, offset)
end
end
end
end

before = $1
after = $2
underline = word.chars.map { |char| "_\b#{char}" }.join
def suggestion_text text, word, offset
text =~ /.{#{offset - 10}}(.{0,10})#{Regexp.escape word}(.{0,10})/

puts "\"...#{$1}#{underline}#{$2}...\""
puts
before = $1
after = $2
underline = word.chars.map { |char| "_\b#{char}" }.join
suggestions = @spell.suggest(word).first 5

suggestions = @spell.suggest(word).first 5
<<-TEXT
"...#{before}#{underline}#{after}..."
puts "\"#{word}\" suggestions:"
puts "\t#{suggestions.join ', '}"
puts
end
end
end
"#{word}" suggestions:
\t#{suggestions.join ', '}
TEXT
end

end
Expand Down
15 changes: 11 additions & 4 deletions test/test_rdoc_generator_spellcheck.rb
Expand Up @@ -16,6 +16,8 @@ def setup
@options.spell_language = 'en_US'

@sc = @SC.new @options

@text = 'Hello, this class has real gud spelling!'
end

def test_class_setup_options_default
Expand All @@ -42,7 +44,7 @@ def test_class_setup_options_spell_language
end

def test_find_misspelled
c = comment 'Hello, this class has real gud spelling!'
c = comment @text

report = @sc.find_misspelled c

Expand All @@ -55,7 +57,7 @@ def test_find_misspelled
def test_generate
klass = @top_level.add_class RDoc::NormalClass, 'Object'

c = comment 'Hello, this class has real gud spelling!'
c = comment @text
klass.add_comment c, @top_level

out, err = capture_io do
Expand All @@ -64,11 +66,16 @@ def test_generate

assert_empty err

assert_match %r%^class Object in file\.rb:%, out
assert_match %r%^"gud"%, out
end

def test_suggestion_text
out = @sc.suggestion_text @text, 'gud', 28

suggestions = suggest('gud').join ', '

expected = <<-EXPECTED
class Object in file.rb:
"...has real _\bg_\bu_\bd spelling!..."
"gud" suggestions:
Expand Down

0 comments on commit a4b2790

Please sign in to comment.