mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 11:03:47 -05:00
Added tests for formula evaluation
* Minor fixes as detected by the tests
This commit is contained in:
@@ -233,7 +233,7 @@ endfunction
|
||||
" tablemode#spreadsheet#GetCells(row) - Get values of all cells in a row as a List.
|
||||
" tablemode#spreadsheet#GetCells(0, col) - Get values of all cells in a column as a List.
|
||||
" tablemode#spreadsheet#GetCells(row, col) - Get the value of table cell by given row, col.
|
||||
function! tablemode#spreadsheet#GetCells(line, ...) abort "{{{2
|
||||
function! tablemode#spreadsheet#GetCells(line, ...) abort
|
||||
let line = tablemode#utils#line(a:line)
|
||||
|
||||
if tablemode#table#IsATableRow(line)
|
||||
@@ -281,12 +281,12 @@ endfunction
|
||||
|
||||
function! tablemode#spreadsheet#GetCell(...) "{{{2
|
||||
if a:0 == 0
|
||||
let [row, colm] = [tablemode#RowNr('.'), tablemode#spreadsheet#ColumnNr('.')]
|
||||
let [row, colm] = [tablemode#spreadsheet#RowNr('.'), tablemode#spreadsheet#ColumnNr('.')]
|
||||
elseif a:0 == 2
|
||||
let [row, colm] = [a:1, a:2]
|
||||
endif
|
||||
|
||||
return tablemode#spreadsheet#GetCells('.', row, col)
|
||||
return tablemode#spreadsheet#GetCells('.', row, colm)
|
||||
endfunction
|
||||
|
||||
function! tablemode#spreadsheet#GetRow(row, ...) abort "{{{2
|
||||
@@ -418,8 +418,8 @@ function! tablemode#spreadsheet#Average(range, ...) abort "{{{2
|
||||
return s:Average(call('tablemode#spreadsheet#GetCellRange', args))
|
||||
endfunction
|
||||
|
||||
function! tablemode#spreadsheet#AddFormula() "{{{2
|
||||
let fr = input('f=')
|
||||
function! tablemode#spreadsheet#AddFormula(...) "{{{2
|
||||
let fr = a:0 ? a:1 : input('f=')
|
||||
let row = tablemode#spreadsheet#RowNr('.')
|
||||
let colm = tablemode#spreadsheet#ColumnNr('.')
|
||||
let indent = indent('.')
|
||||
|
||||
7
t/fixtures/formula/formula.txt
Normal file
7
t/fixtures/formula/formula.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
| Item | Cost |
|
||||
|----------+-------|
|
||||
| Bread | 20 |
|
||||
| Tomatoes | 5 |
|
||||
| Pasta | 100 |
|
||||
| Total | 0 |
|
||||
/* tmf: $5,2=Sum(1:-1) */
|
||||
7
t/fixtures/formula/sample.txt
Normal file
7
t/fixtures/formula/sample.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
| Item | Cost |
|
||||
|----------+------|
|
||||
| Bread | 20 |
|
||||
| Tomatoes | 5 |
|
||||
| Pasta | 100 |
|
||||
| Total | |
|
||||
| Test | |
|
||||
@@ -93,4 +93,41 @@ describe 'spreadsheet'
|
||||
call tablemode#spreadsheet#DeleteColumn()
|
||||
Expect tablemode#spreadsheet#ColumnCount('.') == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Formulas'
|
||||
describe 'Add Formula'
|
||||
before
|
||||
new
|
||||
read t/fixtures/formula/sample.txt
|
||||
end
|
||||
|
||||
it 'should add a formula successfully'
|
||||
call cursor(6, 15)
|
||||
call tablemode#spreadsheet#AddFormula("Sum(1:4)")
|
||||
Expect tablemode#spreadsheet#GetCell() == '125.0'
|
||||
call cursor(8, 15)
|
||||
Expect getline('.') == '/* tmf: $5,2=Sum(1:4) */'
|
||||
|
||||
call cursor(7, 15)
|
||||
call tablemode#spreadsheet#AddFormula("Sum(1:-1)")
|
||||
Expect tablemode#spreadsheet#GetCell() == '250.0'
|
||||
call cursor(8, 15)
|
||||
Expect getline('.') == '/* tmf: $5,2=Sum(1:4) ; $6,2=Sum(1:-1) */'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Evaluate Formula'
|
||||
before
|
||||
new
|
||||
read t/fixtures/formula/formula.txt
|
||||
end
|
||||
|
||||
it 'should evaluate the formula successfull'
|
||||
call cursor(6, 15)
|
||||
call tablemode#spreadsheet#EvaluateFormulaLine()
|
||||
Expect &modified == 1
|
||||
Expect tablemode#spreadsheet#GetCell() == '125.0'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user