diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..3b67c38
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,48 @@
+name: CI
+
+on:
+ push:
+ branches:
+ - master
+ - feature/switch-to-vim-testify
+ pull_request:
+ branches:
+ - master
+ - feature/switch-to-vim-testify
+
+concurrency:
+ group: ${{ github.workflow }}
+ cancel-in-progress: true
+
+jobs:
+ tests:
+ name: Vim Table Mode Tests
+ strategy:
+ matrix:
+ os: [ubuntu-latest, macos-latest]
+ 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: pack/plugins/start/vim-testify
+
+ - name: Install Vim or neovim
+ uses: rhysd/action-setup-vim@v1
+ id: vim
+ with:
+ neovim: true
+ version: nightly
+
+ - 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} --headless -u vimrc +TestifySuite +qall
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/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 [](https://travis-ci.org/dhruvasagar/vim-table-mode)
+# VIM Table Mode v4.8.1 
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/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/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.
-
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..e03b96d
--- /dev/null
+++ b/t/autoload/tablemode/spreadsheet/api/manipulation_with_headers_test.vim
@@ -0,0 +1,58 @@
+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'))
+
+function! s:teardown()
+ let g:table_mode_header_fillchar = '-'
+ bw!
+endfunction
+call testify#teardown(function('s:teardown'))
+
+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..d6bab6d
--- /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/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)
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