test creation of sections

This commit is contained in:
Bailey Ling 2013-08-30 21:15:41 -04:00
parent 54ec1f39ca
commit f5885bf9c2
3 changed files with 55 additions and 3 deletions

View File

@ -2,7 +2,6 @@
" vim: et ts=2 sts=2 sw=2 " vim: et ts=2 sts=2 sw=2
function! s:get_val(key, append) function! s:get_val(key, append)
let val = ''
let part = airline#parts#get(a:key) let part = airline#parts#get(a:key)
if exists('part.function') if exists('part.function')
let func = (part.function).'()' let func = (part.function).'()'
@ -14,12 +13,13 @@ function! s:get_val(key, append)
return a:key return a:key
endif endif
let val = ''
if a:append > 0 if a:append > 0
let val .= '%{airline#util#append('.func.')}' let val .= '%{airline#util#append('.func.')}'
elseif a:append < 0 elseif a:append < 0
return '%{airline#util#prepend('.func.')}' let val .= '%{airline#util#prepend('.func.')}'
else else
return '%{'.func.'}' let val .= '%{'.func.'}'
endif endif
return val return val
endfunction endfunction

24
t/parts.vim Normal file
View File

@ -0,0 +1,24 @@
describe 'parts'
it 'overwrites existing values'
call airline#parts#define('foo', { 'test': '123' })
Expect airline#parts#get('foo').test == '123'
call airline#parts#define('foo', { 'test': '321' })
Expect airline#parts#get('foo').test == '321'
end
it 'can define a function part'
call airline#parts#define_function('func', 'bar')
Expect airline#parts#get('func').function == 'bar'
end
it 'can define a text part'
call airline#parts#define_text('text', 'bar')
Expect airline#parts#get('text').text == 'bar'
end
it 'can define a raw part'
call airline#parts#define_raw('raw', 'bar')
Expect airline#parts#get('raw').raw == 'bar'
end
end

28
t/section.vim Normal file
View File

@ -0,0 +1,28 @@
call airline#init#bootstrap()
function! SectionSpec()
endfunction
describe 'section'
before
call airline#parts#define_text('text', 'text')
call airline#parts#define_raw('raw', 'raw')
call airline#parts#define_function('func', 'SectionSpec')
end
it 'should create sections with no separators'
let s = airline#section#create(['text', 'raw', 'func'])
Expect s == '%{"text"}raw%{SectionSpec()}'
end
it 'should create left sections with separators'
let s = airline#section#create_left(['text', 'text'])
Expect s == '%{"text"}%{airline#util#append("text")}'
end
it 'should create right sections with separators'
let s = airline#section#create_right(['text', 'text'])
Expect s == '%{airline#util#prepend("text")}%{"text"}'
end
end