Added tests for formula evaluation

* Minor fixes as detected by the tests
This commit is contained in:
Dhruva Sagar
2014-04-09 08:09:28 +05:30
parent 1ef8c812d6
commit f91782fca2
4 changed files with 56 additions and 5 deletions

View File

@@ -0,0 +1,7 @@
| Item | Cost |
|----------+-------|
| Bread | 20 |
| Tomatoes | 5 |
| Pasta | 100 |
| Total | 0 |
/* tmf: $5,2=Sum(1:-1) */

View File

@@ -0,0 +1,7 @@
| Item | Cost |
|----------+------|
| Bread | 20 |
| Tomatoes | 5 |
| Pasta | 100 |
| Total | |
| Test | |

View File

@@ -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