Rewrite tests with vim-testify

This commit is contained in:
Dhruva Sagar
2023-03-01 07:22:48 +05:30
parent 9555a3e6e5
commit 7ec0b83dbd
37 changed files with 1241 additions and 862 deletions

View File

@@ -0,0 +1,23 @@
source t/config/options.vim
function! ConvertLines2Dict(lines)
let lines = []
for idx in range(len(a:lines))
call insert(lines, {"lnum": idx+1, "text": a:lines[idx]})
endfor
return lines
endfunction
function! s:TestAlignTable()
let actual = tablemode#align#Align(ConvertLines2Dict(readfile('t/fixtures/align/simple_before.txt')))
let expected = ConvertLines2Dict(readfile('t/fixtures/align/simple_after.txt'))
call testify#assert#equals(actual, expected)
endfunction
call testify#it('Align should align table content', function('s:TestAlignTable'))
function! s:TestAlignTableUnicode()
let actual = tablemode#align#Align(ConvertLines2Dict(readfile('t/fixtures/align/unicode_before.txt')))
let expected = ConvertLines2Dict(readfile('t/fixtures/align/unicode_after.txt'))
call testify#assert#equals(actual, expected)
endfunction
call testify#it('Align should align table content with unicode characters', function('s:TestAlignTableUnicode'))

View File

@@ -0,0 +1,194 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/cell/counts.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestCountE()
call cursor(3, 3)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#CountE('1:3'),
\ 'expected': 1,
\ },
\ {
\ 'actual': tablemode#spreadsheet#CountE('1,1:1,3'),
\ 'expected': 0,
\ },
\ {
\ 'actual': tablemode#spreadsheet#CountE('2,1:2,3'),
\ 'expected': 2,
\ },
\ {
\ 'actual': tablemode#spreadsheet#CountE('1,1:3,3'),
\ 'expected': 2,
\ },
\]
call utils#TableTest(tests)
call cursor(5, 11)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#CountE('1:3'),
\ 'expected': 1,
\ },
\ {
\ 'actual': tablemode#spreadsheet#CountE('3,1:3,3'),
\ 'expected': 0,
\ },
\]
call utils#TableTest(tests)
endfunction
call testify#it('CountE should return the count of empty cells within cell range', function('s:TestCountE'))
function! s:TestCountNE()
call cursor(3, 3)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#CountNE('1:3'),
\ 'expected': 2,
\ },
\ {
\ 'actual': tablemode#spreadsheet#CountNE('1,1:1,3'),
\ 'expected': 3,
\ },
\ {
\ 'actual': tablemode#spreadsheet#CountNE('2,1:2,3'),
\ 'expected': 1,
\ },
\ {
\ 'actual': tablemode#spreadsheet#CountNE('1,1:3,3'),
\ 'expected': 7,
\ },
\]
call utils#TableTest(tests)
call cursor(5, 11)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#CountNE('1:3'),
\ 'expected': 2,
\ },
\ {
\ 'actual': tablemode#spreadsheet#CountNE('3,1:3,3'),
\ 'expected': 3,
\ },
\]
call utils#TableTest(tests)
endfunction
call testify#it('CountNE should return the count of non-empty cells within cell range', function('s:TestCountNE'))
function! s:TestPercentE()
call cursor(3, 3)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#PercentE('1:3'),
\ 'expected': 33,
\ },
\ {
\ 'actual': tablemode#spreadsheet#PercentE('1,1:1,3'),
\ 'expected': 0,
\ },
\ {
\ 'actual': tablemode#spreadsheet#PercentE('2,1:2,3'),
\ 'expected': 66,
\ },
\ {
\ 'actual': tablemode#spreadsheet#PercentE('1,1:3,3'),
\ 'expected': 22,
\ },
\]
call utils#TableTest(tests)
call cursor(5, 11)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#PercentE('1:3'),
\ 'expected': 33,
\ },
\ {
\ 'actual': tablemode#spreadsheet#PercentE('3,1:3,3'),
\ 'expected': 0,
\ },
\]
call utils#TableTest(tests)
endfunction
call testify#it('PercentE should return the percent count of empty cells within cell range', function('s:TestPercentE'))
function! s:TestPercentNE()
call cursor(3, 3)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#PercentNE('1:3'),
\ 'expected': 66,
\ },
\ {
\ 'actual': tablemode#spreadsheet#PercentNE('1,1:1,3'),
\ 'expected': 100,
\ },
\ {
\ 'actual': tablemode#spreadsheet#PercentNE('2,1:2,3'),
\ 'expected': 33,
\ },
\ {
\ 'actual': tablemode#spreadsheet#PercentNE('1,1:3,3'),
\ 'expected': 77,
\ },
\]
call utils#TableTest(tests)
call cursor(5, 11)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#PercentNE('1:3'),
\ 'expected': 66,
\ },
\ {
\ 'actual': tablemode#spreadsheet#PercentNE('3,1:3,3'),
\ 'expected': 100,
\ },
\]
call utils#TableTest(tests)
endfunction
call testify#it('PercentNE should return the percent count of non-empty cells within cell range', function('s:TestPercentNE'))
function! s:TestAverageNE()
call cursor(3, 3)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#AverageNE('1:3'),
\ 'expected': 2.5,
\ },
\ {
\ 'actual': tablemode#spreadsheet#AverageNE('1,1:1,3'),
\ 'expected': 2.0,
\ },
\ {
\ 'actual': tablemode#spreadsheet#AverageNE('2,1:2,3'),
\ 'expected': 0.0,
\ },
\ {
\ 'actual': tablemode#spreadsheet#AverageNE('1,1:3,3'),
\ 'expected': 3.0,
\ },
\]
call utils#TableTest(tests)
call cursor(5, 11)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#AverageNE('1:3'),
\ 'expected': 4.5,
\ },
\ {
\ 'actual': tablemode#spreadsheet#AverageNE('3,1:3,3'),
\ 'expected': 5.0,
\ },
\]
call utils#TableTest(tests)
endfunction
call testify#it('AverageNE should return the average of non-empty cells within cell range', function('s:TestAverageNE'))

