tweak String#undent so that only leading whitespace up to the first indentation level is gsubbed, change test_undent to reflect change and add test_undent_nested to test new behavior
This commit is contained in:
parent
3b88c070c6
commit
b0d5e17906
@ -1,6 +1,6 @@
|
||||
class String
|
||||
def undent
|
||||
gsub(/^.{#{(slice(/^ +/) || '').length}}/, "")
|
||||
gsub(/^[ \t]{#{(slice(/^[ \t]+/) || '').length}}/, "")
|
||||
end
|
||||
|
||||
# eg:
|
||||
|
@ -8,7 +8,7 @@ class StringTest < Homebrew::TestCase
|
||||
....my friend over
|
||||
there
|
||||
EOS
|
||||
assert_equal "hi\nmy friend over\nthere\n", undented
|
||||
assert_equal "hi\n....my friend over\nthere\n", undented
|
||||
end
|
||||
|
||||
def test_undent_not_indented
|
||||
@ -18,4 +18,17 @@ I'm not indented
|
||||
EOS
|
||||
assert_equal "hi\nI'm not indented\n", undented
|
||||
end
|
||||
|
||||
def test_undent_nested
|
||||
nest = <<-EOS.undent
|
||||
goodbye
|
||||
EOS
|
||||
|
||||
undented = <<-EOS.undent
|
||||
hello
|
||||
#{nest}
|
||||
EOS
|
||||
|
||||
assert_equal "hello\ngoodbye\n\n", undented
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user