Permalink
Browse files

Refactored misspelling output from #generate into #suggestion_text

  • Loading branch information...
1 parent e92ba75 commit a4b2790f100c6b5db5dbc0630623db13dcc82859 @drbrain drbrain committed Apr 5, 2012
Showing with 28 additions and 17 deletions.
  1. +17 −13 lib/rdoc/generator/spellcheck.rb
  2. +11 −4 test/test_rdoc_generator_spellcheck.rb
View
30 lib/rdoc/generator/spellcheck.rb
@@ -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
View
15 test/test_rdoc_generator_spellcheck.rb
@@ -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
@@ -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
@@ -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
@@ -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:

0 comments on commit a4b2790

Please sign in to comment.