View File

@@ -0,0 +1,52 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/sample.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestDeleteRow()
call cursor(3, 3)
call testify#assert#equals(tablemode#spreadsheet#RowCount('.'), 2)
call tablemode#spreadsheet#DeleteRow()
call testify#assert#equals(tablemode#spreadsheet#RowCount('.'), 1)
call utils#TestUndo(s:test_file)
endfunction
call testify#it('DeleteRow should delete a row', function('s:TestDeleteRow'))
function! s:TestDeleteColumn()
call cursor(3, 3)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 2)
call tablemode#spreadsheet#DeleteColumn()
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 1)
call utils#TestUndo(s:test_file)
endfunction
call testify#it('DeleteColumn should delete a column', function('s:TestDeleteColumn'))
function! s:TestInsertColumn()
call cursor(3, 3)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 2)
call tablemode#spreadsheet#InsertColumn(0)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 3)
" InsertColumn leaves us in insert mode
stopinsert
call testify#assert#equals(getline('.'), '| | test11 | test12 |')
call utils#TestUndo(s:test_file)
endfunction
call testify#it('InsertColumn should insert a new column before the current column', function('s:TestInsertColumn'))
function! s:TestInserColumnAfter()
call cursor(3, 3)
normal! $
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 2)
call tablemode#spreadsheet#InsertColumn(1)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 3)
" InsertColumn leaves us in insert mode
stopinsert
call testify#assert#equals(getline('.'), '| test11 | test12 | |')
call utils#TestUndo(s:test_file)
endfunction
call testify#it('InsertColumn should be able to insert a new column after the current column', function('s:TestInserColumnAfter'))

View File

@@ -0,0 +1,51 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/escaped_seperator.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestDeleteRow()
call cursor(3, 3)
call testify#assert#equals(tablemode#spreadsheet#RowCount('.'), 7)
call tablemode#spreadsheet#DeleteRow()
call testify#assert#equals(tablemode#spreadsheet#RowCount('.'), 6)
call testify#assert#equals(getline('.'), '| a separator. | |')
call utils#TestUndo(s:test_file)
endfunction
call testify#it('DeleteRow should be able to delete a row with escaped table separator', function('s:TestDeleteRow'))
function! s:TestDeleteColumn()
call cursor(3, 3)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 2)
call tablemode#spreadsheet#DeleteColumn()
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 1)
call testify#assert#equals(getline('.'), '| It can be escaped by a \. |')
call utils#TestUndo(s:test_file)
endfunction
call testify#it('DeleteColumn should be able to delete a column with escaped table separator', function('s:TestDeleteColumn'))
function! s:TestInsertColumnBefore()
call cursor(3, 3)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 2)
call tablemode#spreadsheet#InsertColumn(0)
stopinsert
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 3)
call testify#assert#equals(getline('.'), '| | The \| works as | It can be escaped by a \. |')
call utils#TestUndo(s:test_file)
endfunction
call testify#it('InsertColumn should be able to insert a column before the current column with escaped table separator', function('s:TestInsertColumnBefore'))
function! s:TestInsertColumnAfter()
call cursor(3, 3)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 2)
call tablemode#spreadsheet#InsertColumn(1)
stopinsert
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 3)
call testify#assert#equals(getline('.'), '| The \| works as | | It can be escaped by a \. |')
call utils#TestUndo(s:test_file)
endfunction
call testify#it('InsertColumn should be able to insert a column after the current column with escabled table separator', function('s:TestInsertColumnAfter'))

