From 7ec0b83dbdb21e74212ce11a99711d19e229caa3 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 07:22:48 +0530 Subject: [PATCH 01/23] Rewrite tests with vim-testify --- .github/workflows/ci.yml | 39 ++ Gemfile | 6 - Gemfile.lock | 24 -- Rakefile | 13 - VimFlavor.lock | 1 - autoload/tablemode/spreadsheet/cell.vim | 2 +- t/align.vim | 20 - t/autoload/tablemode/align_test.vim | 23 ++ .../tablemode/spreadsheet/api/count_test.vim | 194 ++++++++++ .../spreadsheet/api/manipulation_test.vim | 52 +++ ...tion_with_escaped_table_separator_test.vim | 51 +++ .../api/manipulation_with_headers_test.vim | 53 +++ .../api/manipulation_with_unicode_test.vim | 47 +++ .../tablemode/spreadsheet/api/math_test.vim | 141 ++++++++ .../api/repeated_manipulations_test.vim | 49 +++ t/autoload/tablemode/spreadsheet/api/test.vim | 66 ++++ .../tablemode/spreadsheet/cell_test.vim | 208 +++++++++++ .../spreadsheet/formula/add_test.vim | 28 ++ .../spreadsheet/formula/eval_test.vim | 18 + .../tablemode/table/add_border_test.vim | 18 + .../table/add_border_with_unicode_test.vim | 37 ++ t/autoload/tablemode/table/is_border_test.vim | 21 ++ t/autoload/tablemode/table/is_header_test.vim | 21 ++ t/autoload/tablemode/table/is_row_test.vim | 18 + t/autoload/tablemode/table/is_table_test.vim | 25 ++ t/autoload/tablemode/table/realign_test.vim | 16 + .../realign_with_header_alignments_test.vim | 16 + ...h_header_realignments_and_unicode_test.vim | 16 + .../table/realign_with_unicode_test.vim | 16 + t/autoload/tablemode_tableize_test.vim | 27 ++ t/autoload/tablemode_test.vim | 24 ++ t/cell.vim | 135 ------- t/formula.vim | 39 -- t/spreadsheet.vim | 341 ------------------ t/table.vim | 184 ---------- t/tablemode.vim | 56 --- t/utils.vim | 58 +-- 37 files changed, 1241 insertions(+), 862 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 Gemfile delete mode 100644 Gemfile.lock delete mode 100644 Rakefile delete mode 100644 VimFlavor.lock delete mode 100644 t/align.vim create mode 100644 t/autoload/tablemode/align_test.vim create mode 100644 t/autoload/tablemode/spreadsheet/api/count_test.vim create mode 100644 t/autoload/tablemode/spreadsheet/api/manipulation_test.vim create mode 100644 t/autoload/tablemode/spreadsheet/api/manipulation_with_escaped_table_separator_test.vim create mode 100644 t/autoload/tablemode/spreadsheet/api/manipulation_with_headers_test.vim create mode 100644 t/autoload/tablemode/spreadsheet/api/manipulation_with_unicode_test.vim create mode 100644 t/autoload/tablemode/spreadsheet/api/math_test.vim create mode 100644 t/autoload/tablemode/spreadsheet/api/repeated_manipulations_test.vim create mode 100644 t/autoload/tablemode/spreadsheet/api/test.vim create mode 100644 t/autoload/tablemode/spreadsheet/cell_test.vim create mode 100644 t/autoload/tablemode/spreadsheet/formula/add_test.vim create mode 100644 t/autoload/tablemode/spreadsheet/formula/eval_test.vim create mode 100644 t/autoload/tablemode/table/add_border_test.vim create mode 100644 t/autoload/tablemode/table/add_border_with_unicode_test.vim create mode 100644 t/autoload/tablemode/table/is_border_test.vim create mode 100644 t/autoload/tablemode/table/is_header_test.vim create mode 100644 t/autoload/tablemode/table/is_row_test.vim create mode 100644 t/autoload/tablemode/table/is_table_test.vim create mode 100644 t/autoload/tablemode/table/realign_test.vim create mode 100644 t/autoload/tablemode/table/realign_with_header_alignments_test.vim create mode 100644 t/autoload/tablemode/table/realign_with_header_realignments_and_unicode_test.vim create mode 100644 t/autoload/tablemode/table/realign_with_unicode_test.vim create mode 100644 t/autoload/tablemode_tableize_test.vim create mode 100644 t/autoload/tablemode_test.vim delete mode 100644 t/cell.vim delete mode 100644 t/formula.vim delete mode 100644 t/spreadsheet.vim delete mode 100644 t/table.vim delete mode 100644 t/tablemode.vim diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..24999c9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +name: CI + +on: + push: + branches: + - master + - feature/switch-to-vim-testify + pull_request: + branches: + - master + - feature/switch-to-vim-testify + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + tests: + name: Vim Table Mode Tests + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + neovim: [false, true] + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v3 + + - name: Install Vim or neovim + uses: rhysd/action-setup-vim@v1 + id: vim + with: + neovim: ${{ matrix.neovim }} + + - name: Run unit tests + env: + VIM: ${{ steps.vim.outputs.executable }} + run: ${VIM} +"set hidden" +TestifySuite diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 88e2ea1..0000000 --- a/Gemfile +++ /dev/null @@ -1,6 +0,0 @@ -source 'https://rubygems.org' - -ruby '3.0.0' - -gem 'rake' -gem 'vim-flavor', '~> 1.1' diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index b449c58..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,24 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - blankslate (2.1.2.4) - parslet (1.5.0) - blankslate (~> 2.0) - rake (12.3.3) - thor (0.18.1) - vim-flavor (1.1.3) - parslet (~> 1.0) - thor (~> 0.14) - -PLATFORMS - ruby - -DEPENDENCIES - rake - vim-flavor (~> 1.1) - -RUBY VERSION - ruby 3.0.0p0 - -BUNDLED WITH - 2.2.3 diff --git a/Rakefile b/Rakefile deleted file mode 100644 index 557fee1..0000000 --- a/Rakefile +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env rake - -task :ci => [:dump, :test] - -task :dump do - sh 'vim --version' -end - -task :test do - sh 'bundle exec vim-flavor test' -end - -task :default => :test diff --git a/VimFlavor.lock b/VimFlavor.lock deleted file mode 100644 index d021597..0000000 --- a/VimFlavor.lock +++ /dev/null @@ -1 +0,0 @@ -kana/vim-vspec (1.1.2) diff --git a/autoload/tablemode/spreadsheet/cell.vim b/autoload/tablemode/spreadsheet/cell.vim index d1d912b..5e7e195 100644 --- a/autoload/tablemode/spreadsheet/cell.vim +++ b/autoload/tablemode/spreadsheet/cell.vim @@ -201,7 +201,7 @@ function! tablemode#spreadsheet#cell#TextObject(inner) "{{{2 endif endfunction function! tablemode#spreadsheet#cell#Motion(direction, ...) "{{{2 - let l:count = a:0 ? a:1 : v:count1 + let l:count = a:0 ? a:1 : (v:count + 1) if tablemode#table#IsRow('.') for ii in range(l:count) if a:direction ==# 'l' diff --git a/t/align.vim b/t/align.vim deleted file mode 100644 index 930504d..0000000 --- a/t/align.vim +++ /dev/null @@ -1,20 +0,0 @@ -" 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/t/autoload/tablemode/align_test.vim b/t/autoload/tablemode/align_test.vim new file mode 100644 index 0000000..d306930 --- /dev/null +++ b/t/autoload/tablemode/align_test.vim @@ -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')) diff --git a/t/autoload/tablemode/spreadsheet/api/count_test.vim b/t/autoload/tablemode/spreadsheet/api/count_test.vim new file mode 100644 index 0000000..37f3b40 --- /dev/null +++ b/t/autoload/tablemode/spreadsheet/api/count_test.vim @@ -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')) diff --git a/t/autoload/tablemode/spreadsheet/api/manipulation_test.vim b/t/autoload/tablemode/spreadsheet/api/manipulation_test.vim new file mode 100644 index 0000000..6091565 --- /dev/null +++ b/t/autoload/tablemode/spreadsheet/api/manipulation_test.vim @@ -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')) diff --git a/t/autoload/tablemode/spreadsheet/api/manipulation_with_escaped_table_separator_test.vim b/t/autoload/tablemode/spreadsheet/api/manipulation_with_escaped_table_separator_test.vim new file mode 100644 index 0000000..dba21c6 --- /dev/null +++ b/t/autoload/tablemode/spreadsheet/api/manipulation_with_escaped_table_separator_test.vim @@ -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')) diff --git a/t/autoload/tablemode/spreadsheet/api/manipulation_with_headers_test.vim b/t/autoload/tablemode/spreadsheet/api/manipulation_with_headers_test.vim new file mode 100644 index 0000000..97fb1b9 --- /dev/null +++ b/t/autoload/tablemode/spreadsheet/api/manipulation_with_headers_test.vim @@ -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')) diff --git a/t/autoload/tablemode/spreadsheet/api/manipulation_with_unicode_test.vim b/t/autoload/tablemode/spreadsheet/api/manipulation_with_unicode_test.vim new file mode 100644 index 0000000..2471016 --- /dev/null +++ b/t/autoload/tablemode/spreadsheet/api/manipulation_with_unicode_test.vim @@ -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')) diff --git a/t/autoload/tablemode/spreadsheet/api/math_test.vim b/t/autoload/tablemode/spreadsheet/api/math_test.vim new file mode 100644 index 0000000..1a8230b --- /dev/null +++ b/t/autoload/tablemode/spreadsheet/api/math_test.vim @@ -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')) diff --git a/t/autoload/tablemode/spreadsheet/api/repeated_manipulations_test.vim b/t/autoload/tablemode/spreadsheet/api/repeated_manipulations_test.vim new file mode 100644 index 0000000..971f951 --- /dev/null +++ b/t/autoload/tablemode/spreadsheet/api/repeated_manipulations_test.vim @@ -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:\call tablemode#spreadsheet#InsertColumn(0)\" + 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:\call tablemode#spreadsheet#InsertColumn(1)\" + 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')) diff --git a/t/autoload/tablemode/spreadsheet/api/test.vim b/t/autoload/tablemode/spreadsheet/api/test.vim new file mode 100644 index 0000000..1ed323a --- /dev/null +++ b/t/autoload/tablemode/spreadsheet/api/test.vim @@ -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')) diff --git a/t/autoload/tablemode/spreadsheet/cell_test.vim b/t/autoload/tablemode/spreadsheet/cell_test.vim new file mode 100644 index 0000000..79aeaaa --- /dev/null +++ b/t/autoload/tablemode/spreadsheet/cell_test.vim @@ -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')) diff --git a/t/autoload/tablemode/spreadsheet/formula/add_test.vim b/t/autoload/tablemode/spreadsheet/formula/add_test.vim new file mode 100644 index 0000000..25aa475 --- /dev/null +++ b/t/autoload/tablemode/spreadsheet/formula/add_test.vim @@ -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')) diff --git a/t/autoload/tablemode/spreadsheet/formula/eval_test.vim b/t/autoload/tablemode/spreadsheet/formula/eval_test.vim new file mode 100644 index 0000000..fba0172 --- /dev/null +++ b/t/autoload/tablemode/spreadsheet/formula/eval_test.vim @@ -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')) diff --git a/t/autoload/tablemode/table/add_border_test.vim b/t/autoload/tablemode/table/add_border_test.vim new file mode 100644 index 0000000..c6ea576 --- /dev/null +++ b/t/autoload/tablemode/table/add_border_test.vim @@ -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')) diff --git a/t/autoload/tablemode/table/add_border_with_unicode_test.vim b/t/autoload/tablemode/table/add_border_with_unicode_test.vim new file mode 100644 index 0000000..9005a78 --- /dev/null +++ b/t/autoload/tablemode/table/add_border_with_unicode_test.vim @@ -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')) diff --git a/t/autoload/tablemode/table/is_border_test.vim b/t/autoload/tablemode/table/is_border_test.vim new file mode 100644 index 0000000..44ee0ac --- /dev/null +++ b/t/autoload/tablemode/table/is_border_test.vim @@ -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')) diff --git a/t/autoload/tablemode/table/is_header_test.vim b/t/autoload/tablemode/table/is_header_test.vim new file mode 100644 index 0000000..9dfb169 --- /dev/null +++ b/t/autoload/tablemode/table/is_header_test.vim @@ -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')) diff --git a/t/autoload/tablemode/table/is_row_test.vim b/t/autoload/tablemode/table/is_row_test.vim new file mode 100644 index 0000000..623eb93 --- /dev/null +++ b/t/autoload/tablemode/table/is_row_test.vim @@ -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')) diff --git a/t/autoload/tablemode/table/is_table_test.vim b/t/autoload/tablemode/table/is_table_test.vim new file mode 100644 index 0000000..5fdfcd2 --- /dev/null +++ b/t/autoload/tablemode/table/is_table_test.vim @@ -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')) diff --git a/t/autoload/tablemode/table/realign_test.vim b/t/autoload/tablemode/table/realign_test.vim new file mode 100644 index 0000000..2f965e0 --- /dev/null +++ b/t/autoload/tablemode/table/realign_test.vim @@ -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')) diff --git a/t/autoload/tablemode/table/realign_with_header_alignments_test.vim b/t/autoload/tablemode/table/realign_with_header_alignments_test.vim new file mode 100644 index 0000000..130638a --- /dev/null +++ b/t/autoload/tablemode/table/realign_with_header_alignments_test.vim @@ -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')) diff --git a/t/autoload/tablemode/table/realign_with_header_realignments_and_unicode_test.vim b/t/autoload/tablemode/table/realign_with_header_realignments_and_unicode_test.vim new file mode 100644 index 0000000..79d077e --- /dev/null +++ b/t/autoload/tablemode/table/realign_with_header_realignments_and_unicode_test.vim @@ -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')) diff --git a/t/autoload/tablemode/table/realign_with_unicode_test.vim b/t/autoload/tablemode/table/realign_with_unicode_test.vim new file mode 100644 index 0000000..249fc05 --- /dev/null +++ b/t/autoload/tablemode/table/realign_with_unicode_test.vim @@ -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')) diff --git a/t/autoload/tablemode_tableize_test.vim b/t/autoload/tablemode_tableize_test.vim new file mode 100644 index 0000000..081711e --- /dev/null +++ b/t/autoload/tablemode_tableize_test.vim @@ -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')) diff --git a/t/autoload/tablemode_test.vim b/t/autoload/tablemode_test.vim new file mode 100644 index 0000000..a662e71 --- /dev/null +++ b/t/autoload/tablemode_test.vim @@ -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')) diff --git a/t/cell.vim b/t/cell.vim deleted file mode 100644 index e3d03ed..0000000 --- a/t/cell.vim +++ /dev/null @@ -1,135 +0,0 @@ -" 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/t/formula.vim b/t/formula.vim deleted file mode 100644 index a052392..0000000 --- a/t/formula.vim +++ /dev/null @@ -1,39 +0,0 @@ -" 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/t/spreadsheet.vim b/t/spreadsheet.vim deleted file mode 100644 index db8e2ff..0000000 --- a/t/spreadsheet.vim +++ /dev/null @@ -1,341 +0,0 @@ -" 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') == 2.5 - call cursor(2,7) - Expect tablemode#spreadsheet#Average('1:2') == 3.0 - Expect tablemode#spreadsheet#Average('2,1:2,2') == 3.5 - end - - it 'should return the min of cell range' - call cursor(1,3) - Expect tablemode#spreadsheet#Min('1:2') == 1.0 - Expect tablemode#spreadsheet#Min('1,1:1,2') == 1.0 - Expect tablemode#spreadsheet#Min('1,1:2,2') == 1.0 - call cursor(2,7) - Expect tablemode#spreadsheet#Min('1:2') == 2.0 - Expect tablemode#spreadsheet#Min('2,1:2,2') == 3.0 - end - - it 'should return the max of cell range' - call cursor(1,3) - Expect tablemode#spreadsheet#Max('1:2') == 3.0 - Expect tablemode#spreadsheet#Max('1,1:1,2') == 2.0 - Expect tablemode#spreadsheet#Max('1,1:2,2') == 4.0 - call cursor(2,7) - Expect tablemode#spreadsheet#Max('1:2') == 4.0 - Expect tablemode#spreadsheet#Max('2,1:2,2') == 4.0 - end - end - - describe 'Count' - before - new - read t/fixtures/cell/counts.txt - end - - it 'should return the count of empty cell range' - call cursor(1,3) - Expect tablemode#spreadsheet#CountE('1:3') == 1 - Expect tablemode#spreadsheet#CountE('1,1:1,3') == 0 - Expect tablemode#spreadsheet#CountE('2,1:2,3') == 2 - Expect tablemode#spreadsheet#CountE('1,1:3,3') == 2 - call cursor(3,11) - Expect tablemode#spreadsheet#CountE('1:3') == 1 - Expect tablemode#spreadsheet#CountE('3,1:3,3') == 0 - end - - it 'should return the count of not-empty cell range' - call cursor(1,3) - Expect tablemode#spreadsheet#CountNE('1:3') == 2 - Expect tablemode#spreadsheet#CountNE('1,1:1,3') == 3 - Expect tablemode#spreadsheet#CountNE('2,1:2,3') == 1 - Expect tablemode#spreadsheet#CountNE('1,1:3,3') == 7 - call cursor(3,11) - Expect tablemode#spreadsheet#CountNE('1:3') == 2 - Expect tablemode#spreadsheet#CountNE('3,1:3,3') == 3 - end - - it 'should return the percent count of empty cell range' - call cursor(1,3) - Expect tablemode#spreadsheet#PercentE('1:3') == 33 - Expect tablemode#spreadsheet#PercentE('1,1:1,3') == 0 - Expect tablemode#spreadsheet#PercentE('2,1:2,3') == 66 - Expect tablemode#spreadsheet#PercentE('1,1:3,3') == 22 - call cursor(3,11) - Expect tablemode#spreadsheet#PercentE('1:3') == 33 - Expect tablemode#spreadsheet#PercentE('3,1:3,3') == 0 - end - - it 'should return the percent count of not-empty cell range' - call cursor(1,3) - Expect tablemode#spreadsheet#PercentNE('1:3') == 66 - Expect tablemode#spreadsheet#PercentNE('1,1:1,3') == 100 - Expect tablemode#spreadsheet#PercentNE('2,1:2,3') == 33 - Expect tablemode#spreadsheet#PercentNE('1,1:3,3') == 77 - call cursor(3,11) - Expect tablemode#spreadsheet#PercentNE('1:3') == 66 - Expect tablemode#spreadsheet#PercentNE('3,1:3,3') == 100 - end - - it 'should return the average of not-empty cell range' - call cursor(1,3) - Expect tablemode#spreadsheet#AverageNE('1:3') == 2.5 - Expect tablemode#spreadsheet#AverageNE('1,1:1,3') == 2.0 - Expect tablemode#spreadsheet#AverageNE('2,1:2,3') == 0.0 - Expect tablemode#spreadsheet#AverageNE('1,1:3,3') == 3.0 - call cursor(3,11) - Expect tablemode#spreadsheet#AverageNE('1:3') == 4.5 - Expect tablemode#spreadsheet#AverageNE('3,1:3,3') == 5.0 - 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 - - it 'should successfully insert a column before the cursor' - Expect tablemode#spreadsheet#ColumnCount('.') == 2 - call tablemode#spreadsheet#InsertColumn(0) - Expect tablemode#spreadsheet#ColumnCount('.') == 3 - Expect getline('.') == '| | test11 | test12 |' - end - - it 'should successfully insert a column after the cursor' - normal! $ - Expect tablemode#spreadsheet#ColumnCount('.') == 2 - call tablemode#spreadsheet#InsertColumn(1) - Expect tablemode#spreadsheet#ColumnCount('.') == 3 - Expect getline('.') == '| test11 | test12 | |' - end - end - - describe 'Manipulation of tables with headers' - before - new - normal! ggdG - let g:table_mode_header_fillchar = '=' - read t/fixtures/complex_header.txt - call cursor(4, 7) - end - - it 'should successfully delete a row ' - Expect tablemode#spreadsheet#RowCount('.') == 5 - call tablemode#spreadsheet#DeleteRow() - Expect tablemode#spreadsheet#RowCount('.') == 4 - Expect getline(4) == '| 2 | 8 | b | y |' - end - - it 'should successfully delete a column' - Expect tablemode#spreadsheet#ColumnCount('.') == 4 - call tablemode#spreadsheet#DeleteColumn() - Expect tablemode#spreadsheet#ColumnCount('.') == 3 - Expect getline(4) == '| 9 | a | z |' - end - - it 'should successfully insert a column before the cursor' - Expect tablemode#spreadsheet#ColumnCount('.') == 4 - call tablemode#spreadsheet#InsertColumn(0) - Expect tablemode#spreadsheet#ColumnCount('.') == 5 - Expect getline(4) == '| | 1 | 9 | a | z |' - end - - it 'should successfully insert a column after the cursor' - normal! $ - Expect tablemode#spreadsheet#ColumnCount('.') == 4 - call tablemode#spreadsheet#InsertColumn(1) - Expect tablemode#spreadsheet#ColumnCount('.') == 5 - Expect getline(4) == '| 1 | 9 | a | z | |' - end - end - - describe 'Repeated Manipulations' - before - new - normal! ggdG - read t/fixtures/big_sample.txt - call cursor(2, 3) - end - - it 'should delete multiple rows correctly' - Expect tablemode#spreadsheet#RowCount('.') == 5 - .,.+1 call tablemode#spreadsheet#DeleteRow() - Expect tablemode#spreadsheet#RowCount('.') == 3 - end - - it 'should delete multiple columns correctly' - Expect tablemode#spreadsheet#ColumnCount('.') == 4 - .,.+1 call tablemode#spreadsheet#DeleteColumn() - Expect tablemode#spreadsheet#ColumnCount('.') == 2 - end - - it 'should insert multiple columns before the cursor correctly' - call cursor(2, 7) - Expect tablemode#spreadsheet#ColumnCount('.') == 4 - execute "normal! 2:\call tablemode#spreadsheet#InsertColumn(0)\" - Expect tablemode#spreadsheet#ColumnCount('.') == 6 - Expect getline('.') == '| 1 | | | 9 | a | z |' - end - - it 'should insert multiple columns after the cursor correctly' - call cursor(2, 7) - Expect tablemode#spreadsheet#ColumnCount('.') == 4 - execute "normal! 2:\call tablemode#spreadsheet#InsertColumn(1)\" - Expect tablemode#spreadsheet#ColumnCount('.') == 6 - Expect getline('.') == '| 1 | 9 | | | a | z |' - end - end - - describe 'Unicode table separators' - before - new - normal! ggdG - read t/fixtures/table/sample_realign_unicode_after.txt - call cursor(2, 19) - end - - it 'should not prevent the deletion of rows' - Expect tablemode#spreadsheet#RowCount('.') == 4 - call tablemode#spreadsheet#DeleteRow() - Expect tablemode#spreadsheet#RowCount('.') == 3 - end - - it 'should not prevent the deletion of columns' - Expect tablemode#spreadsheet#ColumnCount('.') == 3 - call tablemode#spreadsheet#DeleteColumn() - Expect tablemode#spreadsheet#ColumnCount('.') == 2 - end - - it 'should not prevent the insertion of columns before the cursor' - Expect tablemode#spreadsheet#ColumnCount('.') == 3 - call tablemode#spreadsheet#InsertColumn(1) - Expect tablemode#spreadsheet#ColumnCount('.') == 4 - end - - it 'should not prevent the insertion of columns after the cursor' - Expect tablemode#spreadsheet#ColumnCount('.') == 3 - call tablemode#spreadsheet#InsertColumn(1) - Expect tablemode#spreadsheet#ColumnCount('.') == 4 - end - end - - describe 'Escaped table separators' - before - new - normal! ggdG - read t/fixtures/escaped_seperator.txt - call cursor(2, 3) - end - - it 'should not prevent the deletion of rows' - Expect tablemode#spreadsheet#RowCount('.') == 7 - call tablemode#spreadsheet#DeleteRow() - Expect tablemode#spreadsheet#RowCount('.') == 6 - Expect getline('.') == '| a separator. | |' - end - - it 'should not prevent the deletion of columns' - Expect tablemode#spreadsheet#ColumnCount('.') == 2 - call tablemode#spreadsheet#DeleteColumn() - Expect tablemode#spreadsheet#ColumnCount('.') == 1 - Expect getline('.') == '| It can be escaped by a \. |' - end - - it 'should not prevent the insertion of columns' - Expect tablemode#spreadsheet#ColumnCount('.') == 2 - call tablemode#spreadsheet#InsertColumn(1) - Expect tablemode#spreadsheet#ColumnCount('.') == 3 - Expect getline('.') == '| The \| works as | | It can be escaped by a \. |' - end - end -end diff --git a/t/table.vim b/t/table.vim deleted file mode 100644 index 516467c..0000000 --- a/t/table.vim +++ /dev/null @@ -1,184 +0,0 @@ -" 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/t/tablemode.vim b/t/tablemode.vim deleted file mode 100644 index 132c4bb..0000000 --- a/t/tablemode.vim +++ /dev/null @@ -1,56 +0,0 @@ -" 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/t/utils.vim b/t/utils.vim index 3bfff19..fa64896 100644 --- a/t/utils.vim +++ b/t/utils.vim @@ -1,45 +1,19 @@ -" vim: fdm=indent -source t/config/options.vim +function! utils#TestSetup(file) abort + new + silent! exec 'read' a:file +endfunction -describe 'utils' - describe 'line' - it 'should return the current line number' - Expect tablemode#utils#line('.') == line('.') - end +function! utils#TestTeardown() abort + bw! +endfunction - it 'should return the line number itself if it is a number' - Expect tablemode#utils#line(1) == 1 - end - end +function! utils#TestUndo(file) abort + :%delete + silent! exec 'read' a:file +endfunction - 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 +function! utils#TableTest(tests) abort + for test in a:tests + call testify#assert#equals(test.actual, test.expected) + endfor +endfunction From e117bcdc7805fe3a5eb849e5d46da1a0f085e2d9 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 07:58:34 +0530 Subject: [PATCH 02/23] Add checkout vim-testify step to ci workflow --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24999c9..4a6efe1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,12 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Checkout vim-testify + uses: actions/checkout@v3 + with: + repository: dhruvasagar/vim-testify + path: pack/plugins/start/vim-testify + - name: Install Vim or neovim uses: rhysd/action-setup-vim@v1 id: vim From 88824e58401d7b76747cc174b5d29caff3bd8816 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 08:35:40 +0530 Subject: [PATCH 03/23] Try to add plugins to vim's packpath --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4a6efe1..c5695cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,6 @@ jobs: uses: actions/checkout@v3 with: repository: dhruvasagar/vim-testify - path: pack/plugins/start/vim-testify - name: Install Vim or neovim uses: rhysd/action-setup-vim@v1 @@ -42,4 +41,4 @@ jobs: - name: Run unit tests env: VIM: ${{ steps.vim.outputs.executable }} - run: ${VIM} +"set hidden" +TestifySuite + run: ${VIM} +"set packpath +=${{ github.workspace }}/vim-testify,${{ github.workspace }}/vim-table-mode" +"set hidden" +TestifySuite From 9cbf8283bab191922b56e426673f4e15c7da4058 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 08:38:38 +0530 Subject: [PATCH 04/23] Fix Plugin Paths --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5695cb..ac8e11e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,7 @@ jobs: uses: actions/checkout@v3 with: repository: dhruvasagar/vim-testify + path: vim-testify - name: Install Vim or neovim uses: rhysd/action-setup-vim@v1 @@ -41,4 +42,4 @@ jobs: - name: Run unit tests env: VIM: ${{ steps.vim.outputs.executable }} - run: ${VIM} +"set packpath +=${{ github.workspace }}/vim-testify,${{ github.workspace }}/vim-table-mode" +"set hidden" +TestifySuite + run: ${VIM} +"set packpath +=${{ github.workspace }},${{ github.workspace }}/vim-table-mode" +"set hidden" +TestifySuite From acaad2ef266a41b5e01aeb3a012bf71ca7b5415a Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 08:42:44 +0530 Subject: [PATCH 05/23] Simplified packpath --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac8e11e..53f3bfa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,4 +42,4 @@ jobs: - name: Run unit tests env: VIM: ${{ steps.vim.outputs.executable }} - run: ${VIM} +"set packpath +=${{ github.workspace }},${{ github.workspace }}/vim-table-mode" +"set hidden" +TestifySuite + run: ${VIM} +"set packpath +=.,./vim-testify" +"set hidden" +TestifySuite From 8f3893b7b1a96dc743a2850abc74264fdfb284fa Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 08:47:12 +0530 Subject: [PATCH 06/23] Add packloadall --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 53f3bfa..ba27234 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,4 +42,4 @@ jobs: - name: Run unit tests env: VIM: ${{ steps.vim.outputs.executable }} - run: ${VIM} +"set packpath +=.,./vim-testify" +"set hidden" +TestifySuite + run: ${VIM} +"set packpath +=.,./vim-testify" +packloadall +"set hidden" +TestifySuite From 8873d12158a5979a25c4f0925cb422fc12c7628f Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 08:56:44 +0530 Subject: [PATCH 07/23] Try with github workspace --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba27234..4410b71 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,4 +42,4 @@ jobs: - name: Run unit tests env: VIM: ${{ steps.vim.outputs.executable }} - run: ${VIM} +"set packpath +=.,./vim-testify" +packloadall +"set hidden" +TestifySuite + run: ${VIM} +"set packpath +=${{ github.workspace }},${{ github.workspace }}/vim-testify" +packloadall +"set hidden" +TestifySuite From 4addf0b92e2788806fc1d72462c3aab42402cea7 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 09:11:07 +0530 Subject: [PATCH 08/23] Attempting to use a docker container instead --- .github/workflows/ci.yml | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4410b71..5a0d89b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,29 +17,24 @@ concurrency: jobs: tests: name: Vim Table Mode Tests - strategy: - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - neovim: [false, true] - - runs-on: ${{ matrix.os }} - + runs-on: ubuntu-latest + container: + image: alpine:latest steps: + - name: Install git & vim + run: apk --no-cache add git vim + - uses: actions/checkout@v3 + with: + path: ~/.vim/pack/plugins/start/vim-table-mode - name: Checkout vim-testify uses: actions/checkout@v3 with: repository: dhruvasagar/vim-testify - path: vim-testify - - - name: Install Vim or neovim - uses: rhysd/action-setup-vim@v1 - id: vim - with: - neovim: ${{ matrix.neovim }} + path: ~/.vim/pack/plugins/start/vim-testify - name: Run unit tests - env: - VIM: ${{ steps.vim.outputs.executable }} - run: ${VIM} +"set packpath +=${{ github.workspace }},${{ github.workspace }}/vim-testify" +packloadall +"set hidden" +TestifySuite + run: | + cd ~/.vim/pack/plugins/start/vim-table-mode + vim +TestifySuite From f5df58b089a6b451a062836cf7951b718abc756c Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 11:04:33 +0530 Subject: [PATCH 09/23] Try again --- .github/workflows/ci.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a0d89b..4d1ff9b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,19 +22,15 @@ jobs: image: alpine:latest steps: - name: Install git & vim - run: apk --no-cache add git vim + run: apk --no-cache add vim - uses: actions/checkout@v3 - with: - path: ~/.vim/pack/plugins/start/vim-table-mode - name: Checkout vim-testify uses: actions/checkout@v3 with: repository: dhruvasagar/vim-testify - path: ~/.vim/pack/plugins/start/vim-testify + path: vim-testify - name: Run unit tests - run: | - cd ~/.vim/pack/plugins/start/vim-table-mode - vim +TestifySuite + run: vim +"set packpath+=${{ github.workspace }}/vim-table-mode,${{ github.workspace }}/vim-testify" +TestifySuite From 2868a889c176524094ca491b0dabde9e76697784 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 11:07:04 +0530 Subject: [PATCH 10/23] Remove git from workflow --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d1ff9b..90e7852 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: container: image: alpine:latest steps: - - name: Install git & vim + - name: Install vim run: apk --no-cache add vim - uses: actions/checkout@v3 From 021d8bf02535b88afe26fd24decff7691273a9a4 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 11:13:34 +0530 Subject: [PATCH 11/23] Try vimrc --- .github/workflows/ci.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90e7852..13d8fca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,12 +18,7 @@ jobs: tests: name: Vim Table Mode Tests runs-on: ubuntu-latest - container: - image: alpine:latest steps: - - name: Install vim - run: apk --no-cache add vim - - uses: actions/checkout@v3 - name: Checkout vim-testify @@ -32,5 +27,16 @@ jobs: repository: dhruvasagar/vim-testify path: vim-testify + - name: Install Vim or neovim + uses: rhysd/action-setup-vim@v1 + id: vim + with: + neovim: ${{ matrix.neovim }} + + - name: Create vimrc + run: echo "set packpath += ${{ github.workspace }}/vim-table-mode, ${{ github.workspace }}/vim-testify" > vimrc + - name: Run unit tests - run: vim +"set packpath+=${{ github.workspace }}/vim-table-mode,${{ github.workspace }}/vim-testify" +TestifySuite + env: + VIM: ${{ steps.vim.outputs.executable }} + run: ${VIM} -u vimrc +TestifySuite From 0df034ed2ee7306bd24c97243d50eb3fb3536000 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 11:18:45 +0530 Subject: [PATCH 12/23] Back to matrix --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13d8fca..12cd922 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,11 @@ concurrency: jobs: tests: name: Vim Table Mode Tests - runs-on: ubuntu-latest + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + neovim: [false, true] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 From 3ea394ff83be3a5f88615647134ea911b995b535 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 11:54:16 +0530 Subject: [PATCH 13/23] Looks promising --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 12cd922..e767308 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: neovim: ${{ matrix.neovim }} - name: Create vimrc - run: echo "set packpath += ${{ github.workspace }}/vim-table-mode, ${{ github.workspace }}/vim-testify" > vimrc + run: echo "set packpath += ${{ github.workspace }}, ${{ github.workspace }}/vim-testify" > vimrc - name: Run unit tests env: From 7ace092bf502297053c97c02965b07987daf9a5f Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 12:59:44 +0530 Subject: [PATCH 14/23] Improved packpath --- .github/workflows/ci.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e767308..556a926 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,12 +24,14 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 + with: + path: pack/plugins/start/vim-table-mode - name: Checkout vim-testify uses: actions/checkout@v3 with: repository: dhruvasagar/vim-testify - path: vim-testify + path: pack/plugins/start/vim-testify - name: Install Vim or neovim uses: rhysd/action-setup-vim@v1 @@ -38,9 +40,11 @@ jobs: neovim: ${{ matrix.neovim }} - name: Create vimrc - run: echo "set packpath += ${{ github.workspace }}, ${{ github.workspace }}/vim-testify" > vimrc + run: echo "set packpath += ${{ github.workspace }}" > vimrc - name: Run unit tests env: VIM: ${{ steps.vim.outputs.executable }} - run: ${VIM} -u vimrc +TestifySuite + run: | + cd ${{ github.workspace }}/pack/plugins/start/vim-table-mode + ${VIM} -u vimrc +TestifySuite From 022b2d41b3176904d5567d1315fa5b2d12122bb3 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 13:04:25 +0530 Subject: [PATCH 15/23] Fix vimrc location --- .github/workflows/ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 556a926..d5103b0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,12 +39,10 @@ jobs: with: neovim: ${{ matrix.neovim }} - - name: Create vimrc - run: echo "set packpath += ${{ github.workspace }}" > vimrc - - name: Run unit tests env: VIM: ${{ steps.vim.outputs.executable }} run: | cd ${{ github.workspace }}/pack/plugins/start/vim-table-mode + echo "set packpath+=${{ github.workspace }}" > vimrc ${VIM} -u vimrc +TestifySuite From d9cf433893367a26d2974039ff5b5e503d25da23 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 13:06:55 +0530 Subject: [PATCH 16/23] Quit VIM after running tests --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d5103b0..316b083 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,4 +45,4 @@ jobs: run: | cd ${{ github.workspace }}/pack/plugins/start/vim-table-mode echo "set packpath+=${{ github.workspace }}" > vimrc - ${VIM} -u vimrc +TestifySuite + ${VIM} -u vimrc +TestifySuite +qall From d9bd7c6de1b558c5fc64c38e054f6d884b33740a Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 13:35:51 +0530 Subject: [PATCH 17/23] Try out with nightly version of vim / neovim --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 316b083..ba60b8e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,7 @@ jobs: id: vim with: neovim: ${{ matrix.neovim }} + version: nightly - name: Run unit tests env: From 0dd8aff6d1690298617e652b0187059deae291c5 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Wed, 1 Mar 2023 18:53:27 +0530 Subject: [PATCH 18/23] Improve concurrency to ensure tests run on all environments --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba60b8e..055562d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ on: - feature/switch-to-vim-testify concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }} cancel-in-progress: true jobs: From ed55bc2828826973b6e097c8ac47041506bee648 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Thu, 31 Aug 2023 21:43:51 +0530 Subject: [PATCH 19/23] Fix tests for neovim --- .github/workflows/ci.yml | 1 + .../api/manipulation_with_headers_test.vim | 7 ++++++- .../tablemode/spreadsheet/formula/add_test.vim | 4 ++-- t/fixtures/formula/formula.txt | 14 +++++++------- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 055562d..9e63cc5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,3 +47,4 @@ jobs: cd ${{ github.workspace }}/pack/plugins/start/vim-table-mode echo "set packpath+=${{ github.workspace }}" > vimrc ${VIM} -u vimrc +TestifySuite +qall + cat testify_results.txt diff --git a/t/autoload/tablemode/spreadsheet/api/manipulation_with_headers_test.vim b/t/autoload/tablemode/spreadsheet/api/manipulation_with_headers_test.vim index 97fb1b9..e03b96d 100644 --- a/t/autoload/tablemode/spreadsheet/api/manipulation_with_headers_test.vim +++ b/t/autoload/tablemode/spreadsheet/api/manipulation_with_headers_test.vim @@ -7,7 +7,12 @@ function! s:setup() call utils#TestSetup(s:test_file) endfunction call testify#setup(function('s:setup')) -call testify#teardown(function('utils#TestTeardown')) + +function! s:teardown() + let g:table_mode_header_fillchar = '-' + bw! +endfunction +call testify#teardown(function('s:teardown')) function! s:TestDeleteRow() call cursor(5, 7) diff --git a/t/autoload/tablemode/spreadsheet/formula/add_test.vim b/t/autoload/tablemode/spreadsheet/formula/add_test.vim index 25aa475..d6bab6d 100644 --- a/t/autoload/tablemode/spreadsheet/formula/add_test.vim +++ b/t/autoload/tablemode/spreadsheet/formula/add_test.vim @@ -15,7 +15,7 @@ function! s:TestAddFormula() call testify#assert#equals(cell_value, '125.0') call cursor(9, 15) - call testify#assert#equals(getline('.'), '/* tmf: $4,2=Sum(1:3) */') + call testify#assert#equals(getline('.'), ' tmf: $4,2=Sum(1:3) ') call cursor(8, 15) call tablemode#spreadsheet#formula#Add('Sum(1:-1)') @@ -23,6 +23,6 @@ function! s:TestAddFormula() 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) */') + 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')) diff --git a/t/fixtures/formula/formula.txt b/t/fixtures/formula/formula.txt index ab2df91..9e4ef35 100644 --- a/t/fixtures/formula/formula.txt +++ b/t/fixtures/formula/formula.txt @@ -1,7 +1,7 @@ -| Item | Cost | -|----------+-------| -| Bread | 20 | -| Tomatoes | 5 | -| Pasta | 100 | -| Total | 0 | -/* tmf: $4,2=Sum(1:-1) */ +| Item | Cost | +|----------+------| +| Bread | 20 | +| Tomatoes | 5 | +| Pasta | 100 | +| Total | 0 | + tmf: $4,2=Sum(1:-1) From e66a13b7edaff826881efb9acc4ff7cb05251bde Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Thu, 31 Aug 2023 22:05:47 +0530 Subject: [PATCH 20/23] Improved testing --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e63cc5..661ea79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,9 @@ concurrency: jobs: tests: name: Vim Table Mode Tests + continue-on-error: true strategy: + fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] neovim: [false, true] From 0a132f83771c7f1c96a79b4e171b9f3b81aafd30 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Tue, 24 Oct 2023 12:35:12 +0530 Subject: [PATCH 21/23] Fix tests, remove vim & windows --- .github/workflows/ci.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 661ea79..5bfdc3d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,8 +21,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - neovim: [false, true] + os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -39,7 +38,7 @@ jobs: uses: rhysd/action-setup-vim@v1 id: vim with: - neovim: ${{ matrix.neovim }} + neovim: true version: nightly - name: Run unit tests @@ -48,5 +47,4 @@ jobs: run: | cd ${{ github.workspace }}/pack/plugins/start/vim-table-mode echo "set packpath+=${{ github.workspace }}" > vimrc - ${VIM} -u vimrc +TestifySuite +qall - cat testify_results.txt + ${VIM} --headless -u vimrc +TestifySuite +qall From 7526011c93d6c01c3357e02780eeb7d37e533aeb Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Tue, 24 Oct 2023 12:36:10 +0530 Subject: [PATCH 22/23] Improve github action --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5bfdc3d..3b67c38 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,9 +17,7 @@ concurrency: jobs: tests: name: Vim Table Mode Tests - continue-on-error: true strategy: - fail-fast: false matrix: os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} From 81fb86a0195c1ceb1379db321c8b3f2d81f6633f Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Tue, 24 Oct 2023 12:37:25 +0530 Subject: [PATCH 23/23] Fixed Build Badge --- README.md | 247 +++++++++++++++++++++++---------------------- doc/table-mode.txt | 3 +- 2 files changed, 127 insertions(+), 123 deletions(-) diff --git a/README.md b/README.md index 440045f..102ae81 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,39 @@ -# VIM Table Mode v4.8.0 [![Build Status](https://travis-ci.org/dhruvasagar/vim-table-mode.png?branch=master)](https://travis-ci.org/dhruvasagar/vim-table-mode) +# VIM Table Mode v4.8.1 ![Build](https://github.com/dhruvasagar/vim-table-mode/actions/workflows/ci.yml/badge.svg) An awesome automatic table creator & formatter allowing one to create neat tables as you type. -## Getting Started +## Getting Started ### Installation #### Vim 8+ native package manager - clone into `.vim/pack/plugins/start` (the `plugins` folder can have any name) - - Add `packloadall` in your `~/.vimrc`. + +clone into `.vim/pack/plugins/start` (the `plugins` folder can have any name) + +Add `packloadall` in your `~/.vimrc`. #### NeoBundle - Add `NeoBundle 'dhruvasagar/vim-table-mode'` to your `~/.vimrc`. + +Add `NeoBundle 'dhruvasagar/vim-table-mode'` to your `~/.vimrc`. #### pathogen.vim - Add a git submodule for your plugin: - + +Add a git submodule for your plugin: + ```sh $ cd ~/.vim $ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-mode ``` - Copy all files under `autoload/`, `plugin/`, and `doc/` to respective - `~/.vim/autoload/`, `~/.vim/plugin` and `~/.vim/doc` under UNIX, or - `vimfiles/autoload/`, `vimfiles/plugin/` and `vimfiles/doc` under WINDOWS and - restart Vim. - + +Copy all files under `autoload/`, `plugin/`, and `doc/` to respective +`~/.vim/autoload/`, `~/.vim/plugin` and `~/.vim/doc` under UNIX, or +`vimfiles/autoload/`, `vimfiles/plugin/` and `vimfiles/doc` under WINDOWS and +restart Vim. + #### vim-plug - Add `Plug 'dhruvasagar/vim-table-mode'` to your `~/.vimrc`. + +Add `Plug 'dhruvasagar/vim-table-mode'` to your `~/.vimrc`. ### Creating table on-the-fly @@ -36,6 +41,7 @@ To start using the plugin in the on-the-fly mode use `:TableModeToggle` mapped t Tip: You can use the following to quickly enable / disable table mode in insert mode by using `||` or `__`: + > ```vim > function! s:isAtStartOfLine(mapping) > let text_before_cursor = getline('.')[0 : col('.')-1] @@ -43,7 +49,7 @@ You can use the following to quickly enable / disable table mode in insert mode > let comment_pattern = '\V' . escape(substitute(&l:commentstring, '%s.*$', '', ''), '\') > return (text_before_cursor =~? '^' . ('\v(' . comment_pattern . '\v)?') . '\s*\v' . mapping_pattern . '\v$') > endfunction -> +> > inoreabbrev > \ isAtStartOfLine('\|\|') ? > \ ':TableModeEnable' : '' @@ -119,16 +125,16 @@ Markdown and ReST filetypes have automatically configured corners. > If you wish to override their configurations, it should be done in an after > plugin, for example : -> +> > In a `$VIM/after/ftplugin/markdown/custom.vim` you can add the following : -> +> > ```viml > let b:table_mode_corner='+' > ``` - You can also define in a table header border how its content should be - aligned, whether center, right or left by using a `:` character defined by - `g:table_mode_align_char` option. +You can also define in a table header border how its content should be +aligned, whether center, right or left by using a `:` character defined by +`g:table_mode_align_char` option. If you manipulate the table when table mode is disabled or copy paste a table from clipboard from outside and it ends up being misaligned, you can realign @@ -137,144 +143,139 @@ it using `:TableModeRealign` or using the default mapping ### Formatting existing content into a table - Table Mode wouldn't justify its name if it didn't allow formatting - existing content into a table. And it does as promised. Like table creation typing on the fly, - formatting existing content into a table is equally - simple. You can visually select multiple lines and call `:Tableize` on it. - Alternatively, the mapping \tt can be used (defined by the - option `g:table_mode_tableize_map`). This converts CSV (Comma-separated - Values) data into a table. +Table Mode wouldn't justify its name if it didn't allow formatting +existing content into a table. And it does as promised. Like table creation typing on the fly, +formatting existing content into a table is equally +simple. You can visually select multiple lines and call `:Tableize` on it. +Alternatively, the mapping \tt can be used (defined by the +option `g:table_mode_tableize_map`). This converts CSV (Comma-separated +Values) data into a table. - If however you wish to use a different delimiter, you can use the command - `:Tableize/{pattern}` in a similar fashion as you tabulate (e.g. - `:Tableize/;` uses ';' as the delimiter) or use the mapping \T - (defined by the option `g:table_mode_tableize_op_map`) which takes input in the - cmd-line and uses the `{pattern}` input as the delimiter. +If however you wish to use a different delimiter, you can use the command +`:Tableize/{pattern}` in a similar fashion as you tabulate (e.g. +`:Tableize/;` uses ';' as the delimiter) or use the mapping \T +(defined by the option `g:table_mode_tableize_op_map`) which takes input in the +cmd-line and uses the `{pattern}` input as the delimiter. - `:Tableize` also accepts a range. Call it by giving - lines manually like `:line1,line2Tableize`. However this may not be intuitive. - You can use the mapping \T with a `[count]` to apply it to the - next `[count]` lines in standard vim style. +`:Tableize` also accepts a range. Call it by giving +lines manually like `:line1,line2Tableize`. However this may not be intuitive. +You can use the mapping \T with a `[count]` to apply it to the +next `[count]` lines in standard vim style. -### Moving around +### Moving around - Now you can move between cells using table mode motions [|, - ]|, {| & }| to move left | right | up | - down cells respectively. The left | right motions wrap around the table - and move to the next | previous row after the last | first cell in the - current row if one exists. +Now you can move between cells using table mode motions [|, +]|, {| & }| to move left | right | up | +down cells respectively. The left | right motions wrap around the table +and move to the next | previous row after the last | first cell in the +current row if one exists. ### Manipulating Table - - **Cell Text Object** : +- **Cell Text Object** : - Tableize provides a text object for manipulating table cells. Following - the vim philosophy the you have i| & a| for the - inner and around (including the immediate right table separator) the - table cell. + Tableize provides a text object for manipulating table cells. Following + the vim philosophy the you have i| & a| for the + inner and around (including the immediate right table separator) the + table cell. - - **Delete Row** : +- **Delete Row** : - You can use the \tdd mapping (defined by the option - `g:table_mode_delete_row_map`) to delete the current table row (provided - you are within a table row). This can be preceeded with a `[count]` to - delete multiple rows as per Vim command grammar. + You can use the \tdd mapping (defined by the option + `g:table_mode_delete_row_map`) to delete the current table row (provided + you are within a table row). This can be preceeded with a `[count]` to + delete multiple rows as per Vim command grammar. - - **Delete Column** : +- **Delete Column** : - You can use the \tdc mapping (defined by the option - `g:table_mode_delete_column_map`) to delete the entire current column - (provided you are within a table row), this can also be preceeded with a - `[count]` to delete multiple columns. + You can use the \tdc mapping (defined by the option + `g:table_mode_delete_column_map`) to delete the entire current column + (provided you are within a table row), this can also be preceeded with a + `[count]` to delete multiple columns. - - **Insert Column** : +- **Insert Column** : - You can use the \tic mapping (defined by the option - `g:table_mode_insert_column_after_map`) to insert a column after the - cursor (provided you are within a table row). Of course you can use the - \tiC mapping defined by - `g:table_mode_insert_column_before_map` to insert a column before the - cursor. Both can also be preceeded with a [count] to insert multiple - columns. + You can use the \tic mapping (defined by the option + `g:table_mode_insert_column_after_map`) to insert a column after the + cursor (provided you are within a table row). Of course you can use the + \tiC mapping defined by + `g:table_mode_insert_column_before_map` to insert a column before the + cursor. Both can also be preceeded with a [count] to insert multiple + columns. ### Highlight cells based on content - You can highlight cells based on content by setting `let g:table_mode_color_cells` : - - cells starting with `yes` will use the `yesCell` highlight group. - - cells starting with `no` will use the `noCell` highlight group. - - cells starting with `?` will use the `maybeCell` hightlight group. - - You can overwrite any highlight group. For exemple use `hi yesCell ctermfg=2` to remove the background color. - +You can highlight cells based on content by setting `let g:table_mode_color_cells` : - cells starting with `yes` will use the `yesCell` highlight group. - cells starting with `no` will use the `noCell` highlight group. - cells starting with `?` will use the `maybeCell` hightlight group. +You can overwrite any highlight group. For exemple use `hi yesCell ctermfg=2` to remove the background color. ## Advanced Usage: Spreadsheet Capabilities ### Table Formulas - Table Mode now has support for formulas like a spreadsheet. There are 2 ways - of defining formulas : +Table Mode now has support for formulas like a spreadsheet. There are 2 ways +of defining formulas : - - You can add formulas using `:TableAddFormula` or the mapping \tfa - (defined by the option `g:table_mode_add_formula_map`) from within a table - cell, which will ask for input on the cmd-line with a `f=` prompt. The - input formula will be appended to the formula line if one exists or a new - one will be created with the input formula taking the current cell as the - target cell. The formula line is evaluated immidiately to reflect the - results. +- You can add formulas using `:TableAddFormula` or the mapping \tfa + (defined by the option `g:table_mode_add_formula_map`) from within a table + cell, which will ask for input on the cmd-line with a `f=` prompt. The + input formula will be appended to the formula line if one exists or a new + one will be created with the input formula taking the current cell as the + target cell. The formula line is evaluated immidiately to reflect the + results. - - You can directly add / manipulate formula expressions in the formula line. - The formula line is a commented line right after the table, or optionally - separated from the table by a single empty line. It begins with 'tmf:' - (table mode formula). eg) `# tmf: $3=$2*$1`. You can add multiple formulas on - the line separated with a ';' eg) `# tmf: $3=$2*$1;$4=$3/3.14` +- You can directly add / manipulate formula expressions in the formula line. + The formula line is a commented line right after the table, or optionally + separated from the table by a single empty line. It begins with 'tmf:' + (table mode formula). eg) `# tmf: $3=$2*$1`. You can add multiple formulas on + the line separated with a ';' eg) `# tmf: $3=$2*$1;$4=$3/3.14` - You can evaluate the formula line using `:TableEvalFormulaLine` or the - mapping \tfe (defined by the option `g:table_mode_eval_expr_map`) - from anywhere inside the table or while on the formula line. +You can evaluate the formula line using `:TableEvalFormulaLine` or the +mapping \tfe (defined by the option `g:table_mode_eval_expr_map`) +from anywhere inside the table or while on the formula line. - NOTE: You can now use the mapping \t? +NOTE: You can now use the mapping \t? ### Formula Expressions - Expressions are of the format `$target = formula`. +Expressions are of the format `$target = formula`. - - The `target` can be of 2 forms : +- The `target` can be of 2 forms : - - `$n`: This matches the table column number `n`. So the `formula` would - be evaluated for each cell in that column and the result would be placed - in it. You can use negative indice to represent column relative to the - last, -1 being the last. + - `$n`: This matches the table column number `n`. So the `formula` would + be evaluated for each cell in that column and the result would be placed + in it. You can use negative indice to represent column relative to the + last, -1 being the last. - - `$n,m`: This matches the table cell n,m (row, column). So in this case - the formula would be evaluated and the result will be placed in this - cell. You can also use negative values to refer to cells relative to - the size, -1 being the last (row or column). + - `$n,m`: This matches the table cell n,m (row, column). So in this case + the formula would be evaluated and the result will be placed in this + cell. You can also use negative values to refer to cells relative to + the size, -1 being the last (row or column). - - The `formula` can be a simple mathematical expression involving cells - which are also defined by the same format as that of the target cell. You - can use all native vim functions within the formula. Apart from that table - mode also provides 2 special functions `Sum` and `Average`. Both these - functions take a range as input. A range can be of two forms: +- The `formula` can be a simple mathematical expression involving cells + which are also defined by the same format as that of the target cell. You + can use all native vim functions within the formula. Apart from that table + mode also provides 2 special functions `Sum` and `Average`. Both these + functions take a range as input. A range can be of two forms: - - `r1:r2`: This represents cells in the current column from row `r1` - through `r2`. If `r2` is negative it represents `r2` rows above the - current row (of the target cell). + - `r1:r2`: This represents cells in the current column from row `r1` + through `r2`. If `r2` is negative it represents `r2` rows above the + current row (of the target cell). - - `r1,c1:r2,c2`: This represents cells in the table from cell r1,c1 - through cell r2,c2 (row, column). + - `r1,c1:r2,c2`: This represents cells in the table from cell r1,c1 + through cell r2,c2 (row, column). - - Examples : - - `$2 = $1 * $1` - - `$2 = pow($1, 5)` NOTE: Remember to put space between the $1, and 5 - here otherwise it will be treated like a table cell. - - `$2 = $1 / $1,3` - - `$1,2 = $1,1 * $1,1` - - `$5,1 = Sum(1:-1)` - - `$5,1 = float2nr(Sum(1:-1))` - - `$5,3 = Sum(1,2:5,2)` - - `$5,3 = Sum(1,2:5,2)/$5,1` - - `$5,3 = Average(1,2:5,2)/$5,1` +- Examples : + - `$2 = $1 * $1` + - `$2 = pow($1, 5)` NOTE: Remember to put space between the $1, and 5 + here otherwise it will be treated like a table cell. + - `$2 = $1 / $1,3` + - `$1,2 = $1,1 * $1,1` + - `$5,1 = Sum(1:-1)` + - `$5,1 = float2nr(Sum(1:-1))` + - `$5,3 = Sum(1,2:5,2)` + - `$5,3 = Sum(1,2:5,2)/$5,1` + - `$5,3 = Average(1,2:5,2)/$5,1` ## Demo @@ -282,6 +283,7 @@ it using `:TableModeRealign` or using the default mapping src="https://raw.github.com/axil/vim-table-mode/master/youtube.png"/> ## Change Log + See CHANGELOG.md @@ -289,16 +291,19 @@ CHANGELOG.md ## Contributing ### Reporting an Issue : + - Use Github Issue Tracker ### Contributing to code : + - Fork it. - Commit your changes and give your commit message some love. - Push to your fork on github. - Open a Pull Request. ## Credit + I must thank Tim Pope for inspiration. The initial concept was created by him named cucumbertables.vim. diff --git a/doc/table-mode.txt b/doc/table-mode.txt index c22fe26..22a826f 100644 --- a/doc/table-mode.txt +++ b/doc/table-mode.txt @@ -1,7 +1,7 @@ *table-mode.txt* Table Mode for easy table formatting =============================================================================== Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER - VERSION 4.8.0 + VERSION 4.8.1 Author: Dhruva Sagar License: MIT @@ -544,4 +544,3 @@ REPORT ISSUES *table-mode-report-issues* If you discover any issues, please report them at http://github.com/dhruvasagar/vim-table-mode/issues. -