cell.vim 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. " vim: fdm=indent
  2. source t/config/options.vim
  3. describe 'cell'
  4. describe 'API'
  5. before
  6. new
  7. read t/fixtures/sample.txt
  8. end
  9. it 'should return the cells with GetCells'
  10. Expect tablemode#spreadsheet#cell#GetCells(2, 1, 1) ==# 'test11'
  11. " Get Rows
  12. Expect tablemode#spreadsheet#cell#GetCells(2, 1) == ['test11', 'test12']
  13. Expect tablemode#spreadsheet#cell#GetCells(2, 2) == ['test21', 'test22']
  14. " Get Columns
  15. Expect tablemode#spreadsheet#cell#GetCells(2, 0, 1) == ['test11', 'test21']
  16. Expect tablemode#spreadsheet#cell#GetCells(2, 0, 2) == ['test12', 'test22']
  17. end
  18. it 'should return the row with GetRow'
  19. Expect tablemode#spreadsheet#cell#GetRow(1, 2) == ['test11', 'test12']
  20. Expect tablemode#spreadsheet#cell#GetRow(2, 2) == ['test21', 'test22']
  21. end
  22. it 'should return the column with GetColumn'
  23. Expect tablemode#spreadsheet#cell#GetColumn(1, 2) == ['test11', 'test21']
  24. Expect tablemode#spreadsheet#cell#GetColumn(2, 2) == ['test12', 'test22']
  25. end
  26. it 'should return the cells in a range with GetCellRange'
  27. " Entire table as range
  28. Expect tablemode#spreadsheet#cell#GetCellRange('1,1:2,2', 2, 1) == [['test11', 'test21'], ['test12', 'test22']]
  29. " Get Rows given different seed lines and columns
  30. Expect tablemode#spreadsheet#cell#GetCellRange('1,1:1,2', 2, 1) == ['test11', 'test12']
  31. Expect tablemode#spreadsheet#cell#GetCellRange('1,1:1,2', 2, 2) == ['test11', 'test12']
  32. Expect tablemode#spreadsheet#cell#GetCellRange('1,1:1,2', 3, 1) == ['test11', 'test12']
  33. Expect tablemode#spreadsheet#cell#GetCellRange('1,1:1,2', 3, 2) == ['test11', 'test12']
  34. Expect tablemode#spreadsheet#cell#GetCellRange('2,1:2,2', 2, 1) == ['test21', 'test22']
  35. Expect tablemode#spreadsheet#cell#GetCellRange('2,1:2,2', 2, 2) == ['test21', 'test22']
  36. Expect tablemode#spreadsheet#cell#GetCellRange('2,1:2,2', 3, 1) == ['test21', 'test22']
  37. Expect tablemode#spreadsheet#cell#GetCellRange('2,1:2,2', 3, 2) == ['test21', 'test22']
  38. " Get Columns given different seed lines and column
  39. Expect tablemode#spreadsheet#cell#GetCellRange('1:2', 2, 1) == ['test11', 'test21']
  40. Expect tablemode#spreadsheet#cell#GetCellRange('1:2', 2, 2) == ['test12', 'test22']
  41. Expect tablemode#spreadsheet#cell#GetCellRange('1:2', 3, 1) == ['test11', 'test21']
  42. Expect tablemode#spreadsheet#cell#GetCellRange('1:2', 3, 2) == ['test12', 'test22']
  43. " Get Column given negative values in range for representing rows from
  44. " the end, -1 being the second last row.
  45. Expect tablemode#spreadsheet#cell#GetCellRange('1:-1', 2, 1) == ['test11']
  46. Expect tablemode#spreadsheet#cell#GetCellRange('1:-1', 3, 1) == ['test11']
  47. Expect tablemode#spreadsheet#cell#GetCellRange('1:-1', 2, 2) == ['test12']
  48. Expect tablemode#spreadsheet#cell#GetCellRange('1:-1', 3, 2) == ['test12']
  49. end
  50. end
  51. describe 'Motions'
  52. describe 'left or right'
  53. before
  54. new
  55. normal! ggdG
  56. read t/fixtures/sample.txt
  57. call cursor(2, 3)
  58. end
  59. it 'should move left when not on first column'
  60. call cursor(2, 12)
  61. Expect tablemode#spreadsheet#ColumnNr('.') == 2
  62. call tablemode#spreadsheet#cell#Motion('h')
  63. Expect tablemode#spreadsheet#ColumnNr('.') == 1
  64. end
  65. it 'should move to the previous row last column if it exists when on first column'
  66. call cursor(3, 3)
  67. Expect tablemode#spreadsheet#RowNr('.') == 2
  68. Expect tablemode#spreadsheet#ColumnNr('.') == 1
  69. call tablemode#spreadsheet#cell#Motion('h')
  70. Expect tablemode#spreadsheet#RowNr('.') == 1
  71. Expect tablemode#spreadsheet#ColumnNr('.') == 2
  72. end
  73. it 'should move right when not on last column'
  74. Expect tablemode#spreadsheet#ColumnNr('.') == 1
  75. call tablemode#spreadsheet#cell#Motion('l')
  76. Expect tablemode#spreadsheet#ColumnNr('.') == 2
  77. end
  78. it 'should move to the next row first column if it exists when on last column'
  79. call cursor(2, 12)
  80. Expect tablemode#spreadsheet#RowNr('.') == 1
  81. Expect tablemode#spreadsheet#ColumnNr('.') == 2
  82. call tablemode#spreadsheet#cell#Motion('l')
  83. Expect tablemode#spreadsheet#RowNr('.') == 2
  84. Expect tablemode#spreadsheet#ColumnNr('.') == 1
  85. end
  86. end
  87. describe 'up or down'
  88. before
  89. new
  90. normal! ggdG
  91. read t/fixtures/sample.txt
  92. call cursor(2, 3)
  93. end
  94. it 'should move a row up unless on first row'
  95. call cursor(3, 3)
  96. Expect tablemode#spreadsheet#RowNr('.') == 2
  97. call tablemode#spreadsheet#cell#Motion('k')
  98. Expect tablemode#spreadsheet#RowNr('.') == 1
  99. end
  100. it 'should remain on first row when trying to move up'
  101. Expect tablemode#spreadsheet#RowNr('.') == 1
  102. call tablemode#spreadsheet#cell#Motion('k')
  103. Expect tablemode#spreadsheet#RowNr('.') == 1
  104. end
  105. it 'should move a row down unless on last row'
  106. Expect tablemode#spreadsheet#RowNr('.') == 1
  107. call tablemode#spreadsheet#cell#Motion('j')
  108. Expect tablemode#spreadsheet#RowNr('.') == 2
  109. end
  110. it 'should remain on last row when trying to move down'
  111. Expect tablemode#spreadsheet#RowNr('.') == 1
  112. call tablemode#spreadsheet#cell#Motion('k')
  113. Expect tablemode#spreadsheet#RowNr('.') == 1
  114. end
  115. end
  116. end
  117. end