View File

@@ -0,0 +1,53 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/complex_header.txt'
function! s:setup()
let g:table_mode_header_fillchar = '='
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestDeleteRow()
call cursor(5, 7)
call testify#assert#equals(tablemode#spreadsheet#RowCount('.'), 5)
call tablemode#spreadsheet#DeleteRow()
call testify#assert#equals(tablemode#spreadsheet#RowCount('.'), 4)
call testify#assert#equals(getline(5), '| 2 | 8 | b | y |')
call utils#TestUndo(s:test_file)
endfunction
call testify#it('DeleteRow should delete a row in a table with headers', function('s:TestDeleteRow'))
function! s:TestDeleteColumn()
call cursor(5, 7)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 4)
call tablemode#spreadsheet#DeleteColumn()
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 3)
call testify#assert#equals(getline(5), '| 9 | a | z |')
call utils#TestUndo(s:test_file)
endfunction
call testify#it('DeleteColumn should delete a column in a table with headers', function('s:TestDeleteColumn'))
function! s:TestInsertColumn()
call cursor(5, 7)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 4)
call tablemode#spreadsheet#InsertColumn(0)
stopinsert
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 5)
call testify#assert#equals(getline(5), '| | 1 | 9 | a | z |')
call utils#TestUndo(s:test_file)
endfunction
call testify#it('InsertColumn should insert a new column before the current column in a table with headers in a table with headers', function('s:TestInsertColumn'))
function! s:TestInserColumnAfter()
call cursor(5, 7)
normal! $
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 4)
call tablemode#spreadsheet#InsertColumn(1)
stopinsert
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 5)
call testify#assert#equals(getline(5), '| 1 | 9 | a | z | |')
call utils#TestUndo(s:test_file)
endfunction
call testify#it('InsertColumn should be able to insert a new column after the current column in a table with headers', function('s:TestInserColumnAfter'))

View File

@@ -0,0 +1,47 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/table//sample_realign_unicode_after.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestDeleteRow()
call cursor(3, 19)
call testify#assert#equals(tablemode#spreadsheet#RowCount('.'), 4)
call tablemode#spreadsheet#DeleteRow()
call testify#assert#equals(tablemode#spreadsheet#RowCount('.'), 3)
call utils#TestUndo(s:test_file)
endfunction
call testify#it('DeleteRow should be able to delete a row with unicode characters', function('s:TestDeleteRow'))
function! s:TestDeleteColumn()
call cursor(3, 19)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 3)
call tablemode#spreadsheet#DeleteColumn()
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 2)
call utils#TestUndo(s:test_file)
endfunction
call testify#it('DeleteColumn should be able to delete a column with unicode characters', function('s:TestDeleteColumn'))
function! s:TestInsertColumnBefore()
call cursor(3, 19)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 3)
call tablemode#spreadsheet#InsertColumn(0)
stopinsert
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 4)
call utils#TestUndo(s:test_file)
endfunction
call testify#it('InsertColumn should be able to insert a column before the current column with unicode characters', function('s:TestInsertColumnBefore'))
function! s:TestInsertColumnAfter()
call cursor(3, 19)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 3)
call tablemode#spreadsheet#InsertColumn(1)
stopinsert
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 4)
call utils#TestUndo(s:test_file)
endfunction
call testify#it('InsertColumn should be able to insert a column after the current column with unicode characters', function('s:TestInsertColumnAfter'))

View File

