Refactored spreadsheet related code out of table.vim

This commit is contained in:
Dhruva Sagar
2014-04-07 12:05:20 +05:30
parent f20ff17b42
commit defd9531a7
7 changed files with 820 additions and 832 deletions

99
t/spreadsheet.vim Normal file
View File

@@ -0,0 +1,99 @@
" vim: fdm=indent
source t/config.vim
call vspec#hint({'scope': 'tablemode#spreadsheet#scope()', 'sid': 'tablemode#spreadsheet#sid()'})
describe 'spreadsheet'
describe 'API'
before
new
normal! ggdG
call tablemode#TableModeEnable()
normal i
|test11|test12|
|test21|test22|
end
it 'should return the row count'
Expect tablemode#spreadsheet#RowCount(2) == 2
Expect tablemode#spreadsheet#RowCount(3) == 2
end
it 'should return the row number'
Expect tablemode#spreadsheet#RowNr(2) == 1
Expect tablemode#spreadsheet#RowNr(3) == 2
end
it 'should return the column count'
Expect tablemode#spreadsheet#ColumnCount(2) == 2
Expect tablemode#spreadsheet#ColumnCount(3) == 2
end
it 'should return the line number of the first row'
Expect tablemode#spreadsheet#GetFirstRow(2) == 2
Expect tablemode#spreadsheet#GetFirstRow(3) == 2
end
it 'should return the line nuber of the last row'
Expect tablemode#spreadsheet#GetLastRow(2) == 3
Expect tablemode#spreadsheet#GetLastRow(3) == 3
end
it 'should return the cells'
Expect tablemode#spreadsheet#GetCells(2, 1, 1) ==# 'test11'
" Get Rows
Expect tablemode#spreadsheet#GetCells(2, 1) == ['test11', 'test12']
Expect tablemode#spreadsheet#GetCells(2, 2) == ['test21', 'test22']
" Get Columns
Expect tablemode#spreadsheet#GetCells(2, 0, 1) == ['test11', 'test21']
Expect tablemode#spreadsheet#GetCells(2, 0, 2) == ['test12', 'test22']
end
it 'should return the cells in a range'
" Entire table as range
Expect tablemode#spreadsheet#GetCellRange('1,1:2,2', 2, 1) == [['test11', 'test21'], ['test12', 'test22']]
" Get Rows given different seed lines and columns
Expect tablemode#spreadsheet#GetCellRange('1,1:1,2', 2, 1) == ['test11', 'test12']
Expect tablemode#spreadsheet#GetCellRange('1,1:1,2', 2, 2) == ['test11', 'test12']
Expect tablemode#spreadsheet#GetCellRange('1,1:1,2', 3, 1) == ['test11', 'test12']
Expect tablemode#spreadsheet#GetCellRange('1,1:1,2', 3, 2) == ['test11', 'test12']
Expect tablemode#spreadsheet#GetCellRange('2,1:2,2', 2, 1) == ['test21', 'test22']
Expect tablemode#spreadsheet#GetCellRange('2,1:2,2', 2, 2) == ['test21', 'test22']
Expect tablemode#spreadsheet#GetCellRange('2,1:2,2', 3, 1) == ['test21', 'test22']
Expect tablemode#spreadsheet#GetCellRange('2,1:2,2', 3, 2) == ['test21', 'test22']
" Get Columns given different seed lines and column
Expect tablemode#spreadsheet#GetCellRange('1:2', 2, 1) == ['test11', 'test21']
Expect tablemode#spreadsheet#GetCellRange('1:2', 2, 2) == ['test12', 'test22']
Expect tablemode#spreadsheet#GetCellRange('1:2', 3, 1) == ['test11', 'test21']
Expect tablemode#spreadsheet#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#GetCellRange('1:-1', 2, 1) == ['test11']
Expect tablemode#spreadsheet#GetCellRange('1:-1', 3, 1) == ['test11']
Expect tablemode#spreadsheet#GetCellRange('1:-1', 2, 2) == ['test12']
Expect tablemode#spreadsheet#GetCellRange('1:-1', 3, 2) == ['test12']
end
end
describe 'Manipulations'
before
new
normal! ggdG
normal i|test11|test12|
|test21|test22|
call cursor(1, 3)
end
it 'should delete a row successfully'
Expect tablemode#spreadsheet#RowCount('.') == 2
call tablemode#spreadsheet#DeleteRow()
Expect tablemode#spreadsheet#RowCount('.') == 1
end
it 'should successfully delete column'
Expect tablemode#spreadsheet#ColumnCount('.') == 2
call tablemode#spreadsheet#DeleteColumn()
Expect tablemode#spreadsheet#ColumnCount('.') == 1

