table.vim 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. " vim: fdm=indent
  2. source t/config/options.vim
  3. describe 'table'
  4. describe 'IsRow'
  5. before
  6. new
  7. normal! ggdG
  8. read t/fixtures/table/sample.txt
  9. end
  10. it 'should be true when on a table row'
  11. Expect tablemode#table#IsRow(2) to_be_true
  12. Expect tablemode#table#IsRow(3) to_be_true
  13. end
  14. it 'should be false when not on a table row'
  15. Expect tablemode#table#IsRow(1) to_be_false
  16. Expect tablemode#table#IsRow(4) to_be_false
  17. end
  18. end
  19. describe 'IsBorder'
  20. before
  21. new
  22. normal! ggdG
  23. read t/fixtures/table/sample_with_header.txt
  24. end
  25. it 'should be true on a table border'
  26. Expect tablemode#table#IsBorder(1) to_be_true
  27. Expect tablemode#table#IsBorder(3) to_be_true
  28. Expect tablemode#table#IsBorder(6) to_be_true
  29. end
  30. it 'should be false when not on a table border'
  31. Expect tablemode#table#IsBorder(2) to_be_false
  32. Expect tablemode#table#IsBorder(4) to_be_false
  33. Expect tablemode#table#IsBorder(5) to_be_false
  34. end
  35. end
  36. describe 'IsTable'
  37. before
  38. new normal! ggdG
  39. read t/fixtures/table/sample_with_header.txt
  40. end
  41. it 'should be true on a table row'
  42. Expect tablemode#table#IsTable(2) to_be_true
  43. Expect tablemode#table#IsTable(4) to_be_true
  44. Expect tablemode#table#IsTable(5) to_be_true
  45. end
  46. it 'should be true when on a table border'
  47. Expect tablemode#table#IsTable(1) to_be_true
  48. Expect tablemode#table#IsTable(3) to_be_true
  49. Expect tablemode#table#IsTable(6) to_be_true
  50. end
  51. it 'should not be true when not on a table'
  52. Expect tablemode#table#IsTable(7) to_be_false
  53. end
  54. end
  55. describe 'IsHeader'
  56. before
  57. new
  58. normal! ggdG
  59. read t/fixtures/table/sample_with_header.txt
  60. end
  61. it 'should be true on the table header'
  62. Expect tablemode#table#IsHeader(2) to_be_true
  63. end
  64. it 'should be false anywhere else'
  65. Expect tablemode#table#IsHeader(1) to_be_false
  66. Expect tablemode#table#IsHeader(4) to_be_false
  67. Expect tablemode#table#IsHeader(5) to_be_false
  68. Expect tablemode#table#IsHeader(6) to_be_false
  69. Expect tablemode#table#IsHeader(7) to_be_false
  70. end
  71. end
  72. describe 'AddBorder'
  73. before
  74. new
  75. normal! ggdG
  76. read t/fixtures/table/sample_for_header.txt
  77. end
  78. it 'should add border to line'
  79. call tablemode#table#AddBorder(2)
  80. Expect tablemode#table#IsHeader(1) to_be_true
  81. Expect tablemode#table#IsBorder(2) to_be_true
  82. end
  83. describe 'for unicode'
  84. before
  85. new
  86. normal! ggdG
  87. read t/fixtures/table/sample_for_header_unicode.txt
  88. end
  89. it 'should add border to line'
  90. call tablemode#table#AddBorder(1)
  91. call tablemode#table#AddBorder(3)
  92. call tablemode#table#AddBorder(5)
  93. call tablemode#table#AddBorder(7)
  94. call tablemode#table#AddBorder(9)
  95. Expect tablemode#table#IsBorder(1) to_be_true
  96. Expect tablemode#utils#StrDisplayWidth(getline(1)) == tablemode#utils#StrDisplayWidth(getline(2))
  97. Expect tablemode#table#IsBorder(3) to_be_true
  98. Expect tablemode#utils#StrDisplayWidth(getline(3)) == tablemode#utils#StrDisplayWidth(getline(4))
  99. Expect tablemode#table#IsBorder(5) to_be_true
  100. Expect tablemode#utils#StrDisplayWidth(getline(5)) == tablemode#utils#StrDisplayWidth(getline(6))
  101. Expect tablemode#table#IsBorder(7) to_be_true
  102. Expect tablemode#utils#StrDisplayWidth(getline(7)) == tablemode#utils#StrDisplayWidth(getline(8))
  103. Expect tablemode#table#IsBorder(9) to_be_true
  104. Expect tablemode#utils#StrDisplayWidth(getline(9)) == tablemode#utils#StrDisplayWidth(getline(8))
  105. end
  106. end
  107. end
  108. describe 'Realign'
  109. describe 'without header alignments'
  110. describe 'for simple'
  111. before
  112. new
  113. normal! ggdG
  114. read t/fixtures/table/sample_realign_before.txt
  115. end
  116. it 'should be aligned properly'
  117. call tablemode#table#Realign(1)
  118. Expect getline(1,'$') == readfile('t/fixtures/table/sample_realign_after.txt')
  119. end
  120. end
  121. describe 'for unicode'
  122. before
  123. new
  124. normal! ggdG
  125. read t/fixtures/table/sample_realign_unicode_before.txt
  126. end
  127. it 'should be aligned properly'
  128. call tablemode#table#Realign(1)
  129. Expect getline(1,'$') == readfile('t/fixtures/table/sample_realign_unicode_after.txt')
  130. end
  131. end
  132. end
  133. describe 'with header alignments'
  134. describe 'for simple'
  135. before
  136. new
  137. normal! ggdG
  138. read t/fixtures/table/sample_header_realign_before.txt
  139. end
  140. it 'should be aligned properly'
  141. call tablemode#table#Realign(1)
  142. Expect getline(1,'$') == readfile('t/fixtures/table/sample_header_realign_after.txt')
  143. end
  144. end
  145. describe 'for unicode'
  146. before
  147. new
  148. normal! ggdG
  149. read t/fixtures/table/sample_header_realign_unicode_before.txt
  150. end
  151. it 'should be aligned properly'
  152. call tablemode#table#Realign(1)
  153. Expect getline(1,'$') == readfile('t/fixtures/table/sample_header_realign_unicode_after.txt')
  154. end
  155. end
  156. end
  157. end
  158. end