diff --git a/autoload/airline/section.vim b/autoload/airline/section.vim index 788b443b..d14a828f 100644 --- a/autoload/airline/section.vim +++ b/autoload/airline/section.vim @@ -2,7 +2,6 @@ " vim: et ts=2 sts=2 sw=2 function! s:get_val(key, append) - let val = '' let part = airline#parts#get(a:key) if exists('part.function') let func = (part.function).'()' @@ -14,12 +13,13 @@ function! s:get_val(key, append) return a:key endif + let val = '' if a:append > 0 let val .= '%{airline#util#append('.func.')}' elseif a:append < 0 - return '%{airline#util#prepend('.func.')}' + let val .= '%{airline#util#prepend('.func.')}' else - return '%{'.func.'}' + let val .= '%{'.func.'}' endif return val endfunction diff --git a/t/parts.vim b/t/parts.vim new file mode 100644 index 00000000..03fee1eb --- /dev/null +++ b/t/parts.vim @@ -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 + diff --git a/t/section.vim b/t/section.vim new file mode 100644 index 00000000..0a161054 --- /dev/null +++ b/t/section.vim @@ -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 +