~ubuntu-branches/ubuntu/trusty/ruby-facets/trusty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
== String#unindent

  require 'facets/string/unindent'

We will use these two strings as a common basis for demonstration.

  ex1 = <<-EOF.gsub(/^\s*\|/,'')
  |    I must go down to the seas again
  |      The lonely sea and the sky
  |    And all I want is a tall ship
  |      And a star to steer her by
  EOF

  ex2 = <<-EOF.gsub(/^\s*\|/,'')
  |     "Eek!"
  |  She cried
  |    As the mouse quietly scurried
  |by.
  EOF

simple examples

  "   xyz".unindent(-1).assert == "    xyz"
  "   xyz".unindent(0).assert  == "   xyz"
  "   xyz".unindent(1).assert  == "  xyz"
  "   xyz".unindent(2).assert  == " xyz"
  "   xyz".unindent(3).assert  == "xyz"
  "   xyz".unindent(4).assert  == "xyz"

large example unindented one space

  expected = <<-EOF.gsub(/^\s*\|/,'')
  |   I must go down to the seas again
  |     The lonely sea and the sky
  |   And all I want is a tall ship
  |     And a star to steer her by
  EOF

  actual = ex1.unindent(1)
  actual.assert == expected

large example unindented four spaces

  expected = <<-EOF.gsub(/^\s*\|/,'')
  |I must go down to the seas again
  |  The lonely sea and the sky
  |And all I want is a tall ship
  |  And a star to steer her by
  EOF

  actual = ex1.unindent(4)
  actual.assert == expected

unindent larger than current indention

  expected = <<-EOF.gsub(/^\s*\|/,'')
  |"Eek!"
  |She cried
  |As the mouse quietly scurried
  |by.
  EOF

  actual = ex2.unindent(100)
  actual.assert == expected