aboutsummaryrefslogtreecommitdiff
path: root/vim/bundle/vim-table-mode/t/cell.vim
blob: e3d03ed2a17705e550e7840316b1bdac5290c088 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
" vim: fdm=indent
source t/config/options.vim

describe 'cell'
  describe 'API'
    before
      new
      read t/fixtures/sample.txt
    end

    it 'should return the cells with GetCells'
      Expect tablemode#spreadsheet#cell#GetCells(2, 1, 1) ==# 'test11'
      " Get Rows
      Expect tablemode#spreadsheet#cell#GetCells(2, 1) == ['test11', 'test12']
      Expect tablemode#spreadsheet#cell#GetCells(2, 2) == ['test21', 'test22']
      " Get Columns
      Expect tablemode#spreadsheet#cell#GetCells(2, 0, 1) == ['test11', 'test21']
      Expect tablemode#spreadsheet#cell#GetCells(2, 0, 2) == ['test12', 'test22']
    end

    it 'should return the row with GetRow'
      Expect tablemode#spreadsheet#cell#GetRow(1, 2) == ['test11', 'test12']
      Expect tablemode#spreadsheet#cell#GetRow(2, 2) == ['test21', 'test22']
    end

    it 'should return the column with GetColumn'
      Expect tablemode#spreadsheet#cell#GetColumn(1, 2) == ['test11', 'test21']
      Expect tablemode#spreadsheet#cell#GetColumn(2, 2) == ['test12', 'test22']
    end

    it 'should return the cells in a range with GetCellRange'
      " Entire table as range
      Expect tablemode#spreadsheet#cell#GetCellRange('1,1:2,2', 2, 1) == [['test11', 'test21'], ['test12', 'test22']]

      " Get Rows given different seed lines and columns
      Expect tablemode#spreadsheet#cell#GetCellRange('1,1:1,2', 2, 1) == ['test11', 'test12']
      Expect tablemode#spreadsheet#cell#GetCellRange('1,1:1,2', 2, 2) == ['test11', 'test12']
      Expect tablemode#spreadsheet#cell#GetCellRange('1,1:1,2', 3, 1) == ['test11', 'test12']
      Expect tablemode#spreadsheet#cell#GetCellRange('1,1:1,2', 3, 2) == ['test11', 'test12']
      Expect tablemode#spreadsheet#cell#GetCellRange('2,1:2,2', 2, 1) == ['test21', 'test22']
      Expect tablemode#spreadsheet#cell#GetCellRange('2,1:2,2', 2, 2) == ['test21', 'test22']
      Expect tablemode#spreadsheet#cell#GetCellRange('2,1:2,2', 3, 1) == ['test21', 'test22']
      Expect tablemode#spreadsheet#cell#GetCellRange('2,1:2,2', 3, 2) == ['test21', 'test22']

      " Get Columns given different seed lines and column
      Expect tablemode#spreadsheet#cell#GetCellRange('1:2', 2, 1) == ['test11', 'test21']
      Expect tablemode#spreadsheet#cell#GetCellRange('1:2', 2, 2) == ['test12', 'test22']
      Expect tablemode#spreadsheet#cell#GetCellRange('1:2', 3, 1) == ['test11', 'test21']
      Expect tablemode#spreadsheet#cell#GetCellRange('1:2', 3, 2) == ['test12', 'test22']

      " Get Column given negative values in range for representing rows from
      " the end, -1 being the second last row.
      Expect tablemode#spreadsheet#cell#GetCellRange('1:-1', 2, 1) == ['test11']
      Expect tablemode#spreadsheet#cell#GetCellRange('1:-1', 3, 1) == ['test11']
      Expect tablemode#spreadsheet#cell#GetCellRange('1:-1', 2, 2) == ['test12']
      Expect tablemode#spreadsheet#cell#GetCellRange('1:-1', 3, 2) == ['test12']
    end
  end

  describe 'Motions'
    describe 'left or right'
      before
        new
        normal! ggdG
        read t/fixtures/sample.txt
        call cursor(2, 3)
      end

      it 'should move left when not on first column'
        call cursor(2, 12)
        Expect tablemode#spreadsheet#ColumnNr('.') == 2
        call tablemode#spreadsheet#cell#Motion('h')
        Expect tablemode#spreadsheet#ColumnNr('.') == 1
      end

      it 'should move to the previous row last column if it exists when on first column'
        call cursor(3, 3)
        Expect tablemode#spreadsheet#RowNr('.') == 2
        Expect tablemode#spreadsheet#ColumnNr('.') == 1
        call tablemode#spreadsheet#cell#Motion('h')
        Expect tablemode#spreadsheet#RowNr('.') == 1
        Expect tablemode#spreadsheet#ColumnNr('.') == 2
      end

      it 'should move right when not on last column'
        Expect tablemode#spreadsheet#ColumnNr('.') == 1
        call tablemode#spreadsheet#cell#Motion('l')
        Expect tablemode#spreadsheet#ColumnNr('.') == 2
      end

      it 'should move to the next row first column if it exists when on last column'
        call cursor(2, 12)
        Expect tablemode#spreadsheet#RowNr('.') == 1
        Expect tablemode#spreadsheet#ColumnNr('.') == 2
        call tablemode#spreadsheet#cell#Motion('l')
        Expect tablemode#spreadsheet#RowNr('.') == 2
        Expect tablemode#spreadsheet#ColumnNr('.') == 1
      end
    end

    describe 'up or down'
      before
        new
        normal! ggdG
        read t/fixtures/sample.txt
        call cursor(2, 3)
      end

      it 'should move a row up unless on first row'
        call cursor(3, 3)
        Expect tablemode#spreadsheet#RowNr('.') == 2
        call tablemode#spreadsheet#cell#Motion('k')
        Expect tablemode#spreadsheet#RowNr('.') == 1
      end

      it 'should remain on first row when trying to move up'
        Expect tablemode#spreadsheet#RowNr('.') == 1
        call tablemode#spreadsheet#cell#Motion('k')
        Expect tablemode#spreadsheet#RowNr('.') == 1
      end

      it 'should move a row down unless on last row'
        Expect tablemode#spreadsheet#RowNr('.') == 1
        call tablemode#spreadsheet#cell#Motion('j')
        Expect tablemode#spreadsheet#RowNr('.') == 2
      end

      it 'should remain on last row when trying to move down'
        Expect tablemode#spreadsheet#RowNr('.') == 1
        call tablemode#spreadsheet#cell#Motion('k')
        Expect tablemode#spreadsheet#RowNr('.') == 1
      end
    end
  end
end