@@ -0,0 +1,141 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/cell/sample.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestSum()
call cursor(3, 3)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#Sum('1:2'),
\ 'expected': 4.0
\ },
\ {
\ 'actual': tablemode#spreadsheet#Sum('1,1:1,2'),
\ 'expected': 3.0
\ },
\ {
\ 'actual': tablemode#spreadsheet#Sum('1,1:2,2'),
\ 'expected': 10.0
\ },
\]
call utils#TableTest(tests)
call cursor(4, 7)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#Sum('1:2'),
\ 'expected': 6.0
\ },
\ {
\ 'actual': tablemode#spreadsheet#Sum('2,1:2,2'),
\ 'expected': 7.0
\ },
\]
call utils#TableTest(tests)
endfunction
call testify#it('Sum should return the sum of cell range', function('s:TestSum'))
function! s:TestAverage()
call cursor(3, 3)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#Average('1:2'),
\ 'expected': 2.0
\ },
\ {
\ 'actual': tablemode#spreadsheet#Average('1,1:1,2'),
\ 'expected': 1.5
\ },
\ {
\ 'actual': tablemode#spreadsheet#Average('1,1:2,2'),
\ 'expected': 2.5
\ },
\]
call utils#TableTest(tests)
call cursor(4, 7)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#Average('1:2'),
\ 'expected': 3.0
\ },
\ {
\ 'actual': tablemode#spreadsheet#Average('2,1:2,2'),
\ 'expected': 3.5
\ },
\]
call utils#TableTest(tests)
endfunction
call testify#it('Average should return the average of cell range', function('s:TestAverage'))
function! s:TestMin()
call cursor(3, 3)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#Min('1:2'),
\ 'expected': 1.0
\ },
\ {
\ 'actual': tablemode#spreadsheet#Min('1,1:1,2'),
\ 'expected': 1.0
\ },
\ {
\ 'actual': tablemode#spreadsheet#Min('1,1:2,2'),
\ 'expected': 1.0
\ },
\]
call utils#TableTest(tests)
call cursor(4, 7)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#Min('1:2'),
\ 'expected': 2.0
\ },
\ {
\ 'actual': tablemode#spreadsheet#Min('2,1:2,2'),
\ 'expected': 3.0
\ },
\]
call utils#TableTest(tests)
endfunction
call testify#it('Min should return the min of cell range', function('s:TestMin'))
function! s:TestMax()
call cursor(3, 3)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#Max('1:2'),
\ 'expected': 3.0
\ },
\ {
\ 'actual': tablemode#spreadsheet#Max('1,1:1,2'),
\ 'expected': 2.0
\ },
\ {
\ 'actual': tablemode#spreadsheet#Max('1,1:2,2'),
\ 'expected': 4.0
\ },
\]
call utils#TableTest(tests)
call cursor(4, 7)
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#Max('1:2'),
\ 'expected': 4.0
\ },
\ {
\ 'actual': tablemode#spreadsheet#Max('2,1:2,2'),
\ 'expected': 4.0
\ },
\]
call utils#TableTest(tests)
endfunction
call testify#it('Max should return the max of cell range', function('s:TestMax'))

View File

@@ -0,0 +1,49 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/big_sample.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestDeleteRowWithRange()
call cursor(3, 3)
call testify#assert#equals(tablemode#spreadsheet#RowCount('.'), 5)
.,.+1 call tablemode#spreadsheet#DeleteRow()
call testify#assert#equals(tablemode#spreadsheet#RowCount('.'), 3)
call utils#TestUndo(s:test_file)
endfunction
call testify#it('DeleteRow should work with a range', function('s:TestDeleteRowWithRange'))
function! s:TestDeleteColumnWithRange()
call cursor(3, 3)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 4)
.,.+1 call tablemode#spreadsheet#DeleteColumn()
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 2)
call utils#TestUndo(s:test_file)
endfunction
call testify#it('DeleteColumn should work with a range', function('s:TestDeleteColumnWithRange'))
function! s:TestInsertColumnWithCountBefore()
call cursor(3, 7)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 4)
execute "normal! 2:\<C-U>call tablemode#spreadsheet#InsertColumn(0)\<CR>"
stopinsert
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 6)
call testify#assert#equals(getline('.'), '| 1 | | | 9 | a | z |')
call utils#TestUndo(s:test_file)
endfunction
call testify#it('InsertColumn should work with a count to add columns before current column', function('s:TestInsertColumnWithCountBefore'))
function! s:TestInsertColumnWithCountAfter()
call cursor(3, 7)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 4)
execute "normal! 2:\<C-U>call tablemode#spreadsheet#InsertColumn(1)\<CR>"
stopinsert
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 6)
call testify#assert#equals(getline('.'), '| 1 | 9 | | | a | z |')
call utils#TestUndo(s:test_file)
endfunction
call testify#it('InsertColumn should work with a count to add columns after current column', function('s:TestInsertColumnWithCountAfter'))

View File

