diff options
author | Karel Kočí <cynerd@email.cz> | 2016-06-30 16:03:25 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2016-06-30 16:03:25 +0200 |
commit | e573b3020c032400eed60b649a2cbf55266e6bb0 (patch) | |
tree | 8f572394ac8433529c7a8e70d160a2fbe8268b4e /vim/bundle/vim-table-mode/t | |
parent | b8c667bd64b3edd38d56c63c5bd1db53a23b4499 (diff) | |
download | myconfigs-e573b3020c032400eed60b649a2cbf55266e6bb0.tar.gz myconfigs-e573b3020c032400eed60b649a2cbf55266e6bb0.tar.bz2 myconfigs-e573b3020c032400eed60b649a2cbf55266e6bb0.zip |
Add current configurations from old repository
Diffstat (limited to 'vim/bundle/vim-table-mode/t')
29 files changed, 702 insertions, 0 deletions
diff --git a/vim/bundle/vim-table-mode/t/align.vim b/vim/bundle/vim-table-mode/t/align.vim new file mode 100644 index 0000000..930504d --- /dev/null +++ b/vim/bundle/vim-table-mode/t/align.vim @@ -0,0 +1,20 @@ +" vim: fdm=indent +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 + +describe 'Align' + it 'should align table content correctly' + Expect tablemode#align#Align(ConvertLines2Dict(readfile('t/fixtures/align/simple_before.txt'))) == ConvertLines2Dict(readfile('t/fixtures/align/simple_after.txt')) + end + + it 'should align table content with unicode characters correctly' + Expect tablemode#align#Align(ConvertLines2Dict(readfile('t/fixtures/align/unicode_before.txt'))) == ConvertLines2Dict(readfile('t/fixtures/align/unicode_after.txt')) + end +end diff --git a/vim/bundle/vim-table-mode/t/cell.vim b/vim/bundle/vim-table-mode/t/cell.vim new file mode 100644 index 0000000..e3d03ed --- /dev/null +++ b/vim/bundle/vim-table-mode/t/cell.vim @@ -0,0 +1,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 diff --git a/vim/bundle/vim-table-mode/t/config/options.vim b/vim/bundle/vim-table-mode/t/config/options.vim new file mode 100644 index 0000000..99b5098 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/config/options.vim @@ -0,0 +1,27 @@ +let g:table_mode_corner = '+' +let g:table_mode_separator = '|' +let g:table_mode_fillchar = '-' +let g:table_mode_header_fillchar = '-' +let g:table_mode_map_prefix = '<Leader>t' +let g:table_mode_toggle_map = 'm' +let g:table_mode_always_active = 0 +let g:table_mode_delimiter = ',' +let g:table_mode_corner_corner = '|' +let g:table_mode_align_char = ':' +let g:table_mode_disable_mappings = 0 + +let g:table_mode_motion_up_map = '{<Bar>' +let g:table_mode_motion_down_map = '}<Bar>' +let g:table_mode_motion_left_map = '[<Bar>' +let g:table_mode_motion_right_map = ']<Bar>' + +let g:table_mode_cell_text_object_a_map = 'a<Bar>' +let g:table_mode_cell_text_object_i_map = 'i<Bar>' + +let g:table_mode_realign_map = '<Leader>tr' +let g:table_mode_delete_row_map = '<Leader>tdd' +let g:table_mode_delete_column_map = '<Leader>tdc' +let g:table_mode_add_formula_map = '<Leader>tfa' +let g:table_mode_eval_formula_map = '<Leader>tfe' +let g:table_mode_echo_cell_map = '<Leader>t?' +let g:table_mode_sort_map = '<Leader>ts' diff --git a/vim/bundle/vim-table-mode/t/fixtures/align/simple_after.txt b/vim/bundle/vim-table-mode/t/fixtures/align/simple_after.txt new file mode 100644 index 0000000..ed96f07 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/align/simple_after.txt @@ -0,0 +1,2 @@ +| This | is a | table | +| This | is also | a table | diff --git a/vim/bundle/vim-table-mode/t/fixtures/align/simple_before.txt b/vim/bundle/vim-table-mode/t/fixtures/align/simple_before.txt new file mode 100644 index 0000000..b483ea5 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/align/simple_before.txt @@ -0,0 +1,2 @@ +|This|is a|table| +|This|is also|a table| diff --git a/vim/bundle/vim-table-mode/t/fixtures/align/unicode_after.txt b/vim/bundle/vim-table-mode/t/fixtures/align/unicode_after.txt new file mode 100644 index 0000000..8778914 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/align/unicode_after.txt @@ -0,0 +1,2 @@ +| This | is 測試 | table | +| This | is also | a table | diff --git a/vim/bundle/vim-table-mode/t/fixtures/align/unicode_before.txt b/vim/bundle/vim-table-mode/t/fixtures/align/unicode_before.txt new file mode 100644 index 0000000..3edd654 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/align/unicode_before.txt @@ -0,0 +1,2 @@ +| This | is 測試 | table | +| This | is also | a table | diff --git a/vim/bundle/vim-table-mode/t/fixtures/cell/sample.txt b/vim/bundle/vim-table-mode/t/fixtures/cell/sample.txt new file mode 100644 index 0000000..9e670d5 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/cell/sample.txt @@ -0,0 +1,2 @@ +| 1 | 2 | +| 3 | 4 | diff --git a/vim/bundle/vim-table-mode/t/fixtures/formula/formula.txt b/vim/bundle/vim-table-mode/t/fixtures/formula/formula.txt new file mode 100644 index 0000000..ab2df91 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/formula/formula.txt @@ -0,0 +1,7 @@ +| Item | Cost | +|----------+-------| +| Bread | 20 | +| Tomatoes | 5 | +| Pasta | 100 | +| Total | 0 | +/* tmf: $4,2=Sum(1:-1) */ diff --git a/vim/bundle/vim-table-mode/t/fixtures/formula/sample.txt b/vim/bundle/vim-table-mode/t/fixtures/formula/sample.txt new file mode 100644 index 0000000..2920bbc --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/formula/sample.txt @@ -0,0 +1,7 @@ +| Item | Cost | +|----------+------| +| Bread | 20 | +| Tomatoes | 5 | +| Pasta | 100 | +| Total | | +| Test | | diff --git a/vim/bundle/vim-table-mode/t/fixtures/sample.txt b/vim/bundle/vim-table-mode/t/fixtures/sample.txt new file mode 100644 index 0000000..e447226 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/sample.txt @@ -0,0 +1,4 @@ + +| test11 | test12 | +| test21 | test22 | + diff --git a/vim/bundle/vim-table-mode/t/fixtures/table/sample.txt b/vim/bundle/vim-table-mode/t/fixtures/table/sample.txt new file mode 100644 index 0000000..e447226 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/table/sample.txt @@ -0,0 +1,4 @@ + +| test11 | test12 | +| test21 | test22 | + diff --git a/vim/bundle/vim-table-mode/t/fixtures/table/sample_for_header.txt b/vim/bundle/vim-table-mode/t/fixtures/table/sample_for_header.txt new file mode 100644 index 0000000..75f8f25 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/table/sample_for_header.txt @@ -0,0 +1,3 @@ +| test11 | test12 | + +| test21 | test22 | diff --git a/vim/bundle/vim-table-mode/t/fixtures/table/sample_for_header_unicode.txt b/vim/bundle/vim-table-mode/t/fixtures/table/sample_for_header_unicode.txt new file mode 100644 index 0000000..7b4e02a --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/table/sample_for_header_unicode.txt @@ -0,0 +1,9 @@ + +| abc | 测试长度 | 长测试 | + +| 长 | 测试测试测试测试 | 测试测试 | + +| 测试测试 | 测试 | 测试测测试 | + +| 测试测试测试 | 测试测试 | 测试 | + diff --git a/vim/bundle/vim-table-mode/t/fixtures/table/sample_header_realign_after.txt b/vim/bundle/vim-table-mode/t/fixtures/table/sample_header_realign_after.txt new file mode 100644 index 0000000..e4362a1 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/table/sample_header_realign_after.txt @@ -0,0 +1,4 @@ +| S. No | Title | Message | +|-------+:------+:-------:| +| 1 | t1 | msg1 | +| 2 | t2 | msg2 | diff --git a/vim/bundle/vim-table-mode/t/fixtures/table/sample_header_realign_before.txt b/vim/bundle/vim-table-mode/t/fixtures/table/sample_header_realign_before.txt new file mode 100644 index 0000000..1f65bfd --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/table/sample_header_realign_before.txt @@ -0,0 +1,4 @@ +|S. No|Title|Message| +|-----+:----+:-----:| +|1|t1|msg1| +|2|t2|msg2| diff --git a/vim/bundle/vim-table-mode/t/fixtures/table/sample_header_realign_unicode_after.txt b/vim/bundle/vim-table-mode/t/fixtures/table/sample_header_realign_unicode_after.txt new file mode 100644 index 0000000..4c70b01 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/table/sample_header_realign_unicode_after.txt @@ -0,0 +1,8 @@ +|--------------+------------------+------------| +| 测试测试 | 测试长度 | 长测试 | +|--------------+:----------------:+-----------:| +| abc | 测试长度 | 长测试 | +| 长 | 测试测试测试测试 | 测试测试 | +| 测试测试 | 测试 | 测试测测试 | +| 测试测试测试 | 测试测试 | 测试 | +|--------------+------------------+------------| diff --git a/vim/bundle/vim-table-mode/t/fixtures/table/sample_header_realign_unicode_before.txt b/vim/bundle/vim-table-mode/t/fixtures/table/sample_header_realign_unicode_before.txt new file mode 100644 index 0000000..67bf1db --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/table/sample_header_realign_unicode_before.txt @@ -0,0 +1,8 @@ +|--------+--------+------| +|测试测试|测试长度|长测试| +|--------+:------:+-----:| +|abc|测试长度|长测试| +|长|测试测试测试测试|测试测试| +|测试测试|测试|测试测测试| +|测试测试测试|测试测试|测试| +|------------+--------+----| diff --git a/vim/bundle/vim-table-mode/t/fixtures/table/sample_realign_after.txt b/vim/bundle/vim-table-mode/t/fixtures/table/sample_realign_after.txt new file mode 100644 index 0000000..e7fd9e1 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/table/sample_realign_after.txt @@ -0,0 +1,2 @@ +| test11 | test12 | +| test21 | test22 | diff --git a/vim/bundle/vim-table-mode/t/fixtures/table/sample_realign_before.txt b/vim/bundle/vim-table-mode/t/fixtures/table/sample_realign_before.txt new file mode 100644 index 0000000..d1b3499 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/table/sample_realign_before.txt @@ -0,0 +1,2 @@ +|test11|test12| +|test21|test22| diff --git a/vim/bundle/vim-table-mode/t/fixtures/table/sample_realign_unicode_after.txt b/vim/bundle/vim-table-mode/t/fixtures/table/sample_realign_unicode_after.txt new file mode 100644 index 0000000..b479b24 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/table/sample_realign_unicode_after.txt @@ -0,0 +1,4 @@ +| abc | 测试长度 | 长测试 | +| 长 | 测试测试测试测试 | 测试测试 | +| 测试测试 | 测试 | 测试测测试 | +| 测试测试测试 | 测试测试 | 测试 | diff --git a/vim/bundle/vim-table-mode/t/fixtures/table/sample_realign_unicode_before.txt b/vim/bundle/vim-table-mode/t/fixtures/table/sample_realign_unicode_before.txt new file mode 100644 index 0000000..8c3124f --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/table/sample_realign_unicode_before.txt @@ -0,0 +1,4 @@ +|abc|测试长度|长测试| +|长|测试测试测试测试|测试测试| +|测试测试|测试|测试测测试| +|测试测试测试|测试测试|测试| diff --git a/vim/bundle/vim-table-mode/t/fixtures/table/sample_with_header.txt b/vim/bundle/vim-table-mode/t/fixtures/table/sample_with_header.txt new file mode 100644 index 0000000..9213e7f --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/table/sample_with_header.txt @@ -0,0 +1,7 @@ +|--------+---------| +| Title | Message | +|--------+---------| +| test11 | test12 | +| test21 | test22 | +|--------+---------| + diff --git a/vim/bundle/vim-table-mode/t/fixtures/tableize.txt b/vim/bundle/vim-table-mode/t/fixtures/tableize.txt new file mode 100644 index 0000000..ee1cc7a --- /dev/null +++ b/vim/bundle/vim-table-mode/t/fixtures/tableize.txt @@ -0,0 +1,4 @@ + +asd,asd;asd,asd +asd,asd;asd,asd + diff --git a/vim/bundle/vim-table-mode/t/formula.vim b/vim/bundle/vim-table-mode/t/formula.vim new file mode 100644 index 0000000..a052392 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/formula.vim @@ -0,0 +1,39 @@ +" vim: fdm=indent +source t/config/options.vim + +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#formula#Add("Sum(1:3)") + Expect tablemode#spreadsheet#cell#GetCell() == '125.0' + call cursor(8, 15) + Expect getline('.') == '/* tmf: $4,2=Sum(1:3) */' + + call cursor(7, 15) + call tablemode#spreadsheet#formula#Add("Sum(1:-1)") + Expect tablemode#spreadsheet#cell#GetCell() == '250.0' + call cursor(8, 15) + Expect getline('.') == '/* tmf: $4,2=Sum(1:3); $5,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#formula#EvaluateFormulaLine() + Expect &modified == 1 + Expect tablemode#spreadsheet#cell#GetCell() == '125.0' + end + end +end diff --git a/vim/bundle/vim-table-mode/t/spreadsheet.vim b/vim/bundle/vim-table-mode/t/spreadsheet.vim new file mode 100644 index 0000000..093475c --- /dev/null +++ b/vim/bundle/vim-table-mode/t/spreadsheet.vim @@ -0,0 +1,105 @@ +" vim: fdm=indent +source t/config/options.vim + +describe 'spreadsheet' + describe 'API' + before + new + read t/fixtures/sample.txt + 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 column number' + call cursor(2,3) + Expect tablemode#spreadsheet#ColumnNr('.') == 1 + call cursor(2,12) + Expect tablemode#spreadsheet#ColumnNr('.') == 2 + end + + it 'should return true when in the first cell' + call cursor(2,3) + Expect tablemode#spreadsheet#IsFirstCell() to_be_true + call cursor(2,12) + Expect tablemode#spreadsheet#IsFirstCell() to_be_false + end + + it 'should return true when in the last cell' + call cursor(2,3) + Expect tablemode#spreadsheet#IsLastCell() to_be_false + call cursor(2,12) + Expect tablemode#spreadsheet#IsLastCell() to_be_true + 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 + + describe 'Math' + before + new + read t/fixtures/cell/sample.txt + end + + it 'should return the sum of cell range' + call cursor(1,3) + Expect tablemode#spreadsheet#Sum('1:2') == 4.0 + Expect tablemode#spreadsheet#Sum('1,1:1,2') == 3.0 + Expect tablemode#spreadsheet#Sum('1,1:2,2') == 10.0 + call cursor(2,7) + Expect tablemode#spreadsheet#Sum('1:2') == 6.0 + Expect tablemode#spreadsheet#Sum('2,1:2,2') == 7.0 + end + + it 'should return the average of cell range' + call cursor(1,3) + Expect tablemode#spreadsheet#Average('1:2') == 2.0 + Expect tablemode#spreadsheet#Average('1,1:1,2') == 1.5 + Expect tablemode#spreadsheet#Average('1,1:2,2') == 5.0 + call cursor(2,7) + Expect tablemode#spreadsheet#Average('1:2') == 3.0 + Expect tablemode#spreadsheet#Average('2,1:2,2') == 3.5 + end + end + end + + describe 'Manipulations' + before + new + normal! ggdG + read t/fixtures/sample.txt + call cursor(2, 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 + end + end +end diff --git a/vim/bundle/vim-table-mode/t/table.vim b/vim/bundle/vim-table-mode/t/table.vim new file mode 100644 index 0000000..516467c --- /dev/null +++ b/vim/bundle/vim-table-mode/t/table.vim @@ -0,0 +1,184 @@ +" vim: fdm=indent +source t/config/options.vim + +describe 'table' + describe 'IsRow' + before + new + normal! ggdG + read t/fixtures/table/sample.txt + end + + it 'should be true when on a table row' + Expect tablemode#table#IsRow(2) to_be_true + Expect tablemode#table#IsRow(3) to_be_true + end + + it 'should be false when not on a table row' + Expect tablemode#table#IsRow(1) to_be_false + Expect tablemode#table#IsRow(4) to_be_false + end + end + + describe 'IsBorder' + before + new + normal! ggdG + read t/fixtures/table/sample_with_header.txt + end + + it 'should be true on a table border' + Expect tablemode#table#IsBorder(1) to_be_true + Expect tablemode#table#IsBorder(3) to_be_true + Expect tablemode#table#IsBorder(6) to_be_true + end + + it 'should be false when not on a table border' + Expect tablemode#table#IsBorder(2) to_be_false + Expect tablemode#table#IsBorder(4) to_be_false + Expect tablemode#table#IsBorder(5) to_be_false + end + end + + describe 'IsTable' + before + new normal! ggdG + read t/fixtures/table/sample_with_header.txt + end + + it 'should be true on a table row' + Expect tablemode#table#IsTable(2) to_be_true + Expect tablemode#table#IsTable(4) to_be_true + Expect tablemode#table#IsTable(5) to_be_true + end + + it 'should be true when on a table border' + Expect tablemode#table#IsTable(1) to_be_true + Expect tablemode#table#IsTable(3) to_be_true + Expect tablemode#table#IsTable(6) to_be_true + end + + it 'should not be true when not on a table' + Expect tablemode#table#IsTable(7) to_be_false + end + end + + describe 'IsHeader' + before + new + normal! ggdG + read t/fixtures/table/sample_with_header.txt + end + + it 'should be true on the table header' + Expect tablemode#table#IsHeader(2) to_be_true + end + + it 'should be false anywhere else' + Expect tablemode#table#IsHeader(1) to_be_false + Expect tablemode#table#IsHeader(4) to_be_false + Expect tablemode#table#IsHeader(5) to_be_false + Expect tablemode#table#IsHeader(6) to_be_false + Expect tablemode#table#IsHeader(7) to_be_false + end + end + + describe 'AddBorder' + before + new + normal! ggdG + read t/fixtures/table/sample_for_header.txt + end + + it 'should add border to line' + call tablemode#table#AddBorder(2) + Expect tablemode#table#IsHeader(1) to_be_true + Expect tablemode#table#IsBorder(2) to_be_true + end + + describe 'for unicode' + before + new + normal! ggdG + read t/fixtures/table/sample_for_header_unicode.txt + end + + it 'should add border to line' + call tablemode#table#AddBorder(1) + call tablemode#table#AddBorder(3) + call tablemode#table#AddBorder(5) + call tablemode#table#AddBorder(7) + call tablemode#table#AddBorder(9) + + Expect tablemode#table#IsBorder(1) to_be_true + Expect tablemode#utils#StrDisplayWidth(getline(1)) == tablemode#utils#StrDisplayWidth(getline(2)) + Expect tablemode#table#IsBorder(3) to_be_true + Expect tablemode#utils#StrDisplayWidth(getline(3)) == tablemode#utils#StrDisplayWidth(getline(4)) + Expect tablemode#table#IsBorder(5) to_be_true + Expect tablemode#utils#StrDisplayWidth(getline(5)) == tablemode#utils#StrDisplayWidth(getline(6)) + Expect tablemode#table#IsBorder(7) to_be_true + Expect tablemode#utils#StrDisplayWidth(getline(7)) == tablemode#utils#StrDisplayWidth(getline(8)) + Expect tablemode#table#IsBorder(9) to_be_true + Expect tablemode#utils#StrDisplayWidth(getline(9)) == tablemode#utils#StrDisplayWidth(getline(8)) + end + end + end + + describe 'Realign' + describe 'without header alignments' + describe 'for simple' + before + new + normal! ggdG + read t/fixtures/table/sample_realign_before.txt + end + + it 'should be aligned properly' + call tablemode#table#Realign(1) + Expect getline(1,'$') == readfile('t/fixtures/table/sample_realign_after.txt') + end + end + + describe 'for unicode' + before + new + normal! ggdG + read t/fixtures/table/sample_realign_unicode_before.txt + end + + it 'should be aligned properly' + call tablemode#table#Realign(1) + Expect getline(1,'$') == readfile('t/fixtures/table/sample_realign_unicode_after.txt') + end + end + end + + describe 'with header alignments' + describe 'for simple' + before + new + normal! ggdG + read t/fixtures/table/sample_header_realign_before.txt + end + + it 'should be aligned properly' + call tablemode#table#Realign(1) + Expect getline(1,'$') == readfile('t/fixtures/table/sample_header_realign_after.txt') + end + end + + describe 'for unicode' + before + new + normal! ggdG + read t/fixtures/table/sample_header_realign_unicode_before.txt + end + + it 'should be aligned properly' + call tablemode#table#Realign(1) + Expect getline(1,'$') == readfile('t/fixtures/table/sample_header_realign_unicode_after.txt') + end + end + end + end +end diff --git a/vim/bundle/vim-table-mode/t/tablemode.vim b/vim/bundle/vim-table-mode/t/tablemode.vim new file mode 100644 index 0000000..132c4bb --- /dev/null +++ b/vim/bundle/vim-table-mode/t/tablemode.vim @@ -0,0 +1,56 @@ +" vim: fdm=indent +source t/config/options.vim + +describe 'tablemode' + describe 'Activation' + describe 'tablemode#Enable()' + before + call tablemode#Enable() + end + + it 'should enable table mode' + Expect b:table_mode_active to_be_true + end + end + + describe 'tablemode#Disable()' + before + call tablemode#Disable() + end + + it 'should disable table mode' + Expect b:table_mode_active to_be_false + end + end + + describe 'tablemode#Toggle()' + it 'should toggle table mode' + call tablemode#Toggle() + Expect b:table_mode_active to_be_true + call tablemode#Toggle() + Expect b:table_mode_active to_be_false + end + end + end + + describe 'Tableize' + before + new + read t/fixtures/tableize.txt + end + + it 'should tableize with default delimiter' + :2,3call tablemode#TableizeRange('') + Expect tablemode#table#IsRow(2) to_be_true + Expect tablemode#spreadsheet#RowCount(2) == 2 + Expect tablemode#spreadsheet#ColumnCount(2) == 3 + end + + it 'should tableize with given delimiter' + :2,3call tablemode#TableizeRange('/;') + Expect tablemode#table#IsRow(2) to_be_true + Expect tablemode#spreadsheet#RowCount(2) == 2 + Expect tablemode#spreadsheet#ColumnCount(2) == 2 + end + end +end diff --git a/vim/bundle/vim-table-mode/t/utils.vim b/vim/bundle/vim-table-mode/t/utils.vim new file mode 100644 index 0000000..3bfff19 --- /dev/null +++ b/vim/bundle/vim-table-mode/t/utils.vim @@ -0,0 +1,45 @@ +" vim: fdm=indent +source t/config/options.vim + +describe 'utils' + describe 'line' + it 'should return the current line number' + Expect tablemode#utils#line('.') == line('.') + end + + it 'should return the line number itself if it is a number' + Expect tablemode#utils#line(1) == 1 + end + end + + describe 'strip' + it 'should strip all initial or trailing whitespace from a string' + let string = ' This is awesome ' + Expect tablemode#utils#strip(string) == 'This is awesome' + end + end + + describe 'strlen' + it 'should return the length of a string correctly' + let string = 'this is a test' + Expect tablemode#utils#strlen(string) == 14 + end + + it 'should return the length of a unicode string correctly' + let string = '測試 is good.' + Expect tablemode#utils#strlen(string) == 11 + end + end + + describe 'strdisplaywidth' + it 'should return the display width of a string correctly' + let string = 'this is a test' + Expect tablemode#utils#StrDisplayWidth(string) == 14 + end + + it 'should return the display width of a unicode string correctly' + let string = '測試 is good.' + Expect tablemode#utils#StrDisplayWidth(string) == 13 + end + end +end |