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

« back to all changes in this revision

Viewing changes to qed/core/string/unindent.rdoc

  • Committer: Package Import Robot
  • Author(s): Marc Dequènes (Duck)
  • Date: 2012-01-03 03:35:44 UTC
  • Revision ID: package-import@ubuntu.com-20120103033544-pq0yyio1675gfgw6
Tags: upstream-2.9.2
Import upstream version 2.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
== String#unindent
 
2
 
 
3
  require 'facets/string/unindent'
 
4
 
 
5
We will use these two strings as a common basis for demonstration.
 
6
 
 
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
 
12
  EOF
 
13
 
 
14
  ex2 = <<-EOF.gsub(/^\s*\|/,'')
 
15
  |     "Eek!"
 
16
  |  She cried
 
17
  |    As the mouse quietly scurried
 
18
  |by.
 
19
  EOF
 
20
 
 
21
simple examples
 
22
 
 
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"
 
29
 
 
30
large example unindented one space
 
31
 
 
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
 
37
  EOF
 
38
 
 
39
  actual = ex1.unindent(1)
 
40
  actual.assert == expected
 
41
 
 
42
large example unindented four spaces
 
43
 
 
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
 
49
  EOF
 
50
 
 
51
  actual = ex1.unindent(4)
 
52
  actual.assert == expected
 
53
 
 
54
unindent larger than current indention
 
55
 
 
56
  expected = <<-EOF.gsub(/^\s*\|/,'')
 
57
  |"Eek!"
 
58
  |She cried
 
59
  |As the mouse quietly scurried
 
60
  |by.
 
61
  EOF
 
62
 
 
63
  actual = ex2.unindent(100)
 
64
  actual.assert == expected
 
65