@@ -0,0 +1,66 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/sample.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestRowCount()
call testify#assert#equals(tablemode#spreadsheet#RowCount(3), 2)
call testify#assert#equals(tablemode#spreadsheet#RowCount(4), 2)
endfunction
call testify#it('RowCount should return the correct row count', function('s:TestRowCount'))
function! s:TestRowNr()
call testify#assert#equals(tablemode#spreadsheet#RowNr(3), 1)
call testify#assert#equals(tablemode#spreadsheet#RowNr(4), 2)
endfunction
call testify#it('RowNr should return the correct row number', function('s:TestRowNr'))
function! s:TestColumnCount()
call testify#assert#equals(tablemode#spreadsheet#ColumnCount(3), 2)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount(4), 2)
endfunction
call testify#it('ColumnCount should return the correct column count', function('s:TestColumnCount'))
function! s:TestColumnNr()
call cursor(3, 3)
call testify#assert#equals(tablemode#spreadsheet#ColumnNr('.'), 1)
call cursor(3, 12)
call testify#assert#equals(tablemode#spreadsheet#ColumnNr('.'), 2)
endfunction
call testify#it('ColumnNr should return the correct column number', function('s:TestColumnNr'))
function! s:TestIsFirstCell()
call cursor(3, 3)
call testify#assert#assert(tablemode#spreadsheet#IsFirstCell())
call cursor(3, 12)
call testify#assert#assert(!tablemode#spreadsheet#IsFirstCell())
endfunction
call testify#it('IsFirstCell should return true when in the first cell', function('s:TestIsFirstCell'))
function! s:TestIsLastCell()
call cursor(3, 3)
call testify#assert#assert(!tablemode#spreadsheet#IsLastCell())
call cursor(3, 12)
call testify#assert#assert(tablemode#spreadsheet#IsLastCell())
endfunction
call testify#it('IsLastCell should return true when in the last cell', function('s:TestIsLastCell'))
function! s:TestGetFirstRow()
call testify#assert#equals(tablemode#spreadsheet#GetFirstRow(3), 3)
call testify#assert#equals(tablemode#spreadsheet#GetFirstRow(4), 3)
endfunction
call testify#it('GetFirstRow should return the line number of the first row', function('s:TestGetFirstRow'))
function! s:TestGetLastRow()
call testify#assert#equals(tablemode#spreadsheet#GetLastRow(3), 4)
call testify#assert#equals(tablemode#spreadsheet#GetLastRow(4), 4)
endfunction
call testify#it('GetLastRow should return the line number of the last row', function('s:TestGetLastRow'))

View File