View File

@@ -19,69 +19,6 @@ describe 'table'
end
it 'should return false when outside a table'
Expect tablemode#table#IsATableRow(4) to_be_false
end
it 'should return the row count'
Expect tablemode#table#RowCount(2) == 2
Expect tablemode#table#RowCount(3) == 2
end
it 'should return the row number'
Expect tablemode#table#RowNr(2) == 1
Expect tablemode#table#RowNr(3) == 2
end
it 'should return the column count'
Expect tablemode#table#ColumnCount(2) == 2
Expect tablemode#table#ColumnCount(3) == 2
end
it 'should return the line number of the first row'
Expect tablemode#table#GetFirstRow(2) == 2
Expect tablemode#table#GetFirstRow(3) == 2
end
it 'should return the line nuber of the last row'
Expect tablemode#table#GetLastRow(2) == 3
Expect tablemode#table#GetLastRow(3) == 3
end
it 'should return the cells'
Expect Call('s:GetCells', 2, 1, 1) ==# 'test11'
" Get Rows
Expect Call('s:GetCells', 2, 1) == ['test11', 'test12']
Expect Call('s:GetCells', 2, 2) == ['test21', 'test22']
" Get Columns
Expect Call('s:GetCells', 2, 0, 1) == ['test11', 'test21']
Expect Call('s:GetCells', 2, 0, 2) == ['test12', 'test22']
end
it 'should return the cells in a range'
" Entire table as range
Expect Call('s:GetCellRange', '1,1:2,2', 2, 1) == [['test11', 'test21'], ['test12', 'test22']]
" Get Rows given different seed lines and columns
Expect Call('s:GetCellRange', '1,1:1,2', 2, 1) == ['test11', 'test12']
Expect Call('s:GetCellRange', '1,1:1,2', 2, 2) == ['test11', 'test12']
Expect Call('s:GetCellRange', '1,1:1,2', 3, 1) == ['test11', 'test12']
Expect Call('s:GetCellRange', '1,1:1,2', 3, 2) == ['test11', 'test12']
Expect Call('s:GetCellRange', '2,1:2,2', 2, 1) == ['test21', 'test22']
Expect Call('s:GetCellRange', '2,1:2,2', 2, 2) == ['test21', 'test22']
Expect Call('s:GetCellRange', '2,1:2,2', 3, 1) == ['test21', 'test22']
Expect Call('s:GetCellRange', '2,1:2,2', 3, 2) == ['test21', 'test22']
" Get Columns given different seed lines and column
Expect Call('s:GetCellRange', '1:2', 2, 1) == ['test11', 'test21']
Expect Call('s:GetCellRange', '1:2', 2, 2) == ['test12', 'test22']
Expect Call('s:GetCellRange', '1:2', 3, 1) == ['test11', 'test21']
Expect Call('s: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 Call('s:GetCellRange', '1:-1', 2, 1) == ['test11']
Expect Call('s:GetCellRange', '1:-1', 3, 1) == ['test11']
Expect Call('s:GetCellRange', '1:-1', 2, 2) == ['test12']
Expect tablemode#table#IsATableRow(4) to_be_false
end
end
@@ -94,15 +31,15 @@ describe 'table'
asd,asd;asd,asd
asd,asd;asd,asd
end
it 'should tableize with default delimiter'
it 'should tableize with default delimiter'
:2,3call tablemode#TableizeRange('')
Expect tablemode#table#IsATableRow(2) to_be_true
Expect tablemode#spreadsheet#RowCount(2) == 2
Expect tablemode#spreadsheet#ColumnCount(2) == 3
end
it 'should tableize with given delimiter'
it 'should tableize with given delimiter'
:2,3call tablemode#TableizeRange('/;')
Expect tablemode#table#IsATableRow(2) to_be_true
Expect tablemode#spreadsheet#RowCount(2) == 2
@@ -118,33 +55,33 @@ describe 'table'
call tablemode#TableModeEnable()
normal i|test11|test12|
|test21|test22|
call cursor(1, 3)
call cursor(1, 3)
end
it 'should move left when not on first column'
call cursor(1, 12)
Expect tablemode#spreadsheet#ColumnNr('.') == 2
call tablemode#table#TableMotion('h')
Expect tablemode#table#ColumnNr('.') == 1
end
Expect tablemode#spreadsheet#ColumnNr('.') == 1
end
it 'should move to the previous row last column if it exists when on first column'
call cursor(2, 3)
it 'should move to the previous row last column if it exists when on first column'
call cursor(2, 3)
Expect tablemode#spreadsheet#RowNr('.') == 2
Expect tablemode#spreadsheet#ColumnNr('.') == 1
call tablemode#table#TableMotion('h')
Expect tablemode#table#RowNr('.') == 1
Expect tablemode#spreadsheet#RowNr('.') == 1
Expect tablemode#spreadsheet#ColumnNr('.') == 2
end
end
it 'should move right when not on last column'
Expect tablemode#spreadsheet#ColumnNr('.') == 1
call tablemode#table#TableMotion('l')
Expect tablemode#table#ColumnNr('.') == 2
end
Expect tablemode#spreadsheet#ColumnNr('.') == 2
end
it 'should move to the next row first column if it exists when on last column'
call cursor(1, 12)
it 'should move to the next row first column if it exists when on last column'
call cursor(1, 12)
Expect tablemode#spreadsheet#RowNr('.') == 1
Expect tablemode#spreadsheet#ColumnNr('.') == 2
call tablemode#table#TableMotion('l')
@@ -159,49 +96,28 @@ describe 'table'
normal! ggdG
call tablemode#TableModeEnable()
normal i|test11|test12|
|test21|test22|
|test21|test22|
call cursor(1, 3)
end
end
it 'should move a row up unless on first row'
call cursor(2, 3)
Expect tablemode#table#RowNr('.') == 2
Expect tablemode#spreadsheet#RowNr('.') == 2
call tablemode#table#TableMotion('k')
Expect tablemode#table#RowNr('.') == 1
Expect tablemode#spreadsheet#RowNr('.') == 1
end
it 'should remain on first row when trying to move up'
Expect tablemode#table#RowNr('.') == 1
Expect tablemode#spreadsheet#RowNr('.') == 1
call tablemode#table#TableMotion('k')
Expect tablemode#table#RowNr('.') == 1
Expect tablemode#spreadsheet#RowNr('.') == 1
end
it 'should move a row down unless on last row'
Expect tablemode#table#RowNr('.') == 1
Expect tablemode#spreadsheet#RowNr('.') == 1
call tablemode#table#TableMotion('j')
Expect tablemode#table#RowNr('.') == 2
Expect tablemode#spreadsheet#RowNr('.') == 2
end
it 'should remain on last row when trying to move down'
Expect tablemode#table#RowNr('.') == 1
call tablemode#table#TableMotion('k')
Expect tablemode#table#RowNr('.') == 1
end
end
end
describe 'Manipulations'
before
new
normal! ggdG
normal i|test11|test12|
|test21|test22|
call cursor(1, 3)
end
it 'should delete a row successfully'
Expect tablemode#table#RowCount('.') == 2
call tablemode#table#DeleteRow()
Expect tablemode#table#RowCount('.') == 1
end
Expect tablemode#spreadsheet#RowNr('.') == 1