Improved test for utils

This commit is contained in:
Dhruva Sagar
2014-04-30 23:04:27 +05:30
parent 53da3fb4c2
commit fa568fe91b
2 changed files with 39 additions and 28 deletions

View File

@@ -52,9 +52,7 @@ function! tablemode#utils#strlen(text)
return strlen(substitute(a:text, '.', 'x', 'g'))
endfunction
" Return the number of bytes in a string after expanding tabs to spaces. {{{2
" This expansion is done based on the current value of 'tabstop'
function! tablemode#utils#StrDisplayWidth(string)
function! tablemode#utils#StrDisplayWidth(string) "{{{2
if exists('*strdisplaywidth')
return strdisplaywidth(a:string)
else
@@ -77,4 +75,3 @@ function! tablemode#utils#StrDisplayWidth(string)
return rv
endif
endfunction

View File

@@ -3,7 +3,8 @@ source t/config/options.vim
call vspec#hint({'scope': 'tablemode#utils#scope()', 'sid': 'tablemode#utils#sid()'})
describe 'line'
describe 'utils'
describe 'line'
it 'should return the current line number'
Expect tablemode#utils#line('.') == line('.')
end
@@ -11,16 +12,16 @@ describe 'line'
it 'should return the line number itself if it is a number'
Expect tablemode#utils#line(1) == 1
end
end
end
describe 'strip'
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
end
describe 'strlen'
describe 'strlen'
it 'should return the length of a string correctly'
let string = 'this is a test'
Expect tablemode#utils#strlen(string) == 14
@@ -30,4 +31,17 @@ describe 'strlen'
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