@@ -0,0 +1,208 @@
source t/config/options.vim
source t/utils.vim
function! s:setup()
call utils#TestSetup('t/fixtures/sample.txt')
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestGetCells()
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCells(3, 1, 1),
\ 'expected': 'test11'
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCells(3, 1),
\ 'expected': ['test11', 'test12']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCells(3, 2),
\ 'expected': ['test21', 'test22']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCells(3, 0, 1),
\ 'expected': ['test11', 'test21']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCells(3, 0, 2),
\ 'expected': ['test12', 'test22']
\ },
\]
call utils#TableTest(tests)
endfunction
call testify#it('GetCells should return correct cell value', function('s:TestGetCells'))
function! s:TestGetRow()
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#cell#GetRow(1, 3),
\ 'expected': ['test11', 'test12']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetRow(2, 3),
\ 'expected': ['test21', 'test22']
\ },
\]
call utils#TableTest(tests)
endfunction
call testify#it('GetRow should return the row', function('s:TestGetRow'))
function! s:TestGetColumn()
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#cell#GetColumn(1, 3),
\ 'expected': ['test11', 'test21']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetRow(2, 3),
\ 'expected': ['test21', 'test22']
\ },
\]
call utils#TableTest(tests)
endfunction
call testify#it('GetColumn should return the column', function('s:TestGetColumn'))
function! s:TestGetCellRange()
let tests = [
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('1,1:2,2', 3, 1),
\ 'expected': [['test11', 'test21'], ['test12', 'test22']]
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('1,1:1,2', 3, 1),
\ 'expected': ['test11', 'test12']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('1,1:1,2', 3, 2),
\ 'expected': ['test11', 'test12']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('1,1:1,2', 4, 1),
\ 'expected': ['test11', 'test12']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('1,1:1,2', 4, 2),
\ 'expected': ['test11', 'test12']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('2,1:2,2', 3, 1),
\ 'expected': ['test21', 'test22']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('2,1:2,2', 3, 2),
\ 'expected': ['test21', 'test22']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('2,1:2,2', 4, 1),
\ 'expected': ['test21', 'test22']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('2,1:2,2', 4, 2),
\ 'expected': ['test21', 'test22']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('1:2', 3, 1),
\ 'expected': ['test11', 'test21']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('1:2', 3, 2),
\ 'expected': ['test12', 'test22']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('1:2', 4, 1),
\ 'expected': ['test11', 'test21']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('1:2', 4, 2),
\ 'expected': ['test12', 'test22']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('1:-1', 3, 1),
\ 'expected': ['test11']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('1:-1', 4, 1),
\ 'expected': ['test11']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('1:-1', 3, 2),
\ 'expected': ['test12']
\ },
\ {
\ 'actual': tablemode#spreadsheet#cell#GetCellRange('1:-1', 4, 2),
\ 'expected': ['test12']
\ },
\]
call utils#TableTest(tests)
endfunction
call testify#it('GetCellRange should return the cell values in given range', function('s:TestGetCellRange'))
function! s:TestLeftMotion()
call cursor(3, 12)
call testify#assert#equals(tablemode#spreadsheet#ColumnNr('.'), 2)
call tablemode#spreadsheet#cell#Motion('h')
call testify#assert#equals(tablemode#spreadsheet#ColumnNr('.'), 1)
endfunction
call testify#it('Motion "h" should move cursor to the left column', function('s:TestLeftMotion'))
function! s:TestLeftMotionFirstColumn() abort
call cursor(4, 3)
call testify#assert#equals(tablemode#spreadsheet#RowNr('.'), 2)
call testify#assert#equals(tablemode#spreadsheet#ColumnNr('.'), 1)
call tablemode#spreadsheet#cell#Motion('h')
call testify#assert#equals(tablemode#spreadsheet#RowNr('.'), 1)
call testify#assert#equals(tablemode#spreadsheet#ColumnNr('.'), 2)
endfunction
call testify#it('Motion "h" should move cursor to the last column of previous row when on first column', function('s:TestLeftMotionFirstColumn'))
function! s:TestRightMotion()
call cursor(3, 3)
call testify#assert#equals(tablemode#spreadsheet#ColumnNr('.'), 1)
call tablemode#spreadsheet#cell#Motion('l')
call testify#assert#equals(tablemode#spreadsheet#ColumnNr('.'), 2)
endfunction
call testify#it('Motion "l" should move cursor to the right column', function('s:TestRightMotion'))
function! s:TestRightMotionLastColumn()
call cursor(3, 12)
call testify#assert#equals(tablemode#spreadsheet#RowNr('.'), 1)
call testify#assert#equals(tablemode#spreadsheet#ColumnNr('.'), 2)
call tablemode#spreadsheet#cell#Motion('l')
call testify#assert#equals(tablemode#spreadsheet#RowNr('.'), 2)
call testify#assert#equals(tablemode#spreadsheet#ColumnNr('.'), 1)
endfunction
call testify#it('Motion "l" should move cursor to the first column of next row when on last column', function('s:TestRightMotionLastColumn'))
function! s:TestUpMotion()
call cursor(4, 3)
call testify#assert#equals(tablemode#spreadsheet#RowNr('.'), 2)
call tablemode#spreadsheet#cell#Motion('k')
call testify#assert#equals(tablemode#spreadsheet#RowNr('.'), 1)
endfunction
call testify#it('Motion "k" should move cursor to the column above', function('s:TestUpMotion'))
function! s:TestUpMotionFirstRow()
call cursor(3, 3)
call testify#assert#equals(tablemode#spreadsheet#RowNr('.'), 1)
call tablemode#spreadsheet#cell#Motion('k')
call testify#assert#equals(tablemode#spreadsheet#RowNr('.'), 1)
endfunction
call testify#it('Motion "k" should remain on first row when trying to move up', function('s:TestUpMotionFirstRow'))
function! s:TestDownMotion()
call cursor(3, 3)
call testify#assert#equals(tablemode#spreadsheet#RowNr('.'), 1)
call tablemode#spreadsheet#cell#Motion('j')
call testify#assert#equals(tablemode#spreadsheet#RowNr('.'), 2)
endfunction
call testify#it('Motion "j" should move cursor to the column above', function('s:TestDownMotion'))
function! s:TestDownMotionFirstRow()
call cursor(4, 3)
call testify#assert#equals(tablemode#spreadsheet#RowNr('.'), 2)
call tablemode#spreadsheet#cell#Motion('j')
call testify#assert#equals(tablemode#spreadsheet#RowNr('.'), 2)
endfunction
call testify#it('Motion "j" should remain on last row when trying to move down', function('s:TestDownMotionFirstRow'))

View File

@@ -0,0 +1,28 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/formula/sample.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestAddFormula()
call cursor(7, 15)
call tablemode#spreadsheet#formula#Add('Sum(1:3)')
let cell_value = tablemode#spreadsheet#cell#GetCell()
call testify#assert#equals(cell_value, '125.0')
call cursor(9, 15)
call testify#assert#equals(getline('.'), '/* tmf: $4,2=Sum(1:3) */')
call cursor(8, 15)
call tablemode#spreadsheet#formula#Add('Sum(1:-1)')
let cell_value = tablemode#spreadsheet#cell#GetCell()
call testify#assert#equals(cell_value, '250.0')
call cursor(9, 15)
call testify#assert#equals(getline('.'), '/* tmf: $4,2=Sum(1:3); $5,2=Sum(1:-1) */')
endfunction
call testify#it('Should Add a formula to the table correctly', function('s:TestAddFormula'))

