3
require 'facets/string/unindent'
5
We will use these two strings as a common basis for demonstration.
7
ex1 = <<-EOF.gsub(/^\s*\|/,'')
8
| I must go down to the seas again
9
| The lonely sea and the sky
10
| And all I want is a tall ship
11
| And a star to steer her by
14
ex2 = <<-EOF.gsub(/^\s*\|/,'')
17
| As the mouse quietly scurried
23
" xyz".unindent(-1).assert == " xyz"
24
" xyz".unindent(0).assert == " xyz"
25
" xyz".unindent(1).assert == " xyz"
26
" xyz".unindent(2).assert == " xyz"
27
" xyz".unindent(3).assert == "xyz"
28
" xyz".unindent(4).assert == "xyz"
30
large example unindented one space
32
expected = <<-EOF.gsub(/^\s*\|/,'')
33
| I must go down to the seas again
34
| The lonely sea and the sky
35
| And all I want is a tall ship
36
| And a star to steer her by
39
actual = ex1.unindent(1)
40
actual.assert == expected
42
large example unindented four spaces
44
expected = <<-EOF.gsub(/^\s*\|/,'')
45
|I must go down to the seas again
46
| The lonely sea and the sky
47
|And all I want is a tall ship
48
| And a star to steer her by
51
actual = ex1.unindent(4)
52
actual.assert == expected
54
unindent larger than current indention
56
expected = <<-EOF.gsub(/^\s*\|/,'')
59
|As the mouse quietly scurried
63
actual = ex2.unindent(100)
64
actual.assert == expected