Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Gem::Text#format_text now strips trailing whitespace

  • Loading branch information...
commit e8600995785f3e3a8ea4b1455972c063d4b9dd13 1 parent fb6753d
@drbrain drbrain authored
Showing with 16 additions and 1 deletion.
  1. +1 −1  lib/rubygems/text.rb
  2. +15 −0 test/rubygems/test_gem_text.rb
View
2  lib/rubygems/text.rb
@@ -15,7 +15,7 @@ def format_text(text, wrap, indent=0)
while work.length > wrap do
if work =~ /^(.{0,#{wrap}})[ \n]/ then
- result << $1
+ result << $1.rstrip
work.slice!(0, $&.length)
else
result << work.slice!(0, wrap)
View
15 test/rubygems/test_gem_text.rb
@@ -20,6 +20,21 @@ def test_format_text_none_indent
assert_equal " text to wrap", format_text("text to wrap", 40, 2)
end
+ def test_format_text_trailing # for two spaces after .
+ text = <<-TEXT
+This line is really, really long. So long, in fact, that it is more than eighty characters long! The purpose of this line is for testing wrapping behavior because sometimes people don't wrap their text to eighty characters. Without the wrapping, the text might not look good in the RSS feed.
+ TEXT
+
+ expected = <<-EXPECTED
+This line is really, really long. So long, in fact, that it is more than
+eighty characters long! The purpose of this line is for testing wrapping
+behavior because sometimes people don't wrap their text to eighty characters.
+Without the wrapping, the text might not look good in the RSS feed.
+ EXPECTED
+
+ assert_equal expected, format_text(text, 78)
+ end
+
def test_levenshtein_distance_add
assert_equal 2, levenshtein_distance("zentest", "zntst")
assert_equal 2, levenshtein_distance("zntst", "zentest")
Please sign in to comment.
Something went wrong with that request. Please try again.