View File

@@ -0,0 +1,18 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/formula/formula.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestEvalFormula()
call cursor(7, 15)
call tablemode#spreadsheet#formula#EvaluateFormulaLine()
call testify#assert#equals(&modified, 1)
let cell_value = tablemode#spreadsheet#cell#GetCell()
call testify#assert#equals(cell_value, '125.0')
endfunction
call testify#it('Should evaluate the formula correctly', function('s:TestEvalFormula'))

View File

@@ -0,0 +1,18 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/table/sample_for_header.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestAddBorder()
call testify#assert#assert(!tablemode#table#IsHeader(2))
call tablemode#table#AddBorder(3)
call testify#assert#assert(tablemode#table#IsHeader(2))
call testify#assert#assert(tablemode#table#IsBorder(3))
call utils#TestUndo(s:test_file)
endfunction
call testify#it('AddBorder should be able to add borders correctly', function('s:TestAddBorder'))

View File

@@ -0,0 +1,37 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/table/sample_for_header_unicode.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestAddBorder()
call tablemode#table#AddBorder(2)
call tablemode#table#AddBorder(4)
call tablemode#table#AddBorder(6)
call tablemode#table#AddBorder(8)
call tablemode#table#AddBorder(10)
call testify#assert#assert(tablemode#table#IsHeader(3))
call testify#assert#assert(tablemode#table#IsBorder(2))
call testify#assert#assert(tablemode#table#IsBorder(4))
call testify#assert#assert(tablemode#table#IsBorder(6))
call testify#assert#assert(tablemode#table#IsBorder(8))
call testify#assert#assert(tablemode#table#IsBorder(10))
call testify#assert#equals(tablemode#utils#StrDisplayWidth(getline(2)), tablemode#utils#StrDisplayWidth(getline(3)))
call testify#assert#equals(tablemode#utils#StrDisplayWidth(getline(3)), tablemode#utils#StrDisplayWidth(getline(4)))
call testify#assert#equals(tablemode#utils#StrDisplayWidth(getline(4)), tablemode#utils#StrDisplayWidth(getline(5)))
call testify#assert#equals(tablemode#utils#StrDisplayWidth(getline(5)), tablemode#utils#StrDisplayWidth(getline(6)))
call testify#assert#equals(tablemode#utils#StrDisplayWidth(getline(6)), tablemode#utils#StrDisplayWidth(getline(7)))
call testify#assert#equals(tablemode#utils#StrDisplayWidth(getline(7)), tablemode#utils#StrDisplayWidth(getline(8)))
call testify#assert#equals(tablemode#utils#StrDisplayWidth(getline(8)), tablemode#utils#StrDisplayWidth(getline(9)))
call testify#assert#equals(tablemode#utils#StrDisplayWidth(getline(9)), tablemode#utils#StrDisplayWidth(getline(10)))
call utils#TestUndo(s:test_file)
endfunction
call testify#it('AddBorder should be able to add borders correctly with unicode characters', function('s:TestAddBorder'))

View File

@@ -0,0 +1,21 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/table/sample_with_header.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestIsBorder()
call testify#assert#assert(tablemode#table#IsBorder(2))
call testify#assert#assert(tablemode#table#IsBorder(4))
call testify#assert#assert(tablemode#table#IsBorder(7))
call testify#assert#assert(!tablemode#table#IsBorder(1))
call testify#assert#assert(!tablemode#table#IsBorder(3))
call testify#assert#assert(!tablemode#table#IsBorder(5))
call testify#assert#assert(!tablemode#table#IsBorder(6))
endfunction
call testify#it('IsBorder should be correct', function('s:TestIsBorder'))

View File

@@ -0,0 +1,21 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/table/sample_with_header.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestIsHeader()
call testify#assert#assert(tablemode#table#IsHeader(3))
call testify#assert#assert(!tablemode#table#IsHeader(1))
call testify#assert#assert(!tablemode#table#IsHeader(2))
call testify#assert#assert(!tablemode#table#IsHeader(4))
call testify#assert#assert(!tablemode#table#IsHeader(5))
call testify#assert#assert(!tablemode#table#IsHeader(6))
call testify#assert#assert(!tablemode#table#IsHeader(7))
endfunction
call testify#it('IsHeader should be correct', function('s:TestIsHeader'))

View File

