PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/test/core/string/test_tab.rb

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 234 lines | 191 code | 38 blank | 5 comment | 0 complexity | 6b8e166cba8254052093d6120626c3dc MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. require 'facets/string/tab'
  2. require 'test/unit'
  3. class TC_String_Tabs < Test::Unit::TestCase
  4. def setup
  5. @tabs = <<-EOF
  6. \tOne tab
  7. \tOne space and one tab
  8. \t Six spaces, a tab, and a space
  9. EOF
  10. @poem1 = <<-EOF
  11. I must go down to the seas again
  12. The lonely sea and the sky
  13. And all I want is a tall ship
  14. And a star to steer her by
  15. EOF
  16. @poem2 = <<-EOF
  17. "Eek!"
  18. She cried
  19. As the mouse quietly scurried
  20. by.
  21. EOF
  22. end # def setup
  23. def test_tab
  24. a = "xyz".tab(4)
  25. assert_equal( ' ', a[0..3] )
  26. # Need to expand on this
  27. end
  28. def test_expand_tabs_1
  29. expected = <<-EOF
  30. One tab
  31. One space and one tab
  32. Six spaces, a tab, and a space
  33. EOF
  34. assert_equal(expected, @tabs.expand_tabs)
  35. assert_equal(expected, @tabs.expand_tabs(8))
  36. end
  37. def test_expand_tabs_2
  38. expected = <<-EOF
  39. One tab
  40. One space and one tab
  41. Six spaces, a tab, and a space
  42. EOF
  43. assert_equal(expected, @tabs.expand_tabs(4))
  44. end
  45. def test_expand_tabs_3
  46. expected = <<-EOF
  47. One tab
  48. One space and one tab
  49. Six spaces, a tab, and a space
  50. EOF
  51. assert_equal(expected, @tabs.expand_tabs(16))
  52. end
  53. def test_expand_tabs_4
  54. expected = <<-EOF
  55. One tab
  56. One space and one tab
  57. Six spaces, a tab, and a space
  58. EOF
  59. assert_equal(expected, @tabs.expand_tabs(1))
  60. end
  61. def test_expand_tabs_5
  62. expected = <<-EOF
  63. One tab
  64. One space and one tab
  65. Six spaces, a tab, and a space
  66. EOF
  67. assert_equal(expected, @tabs.expand_tabs(0))
  68. end
  69. def test_tabto
  70. a = "xyz".tabto(4)
  71. assert_equal( ' ', a[0..3] )
  72. # Need to expand on this
  73. end
  74. def test_indent
  75. a = "xyz".indent(4)
  76. assert_equal( ' ', a[0..3] )
  77. # Need to expand on this
  78. end
  79. def test_outdent_0
  80. assert_equal(" xyz", " xyz".outdent(-1))
  81. assert_equal(" xyz", " xyz".outdent(0))
  82. assert_equal(" xyz", " xyz".outdent(1))
  83. assert_equal(" xyz", " xyz".outdent(2))
  84. assert_equal("xyz", " xyz".outdent(3))
  85. assert_equal("xyz", " xyz".outdent(4))
  86. end
  87. def test_outdent_1
  88. expected = <<-EOF
  89. I must go down to the seas again
  90. The lonely sea and the sky
  91. And all I want is a tall ship
  92. And a star to steer her by
  93. EOF
  94. actual = @poem1.outdent(1)
  95. assert_equal(expected, actual)
  96. end
  97. def test_outdent_2
  98. expected = <<-EOF
  99. I must go down to the seas again
  100. The lonely sea and the sky
  101. And all I want is a tall ship
  102. And a star to steer her by
  103. EOF
  104. actual = @poem1.outdent(4)
  105. assert_equal(expected, actual)
  106. end
  107. def test_outdent_3
  108. expected = <<-EOF
  109. "Eek!"
  110. She cried
  111. As the mouse quietly scurried
  112. by.
  113. EOF
  114. actual = @poem2.outdent(100)
  115. assert_equal(expected, actual)
  116. end
  117. def test_margin
  118. s = %q{
  119. |ABC
  120. |123
  121. |TEST
  122. }.margin
  123. assert_equal( "ABC\n123\nTEST", s )
  124. s = %q{
  125. |ABC
  126. |123
  127. |TEST
  128. }.margin
  129. assert_equal( "ABC\n123\nTEST", s )
  130. s = %q{|ABC
  131. |123
  132. |TEST
  133. }.margin
  134. assert_equal( "ABC\n123\nTEST", s )
  135. s = %q{
  136. |ABC
  137. |123
  138. |TEST}.margin
  139. assert_equal( "ABC\n123\nTEST", s )
  140. s = %q{|ABC
  141. |123
  142. |TEST}.margin
  143. assert_equal( "ABC\n123\nTEST", s )
  144. s = %q{ |ABC
  145. |123
  146. |TEST}.margin
  147. assert_equal( "ABC\n123\nTEST", s )
  148. s = %q{ABC
  149. |123
  150. |TEST
  151. }.margin
  152. assert_equal( "ABC\n123\nTEST", s )
  153. end
  154. #
  155. def test_spacing
  156. s = %q{
  157. | ABC
  158. | 123
  159. | TEST
  160. }.margin
  161. assert_equal( " ABC\n 123\n TEST", s )
  162. s = %q{
  163. |ABC
  164. |123
  165. |TEST
  166. }.margin(1)
  167. assert_equal( " ABC\n 123\n TEST", s )
  168. s = %q{
  169. |ABC
  170. |123
  171. |TEST
  172. }.margin(2)
  173. assert_equal( " ABC\n 123\n TEST", s )
  174. s = %q{ ABC
  175. - 123
  176. - TEST
  177. }.margin
  178. assert_equal( " ABC\n 123\n TEST", s )
  179. end
  180. #
  181. def test_random_placement
  182. @volly = {}
  183. 100.times{ |n|
  184. k = []
  185. a = []
  186. 5.times{ |i|
  187. k << ( ( ' ' * Integer(rand*10) ) + '|' + i.to_s )
  188. a << ( i.to_s )
  189. }
  190. @volly[k.join("\n")] = a.join("\n")
  191. }
  192. @volly.each{ |k,v|
  193. assert_equal( v, k.margin )
  194. }
  195. end
  196. end