From f5885bf9c2ae12a9f1b74f1e57fa4adaf8d3f20c Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Fri, 30 Aug 2013 21:15:41 -0400 Subject: [PATCH] test creation of sections --- autoload/airline/section.vim | 6 +++--- t/parts.vim | 24 ++++++++++++++++++++++++ t/section.vim | 28 ++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 t/parts.vim create mode 100644 t/section.vim diff --git a/autoload/airline/section.vim b/autoload/airline/section.vim index 788b443..d14a828 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 0000000..03fee1e --- /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 0000000..0a16105 --- /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 +