@@ -0,0 +1,18 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/table/sample.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestIsRow()
call testify#assert#assert(tablemode#table#IsRow(3))
call testify#assert#assert(tablemode#table#IsRow(4))
call testify#assert#assert(!tablemode#table#IsRow(1))
call testify#assert#assert(!tablemode#table#IsRow(5))
endfunction
call testify#it('IsRow should be correct', function('s:TestIsRow'))

View File

@@ -0,0 +1,25 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/table/sample_with_header.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestIsTable()
" when on row
call testify#assert#assert(tablemode#table#IsTable(2))
call testify#assert#assert(tablemode#table#IsTable(4))
call testify#assert#assert(tablemode#table#IsTable(7))
" when on border
call testify#assert#assert(tablemode#table#IsTable(3))
call testify#assert#assert(tablemode#table#IsTable(5))
call testify#assert#assert(tablemode#table#IsTable(6))
" when not in a table
call testify#assert#assert(!tablemode#table#IsTable(1))
endfunction
call testify#it('IsTable should be correct', function('s:TestIsTable'))

View File

@@ -0,0 +1,16 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/table/sample_realign_before.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestRealign()
call tablemode#table#Realign(2)
call testify#assert#equals(getline(2, '$'), readfile('t/fixtures/table/sample_realign_after.txt'))
call utils#TestUndo(s:test_file)
endfunction
call testify#it('Realign should align table properly', function('s:TestRealign'))

View File

@@ -0,0 +1,16 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/table/sample_header_realign_before.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestRealign()
call tablemode#table#Realign(2)
call testify#assert#equals(getline(2, '$'), readfile('t/fixtures/table/sample_header_realign_after.txt'))
call utils#TestUndo(s:test_file)
endfunction
call testify#it('Realign should align table properly with header realignments', function('s:TestRealign'))

View File

@@ -0,0 +1,16 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/table/sample_header_realign_unicode_before.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestRealign()
call tablemode#table#Realign(2)
call testify#assert#equals(getline(2, '$'), readfile('t/fixtures/table/sample_header_realign_unicode_after.txt'))
call utils#TestUndo(s:test_file)
endfunction
call testify#it('Realign should align table properly with header realignments and unicode characters', function('s:TestRealign'))

View File

@@ -0,0 +1,16 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/table/sample_realign_unicode_before.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestRealign()
call tablemode#table#Realign(2)
call testify#assert#equals(getline(2, '$'), readfile('t/fixtures/table/sample_realign_unicode_after.txt'))
call utils#TestUndo(s:test_file)
endfunction
call testify#it('Realign should align table properly with unicode characters', function('s:TestRealign'))

View File

@@ -0,0 +1,27 @@
source t/config/options.vim
source t/utils.vim
let s:test_file = 't/fixtures/tableize.txt'
function! s:setup()
call utils#TestSetup(s:test_file)
endfunction
call testify#setup(function('s:setup'))
call testify#teardown(function('utils#TestTeardown'))
function! s:TestTabelize()
:3,4call tablemode#TableizeRange('')
call testify#assert#assert(tablemode#table#IsRow(3))
call testify#assert#equals(tablemode#spreadsheet#RowCount(3), 2)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount(3), 3)
call utils#TestUndo(s:test_file)
endfunction
call testify#it('Tableize should tableize with default delimiter correctly', function('s:TestTabelize'))
function! s:TestTabelizeCustomDelimiter()
:3,4call tablemode#TableizeRange('/;')
call testify#assert#assert(tablemode#table#IsRow(3))
call testify#assert#equals(tablemode#spreadsheet#RowCount(3), 2)
call testify#assert#equals(tablemode#spreadsheet#ColumnCount(3), 2)
call utils#TestUndo(s:test_file)
endfunction
call testify#it('Tableize should tableize with custom delimiter correctly', function('s:TestTabelizeCustomDelimiter'))

View File

@@ -0,0 +1,24 @@
source t/config/options.vim
function! s:TestTablemodeEnable()
silent call tablemode#Enable()
call testify#assert#assert(b:table_mode_active)
endfunction
call testify#it('tablemode#Enable should work', function('s:TestTablemodeEnable'))
function! s:TestTablemodeDisable()
silent call tablemode#Disable()
call testify#assert#assert(!b:table_mode_active)
endfunction
call testify#it('tablemode#Disable should work', function('s:TestTablemodeDisable'))
function! s:TestTablemodeToggle()
if exists('b:table_mode_active')
call testify#assert#assert(!b:table_mode_active)
endif
silent call tablemode#Toggle()
call testify#assert#assert(b:table_mode_active)
silent call tablemode#Toggle()
call testify#assert#assert(!b:table_mode_active)
endfunction
call testify#it('tablemode#Toggle should work', function('s:TestTablemodeToggle'))