Skip to content

Commit 4f87502

Browse files
authored
Merge pull request #80 from DannyBen/fix/string-wrap
Avoid wrapping uninterrupted strings
2 parents 6bb6d2f + cd18368 commit 4f87502

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/bashly/extensions/string.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def wrap(length = 80)
1616
strip!
1717
split("\n").collect! do |line|
1818
if line.length > length
19-
line.gsub!(/([^\s]{#{length}})([^\s$])/, "\\1 \\2")
2019
line.gsub(/(.{1,#{length}})(\s+|$)/, "\\1\n").rstrip
2120
else
2221
line

spec/bashly/extensions/string_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@
2020
it "wraps the string to the specified length" do
2121
expect(subject.wrap 30).to eq "a long line of text that is\ngoing to be wrapped, fingers\ncrossed!"
2222
end
23-
end
2423

24+
# GH-79
25+
context "with an uninterrupted string" do
26+
subject { "a long line of text with a nice uninterrupted-string-like-a-url-for-example" }
27+
it "does not break the uninterrupted portion" do
28+
expect(subject.wrap 30).to eq "a long line of text with a\nnice\nuninterrupted-string-like-a-url-for-example"
29+
end
30+
end
31+
end
2532

2633
describe '#to_underscore' do
2734
subject { "Some String" }

0 commit comments

Comments
 (0)