From a61e0692742915a8bbbd55d8e0e21aad10860be0 Mon Sep 17 00:00:00 2001 From: itchyny Date: Mon, 21 Mar 2016 15:50:10 +0900 Subject: [PATCH] add more tests, error and notfound for s:expand --- test/expand.vim | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/expand.vim b/test/expand.vim index a6bf9d2..b9d45d5 100644 --- a/test/expand.vim +++ b/test/expand.vim @@ -118,3 +118,49 @@ function! s:suite.custom_type_mixed() \ [[['readonly', 'filename', 'left'], ['{''custom'': 24}'], ['function(''tr'')', 'modified']], [[0, 0, 1], [1], [1, 0]], [0, 'custom', 0, 1]]) delfunction Custom endfunction + +function! s:suite.custom_error() + function! Custom() + throw 'error' + return 'custom' + endfunction + let g:lightline = { 'component_expand': { 'custom': 'Custom' } } + call lightline#init() + call s:assert.equals(SID('expand')([['readonly', 'filename'], ['custom'], ['modified']]), + \ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], [0, 2, 3]]) + call s:assert.equals(SID('expand')([['readonly', 'filename', 'custom', 'modified']]), + \ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], [0, 1]]) + delfunction Custom +endfunction + +function! s:suite.custom_type_error() + function! Custom() + throw 'error' + return 'custom' + endfunction + let g:lightline = { 'component_expand': { 'custom': 'Custom' }, 'component_type': { 'custom': 'custom' } } + call lightline#init() + call s:assert.equals(SID('expand')([['readonly', 'filename'], ['custom'], ['modified']]), + \ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], [0, 2, 3]]) + call s:assert.equals(SID('expand')([['readonly', 'filename', 'custom', 'modified']]), + \ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], [0, 1]]) + delfunction Custom +endfunction + +function! s:suite.notfound() + let g:lightline = { 'component_expand': { 'custom': 'NotFound' } } + call lightline#init() + call s:assert.equals(SID('expand')([['readonly', 'filename'], ['custom'], ['modified']]), + \ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], [0, 2, 3]]) + call s:assert.equals(SID('expand')([['readonly', 'filename', 'custom', 'modified']]), + \ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], [0, 1]]) +endfunction + +function! s:suite.custom_type_notfound() + let g:lightline = { 'component_expand': { 'custom': 'NotFound' }, 'component_type': { 'custom': 'custom' } } + call lightline#init() + call s:assert.equals(SID('expand')([['readonly', 'filename'], ['custom'], ['modified']]), + \ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], [0, 2, 3]]) + call s:assert.equals(SID('expand')([['readonly', 'filename', 'custom', 'modified']]), + \ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], [0, 1]]) +endfunction