mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 02:53:48 -05:00
Rewrite tests with vim-testify
This commit is contained in:
39
.github/workflows/ci.yml
vendored
Normal file
39
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- feature/switch-to-vim-testify
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- feature/switch-to-vim-testify
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
name: Vim Table Mode Tests
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
neovim: [false, true]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install Vim or neovim
|
||||
uses: rhysd/action-setup-vim@v1
|
||||
id: vim
|
||||
with:
|
||||
neovim: ${{ matrix.neovim }}
|
||||
|
||||
- name: Run unit tests
|
||||
env:
|
||||
VIM: ${{ steps.vim.outputs.executable }}
|
||||
run: ${VIM} +"set hidden" +TestifySuite
|
||||
6
Gemfile
6
Gemfile
@@ -1,6 +0,0 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
ruby '3.0.0'
|
||||
|
||||
gem 'rake'
|
||||
gem 'vim-flavor', '~> 1.1'
|
||||
24
Gemfile.lock
24
Gemfile.lock
@@ -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
|
||||
13
Rakefile
13
Rakefile
@@ -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
|
||||
@@ -1 +0,0 @@
|
||||
kana/vim-vspec (1.1.2)
|
||||
@@ -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'
|
||||
|
||||
20
t/align.vim
20
t/align.vim
@@ -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
|
||||
23
t/autoload/tablemode/align_test.vim
Normal file
23
t/autoload/tablemode/align_test.vim
Normal file
@@ -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'))
|
||||
194
t/autoload/tablemode/spreadsheet/api/count_test.vim
Normal file
194
t/autoload/tablemode/spreadsheet/api/count_test.vim
Normal file
@@ -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'))
|
||||
52
t/autoload/tablemode/spreadsheet/api/manipulation_test.vim
Normal file
52
t/autoload/tablemode/spreadsheet/api/manipulation_test.vim
Normal file
@@ -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'))
|
||||
@@ -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'))
|
||||
@@ -0,0 +1,53 @@
|
||||
source t/config/options.vim
|
||||
source t/utils.vim
|
||||
|
||||
let s:test_file = 't/fixtures/complex_header.txt'
|
||||
function! s:setup()
|
||||
let g:table_mode_header_fillchar = '='
|
||||
call utils#TestSetup(s:test_file)
|
||||
endfunction
|
||||
call testify#setup(function('s:setup'))
|
||||
call testify#teardown(function('utils#TestTeardown'))
|
||||
|
||||
function! s:TestDeleteRow()
|
||||
call cursor(5, 7)
|
||||
call testify#assert#equals(tablemode#spreadsheet#RowCount('.'), 5)
|
||||
call tablemode#spreadsheet#DeleteRow()
|
||||
call testify#assert#equals(tablemode#spreadsheet#RowCount('.'), 4)
|
||||
call testify#assert#equals(getline(5), '| 2 | 8 | b | y |')
|
||||
call utils#TestUndo(s:test_file)
|
||||
endfunction
|
||||
call testify#it('DeleteRow should delete a row in a table with headers', function('s:TestDeleteRow'))
|
||||
|
||||
function! s:TestDeleteColumn()
|
||||
call cursor(5, 7)
|
||||
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 4)
|
||||
call tablemode#spreadsheet#DeleteColumn()
|
||||
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 3)
|
||||
call testify#assert#equals(getline(5), '| 9 | a | z |')
|
||||
call utils#TestUndo(s:test_file)
|
||||
endfunction
|
||||
call testify#it('DeleteColumn should delete a column in a table with headers', function('s:TestDeleteColumn'))
|
||||
|
||||
function! s:TestInsertColumn()
|
||||
call cursor(5, 7)
|
||||
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 4)
|
||||
call tablemode#spreadsheet#InsertColumn(0)
|
||||
stopinsert
|
||||
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 5)
|
||||
call testify#assert#equals(getline(5), '| | 1 | 9 | a | z |')
|
||||
call utils#TestUndo(s:test_file)
|
||||
endfunction
|
||||
call testify#it('InsertColumn should insert a new column before the current column in a table with headers in a table with headers', function('s:TestInsertColumn'))
|
||||
|
||||
function! s:TestInserColumnAfter()
|
||||
call cursor(5, 7)
|
||||
normal! $
|
||||
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 4)
|
||||
call tablemode#spreadsheet#InsertColumn(1)
|
||||
stopinsert
|
||||
call testify#assert#equals(tablemode#spreadsheet#ColumnCount('.'), 5)
|
||||
call testify#assert#equals(getline(5), '| 1 | 9 | a | z | |')
|
||||
call utils#TestUndo(s:test_file)
|
||||
endfunction
|
||||
call testify#it('InsertColumn should be able to insert a new column after the current column in a table with headers', function('s:TestInserColumnAfter'))
|
||||
@@ -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'))
|
||||
141
t/autoload/tablemode/spreadsheet/api/math_test.vim
Normal file
141
t/autoload/tablemode/spreadsheet/api/math_test.vim
Normal file
@@ -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'))
|
||||
@@ -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:\<C-U>call tablemode#spreadsheet#InsertColumn(0)\<CR>"
|
||||
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:\<C-U>call tablemode#spreadsheet#InsertColumn(1)\<CR>"
|
||||
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'))
|
||||
66
t/autoload/tablemode/spreadsheet/api/test.vim
Normal file
66
t/autoload/tablemode/spreadsheet/api/test.vim
Normal file
@@ -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'))
|
||||
208
t/autoload/tablemode/spreadsheet/cell_test.vim
Normal file
208
t/autoload/tablemode/spreadsheet/cell_test.vim
Normal file
@@ -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'))
|
||||
28
t/autoload/tablemode/spreadsheet/formula/add_test.vim
Normal file
28
t/autoload/tablemode/spreadsheet/formula/add_test.vim
Normal file
@@ -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'))
|
||||
18
t/autoload/tablemode/spreadsheet/formula/eval_test.vim
Normal file
18
t/autoload/tablemode/spreadsheet/formula/eval_test.vim
Normal file
@@ -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'))
|
||||
18
t/autoload/tablemode/table/add_border_test.vim
Normal file
18
t/autoload/tablemode/table/add_border_test.vim
Normal file
@@ -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'))
|
||||
37
t/autoload/tablemode/table/add_border_with_unicode_test.vim
Normal file
37
t/autoload/tablemode/table/add_border_with_unicode_test.vim
Normal file
@@ -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'))
|
||||
21
t/autoload/tablemode/table/is_border_test.vim
Normal file
21
t/autoload/tablemode/table/is_border_test.vim
Normal file
@@ -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'))
|
||||
21
t/autoload/tablemode/table/is_header_test.vim
Normal file
21
t/autoload/tablemode/table/is_header_test.vim
Normal file
@@ -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'))
|
||||
18
t/autoload/tablemode/table/is_row_test.vim
Normal file
18
t/autoload/tablemode/table/is_row_test.vim
Normal file
@@ -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'))
|
||||
25
t/autoload/tablemode/table/is_table_test.vim
Normal file
25
t/autoload/tablemode/table/is_table_test.vim
Normal file
@@ -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'))
|
||||
16
t/autoload/tablemode/table/realign_test.vim
Normal file
16
t/autoload/tablemode/table/realign_test.vim
Normal file
@@ -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'))
|
||||
@@ -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'))
|
||||
@@ -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'))
|
||||
16
t/autoload/tablemode/table/realign_with_unicode_test.vim
Normal file
16
t/autoload/tablemode/table/realign_with_unicode_test.vim
Normal file
@@ -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'))
|
||||
27
t/autoload/tablemode_tableize_test.vim
Normal file
27
t/autoload/tablemode_tableize_test.vim
Normal file
@@ -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'))
|
||||
24
t/autoload/tablemode_test.vim
Normal file
24
t/autoload/tablemode_test.vim
Normal file
@@ -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'))
|
||||
135
t/cell.vim
135
t/cell.vim
@@ -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
|
||||
@@ -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
|
||||
@@ -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:\<C-u>call tablemode#spreadsheet#InsertColumn(0)\<CR>"
|
||||
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:\<C-u>call tablemode#spreadsheet#InsertColumn(1)\<CR>"
|
||||
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
|
||||
184
t/table.vim
184
t/table.vim
@@ -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
|
||||
@@ -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
|
||||
58
t/utils.vim
58
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
|
||||
|
||||
Reference in New Issue
Block a user