From 6f67937c02e83418c5cb2c13758fadb997d2c62c Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Thu, 27 Nov 2014 20:01:40 +0900 Subject: [PATCH] Fix tests --- test/matcher.vim | 78 +++++++++++++++++++++++++++++++++++++++ test/sorter.vim | 44 ++++++++++++++++++++++ test/source.vim | 47 ++++++++++++++++++++++++ vest/test-matcher.vim | 85 ------------------------------------------- vest/test-sorter.vim | 54 --------------------------- vest/test-source.vim | 81 ----------------------------------------- 6 files changed, 169 insertions(+), 220 deletions(-) create mode 100644 test/matcher.vim create mode 100644 test/sorter.vim create mode 100644 test/source.vim delete mode 100644 vest/test-matcher.vim delete mode 100644 vest/test-sorter.vim delete mode 100644 vest/test-source.vim diff --git a/test/matcher.vim b/test/matcher.vim new file mode 100644 index 00000000..40a71cae --- /dev/null +++ b/test/matcher.vim @@ -0,0 +1,78 @@ +let s:suite = themis#suite('parser') +let s:assert = themis#helper('assert') + +function! s:suite.before_each() + let g:fuzzy_save = 20 +endfunction +function! s:suite.after_each() + let g:unite_matcher_fuzzy_max_input_length = g:fuzzy_save +endfunction + +function! s:suite.lua() + if !has('lua') + return + endif + call unite#filters#matcher_fuzzy#define() + + let g:unite_matcher_fuzzy_max_input_length = 20 + call s:assert.equals(unite#filters#lua_matcher( + \ [{'word' : 'foo'}], { 'input' : 'foo' }, 0), [{'word' : 'foo'}]) + call s:assert.equals(unite#filters#lua_matcher( + \ [{'word' : 'foo'}], { 'input' : 'bar' }, 0), []) + call s:assert.equals(unite#filters#lua_matcher( + \ [{'word' : 'Foo'}], { 'input' : 'foo'}, 0), []) + call s:assert.equals(unite#filters#lua_matcher( + \ [{'word' : 'Foo'}], { 'input' : 'foo'}, 1), [{'word' : 'Foo'}]) + call s:assert.equals(unite#filters#lua_matcher( + \ [{'word' : 'Foo'}, {'word' : 'Bar'}], + \ {'input' : 'foo'}, 1), [{'word' : 'Foo'}]) + call s:assert.equals(unite#filters#lua_matcher( + \ [{'word' : 'foo'}, {'word' : 'bar'}, + \ {'word' : 'foobar'}, {'word' : 'baz'}], + \ {'input' : 'foo'}, 0), [{'word' : 'foo'}, {'word' : 'foobar'}]) + call s:assert.equals(unite#filters#lua_fuzzy_matcher( + \ [{'word' : '/Users/core.cljs'}, {'word' : '/Users/core.js'}], + \ { 'input' : 'cl' }, 0), [{'word' : '/Users/core.cljs'}]) + call s:assert.equals(unite#filters#lua_fuzzy_matcher( + \ [{'word' : '/Users/core.cljs'}, {'word' : '/Users/core.js'}], + \ { 'input' : 'co' }, 0), + \ [{'word' : '/Users/core.cljs'}, {'word' : '/Users/core.js'}]) + call s:assert.equals(unite#filters#lua_fuzzy_matcher( + \ [{'word' : '/Users/core.cljs'}, {'word' : '/Users/core.js'}], + \ { 'input' : '/U' }, 0), + \ [{'word' : '/Users/core.cljs'}, {'word' : '/Users/core.js'}]) + call s:assert.equals(unite#filters#lua_fuzzy_matcher( + \ [{'word' : '/Users/core.cljs'}, {'word' : '/Users/core.js'}], + \ { 'input' : '/Us' }, 0), + \ [{'word' : '/Users/core.cljs'}, {'word' : '/Users/core.js'}]) + call s:assert.equals(unite#filters#lua_fuzzy_matcher( + \ [{'word' : '/unite/sources/find.vim'}], + \ { 'input' : '/u/s/f' }, 0), [{'word' : '/unite/sources/find.vim'}]) + call s:assert.equals(unite#filters#lua_fuzzy_matcher( + \ [{'word' : 'app/code/local/Tbuy/Utils/Block/LocalCurrency.php'}], + \ { 'input' : 'apcoltbuyutilsblockl' }, 1), + \ [{'word' : 'app/code/local/Tbuy/Utils/Block/LocalCurrency.php'}]) + + call s:assert.equals(unite#filters#matcher_fuzzy#get_fuzzy_input( + \ 'fooooooooooooooooooooooooooooooooo'), + \ ['fooooooooooooooooooooooooooooooooo', '']) + call s:assert.equals(unite#filters#matcher_fuzzy#get_fuzzy_input( + \ 'fooooooooooooooooooooo/oooooooooooo'), + \ ['fooooooooooooooooooooo', '/oooooooooooo']) + + call s:assert.equals(unite#helper#paths2candidates( + \ ['foo']), [ + \ {'word' : 'foo', 'action__path' : 'foo'}]) + + call s:assert.equals(unite#filters#converter_relative_word#lua([ + \ {'word' : '/foo/foo'}, + \ {'word' : + \ unite#util#substitute_path_separator(expand('~/')).'bar'}, + \ {'word' : '/foo/foo', 'action__path' : '/foo/baz'}, + \ ], '/foo'), [ + \ {'word' : 'foo'}, {'word' : 'bar'}, + \ {'word' : 'baz', 'action__path' : '/foo/baz'} + \ ]) +endfunction + +" vim:foldmethod=marker:fen: diff --git a/test/sorter.vim b/test/sorter.vim new file mode 100644 index 00000000..78bef823 --- /dev/null +++ b/test/sorter.vim @@ -0,0 +1,44 @@ +let s:suite = themis#suite('parser') +let s:assert = themis#helper('assert') + +function! s:suite.sorter_rank() + if !has('lua') + return + endif + + for has_lua in range(2) + call s:assert.equals(map(unite#filters#sorter_rank#_sort( + \ [{'word' : 'g/vimrc.ln'}, {'word' : 'gvimrc.ln'}], + \ 'gvimr', has_lua), 'v:val.word'), ['gvimrc.ln', 'g/vimrc.ln']) + call s:assert.equals(map(unite#filters#sorter_rank#_sort( + \ [{'word' : 'g/vimrc.ln'}, {'word' : 'gvimrc.ln'}], + \ 'gvimrc', has_lua), 'v:val.word'), ['gvimrc.ln', 'g/vimrc.ln']) + call s:assert.equals(map(unite#filters#sorter_rank#_sort( + \ [{'word' : 'ab12345js12345tt'}, {'word' : 'ab.js.tt'}], + \ 'abjstt', has_lua), 'v:val.word'), ['ab.js.tt', 'ab12345js12345tt']) + call s:assert.equals(map(unite#filters#sorter_rank#_sort( + \ [{'word' : 'source/r', 'action__path' : ''}, + \ {'word' : 'sort.vim', 'action__path' : ''}], + \ 'so', has_lua), 'v:val.word'), ['sort.vim', 'source/r']) + call s:assert.equals(map(unite#filters#sorter_rank#_sort( + \ [{'word' : 'spammers.txt', 'action__path' : ''}, + \ {'word' : 'thread_parsing.py', 'action__path' : ''}], + \ 'pars', has_lua), 'v:val.word'), + \ ['thread_parsing.py', 'spammers.txt']) + endfor +endfunction + +function! s:suite.sorter_rank() + call s:assert.equals(unite#candidates#_group_post_filters([ + \ {'word' : 'foo', 'group' : 'bar'}, + \ {'word' : 'bar', 'group' : 'baz'}, + \ {'word' : 'qux', 'group' : 'baz'}]), [ + \ {'word' : 'bar', 'is_dummy' : 1}, + \ {'word' : 'foo', 'group' : 'bar'}, + \ {'word' : 'baz', 'is_dummy' : 1}, + \ {'word' : 'bar', 'group' : 'baz'}, + \ {'word' : 'qux', 'group' : 'baz'}, + \]) +endfunction + +" vim:foldmethod=marker:fen: diff --git a/test/source.vim b/test/source.vim new file mode 100644 index 00000000..45b9be44 --- /dev/null +++ b/test/source.vim @@ -0,0 +1,47 @@ +let s:suite = themis#suite('parser') +let s:assert = themis#helper('assert') + +let g:kind = { + \ 'name' : 'hoge', + \ 'default_action' : 'open', + \ 'action_table': {}, + \ } +let g:kind.action_table.open = { + \ 'is_selectable' : 1, + \ } +function! g:kind.action_table.open.func(candidate) + echo 'hoge' +endfunction + +let g:source = { + \ 'name' : 'hoge', + \ 'is_volatile' : 1, + \ 'variables' : {'foo' : 'foo'} + \} +function! g:source.gather_candidates(args, context) "{{{ + " Add dummy candidate. + let g:candidates = [ a:context.input ] + + call map(g:candidates, '{ + \ "word" : v:val, + \ "source" : "hoge", + \ "kind" : "hoge", + \}') + + return g:candidates +endfunction"}}} + +function! s:suite.source() + call s:assert.equals(unite#define_kind(g:kind), 0) + + call s:assert.equals(unite#define_source(g:source), 0) + call s:assert.true(!empty(unite#get_all_sources(g:source.name))) + + call s:assert.equals(unite#undef_kind(g:kind.name), 0) + + call s:assert.equals(unite#undef_source(g:source.name), 0) + call s:assert.true(empty(unite#get_all_sources(g:source.name))) + call s:assert.equals(unite#define_source(g:source), 0) +endfunction + +" vim:foldmethod=marker:fen: diff --git a/vest/test-matcher.vim b/vest/test-matcher.vim deleted file mode 100644 index db0a63fc..00000000 --- a/vest/test-matcher.vim +++ /dev/null @@ -1,85 +0,0 @@ -scriptencoding utf-8 - -" Saving 'cpoptions' {{{ -let s:save_cpo = &cpo -set cpo&vim -" }}} - -Context Source.run() - if has('lua') - call unite#filters#matcher_fuzzy#define() - - let g:fuzzy_save = g:unite_matcher_fuzzy_max_input_length - try - let g:unite_matcher_fuzzy_max_input_length = 20 - - It tests lua matcher. - ShouldEqual unite#filters#lua_matcher( - \ [{'word' : 'foo'}], { 'input' : 'foo' }, 0), [{'word' : 'foo'}] - ShouldEqual unite#filters#lua_matcher( - \ [{'word' : 'foo'}], { 'input' : 'bar' }, 0), [] - ShouldEqual unite#filters#lua_matcher( - \ [{'word' : 'Foo'}], { 'input' : 'foo'}, 0), [] - ShouldEqual unite#filters#lua_matcher( - \ [{'word' : 'Foo'}], { 'input' : 'foo'}, 1), [{'word' : 'Foo'}] - ShouldEqual unite#filters#lua_matcher( - \ [{'word' : 'Foo'}, {'word' : 'Bar'}], { 'input' : 'foo' }, 1), [{'word' : 'Foo'}] - ShouldEqual unite#filters#lua_matcher( - \ [{'word' : 'foo'}, {'word' : 'bar'}, - \ {'word' : 'foobar'}, {'word' : 'baz'}], - \ { 'input' : 'foo' }, 0), [{'word' : 'foo'}, {'word' : 'foobar'}] - ShouldEqual unite#filters#lua_fuzzy_matcher( - \ [{'word' : '/Users/core.cljs'}, {'word' : '/Users/core.js'}], - \ { 'input' : 'cl' }, 0), [{'word' : '/Users/core.cljs'}] - ShouldEqual unite#filters#lua_fuzzy_matcher( - \ [{'word' : '/Users/core.cljs'}, {'word' : '/Users/core.js'}], - \ { 'input' : 'co' }, 0), [{'word' : '/Users/core.cljs'}, {'word' : '/Users/core.js'}] - ShouldEqual unite#filters#lua_fuzzy_matcher( - \ [{'word' : '/Users/core.cljs'}, {'word' : '/Users/core.js'}], - \ { 'input' : '/U' }, 0), [{'word' : '/Users/core.cljs'}, {'word' : '/Users/core.js'}] - ShouldEqual unite#filters#lua_fuzzy_matcher( - \ [{'word' : '/Users/core.cljs'}, {'word' : '/Users/core.js'}], - \ { 'input' : '/Us' }, 0), [{'word' : '/Users/core.cljs'}, {'word' : '/Users/core.js'}] - ShouldEqual unite#filters#lua_fuzzy_matcher( - \ [{'word' : '/unite/sources/find.vim'}], - \ { 'input' : '/u/s/f' }, 0), [{'word' : '/unite/sources/find.vim'}] - ShouldEqual unite#filters#lua_fuzzy_matcher( - \ [{'word' : 'app/code/local/Tbuy/Utils/Block/LocalCurrency.php'}], - \ { 'input' : 'apcoltbuyutilsblockl' }, 1), - \ [{'word' : 'app/code/local/Tbuy/Utils/Block/LocalCurrency.php'}] - - ShouldEqual unite#filters#matcher_fuzzy#get_fuzzy_input( - \ 'fooooooooooooooooooooooooooooooooo'), - \ ['fooooooooooooooooooooooooooooooooo', ''] - ShouldEqual unite#filters#matcher_fuzzy#get_fuzzy_input( - \ 'fooooooooooooooooooooo/oooooooooooo'), - \ ['fooooooooooooooooooooo', '/oooooooooooo'] - - ShouldEqual unite#helper#paths2candidates( - \ ['foo']), [ - \ {'word' : 'foo', 'action__path' : 'foo'}, - \ ] - - ShouldEqual unite#filters#converter_relative_word#lua([ - \ {'word' : '/foo/foo'}, - \ {'word' : - \ unite#util#substitute_path_separator(expand('~/')).'bar'}, - \ {'word' : '/foo/foo', 'action__path' : '/foo/baz'}, - \ ], '/foo'), [ - \ {'word' : 'foo'}, {'word' : 'bar'}, - \ {'word' : 'baz', 'action__path' : '/foo/baz'} - \ ] - finally - let g:unite_matcher_fuzzy_max_input_length = g:fuzzy_save - endtry - End - endif -End - -Fin - -" Restore 'cpoptions' {{{ -let &cpo = s:save_cpo -" }}} - -" vim:foldmethod=marker:fen: diff --git a/vest/test-sorter.vim b/vest/test-sorter.vim deleted file mode 100644 index 715ccb07..00000000 --- a/vest/test-sorter.vim +++ /dev/null @@ -1,54 +0,0 @@ -scriptencoding utf-8 - -" Saving 'cpoptions' {{{ -let s:save_cpo = &cpo -set cpo&vim -" }}} - -Context Source.run() - if has('lua') - It tests sorter rank. - for g:has_lua in range(2) - ShouldEqual map(unite#filters#sorter_rank#_sort( - \ [{'word' : 'g/vimrc.ln'}, {'word' : 'gvimrc.ln'}], - \ 'gvimr', g:has_lua), 'v:val.word'), ['gvimrc.ln', 'g/vimrc.ln'] - ShouldEqual map(unite#filters#sorter_rank#_sort( - \ [{'word' : 'g/vimrc.ln'}, {'word' : 'gvimrc.ln'}], - \ 'gvimrc', g:has_lua), 'v:val.word'), ['gvimrc.ln', 'g/vimrc.ln'] - ShouldEqual map(unite#filters#sorter_rank#_sort( - \ [{'word' : 'ab12345js12345tt'}, {'word' : 'ab.js.tt'}], - \ 'abjstt', g:has_lua), 'v:val.word'), ['ab.js.tt', 'ab12345js12345tt'] - ShouldEqual map(unite#filters#sorter_rank#_sort( - \ [{'word' : 'source/r', 'action__path' : ''}, - \ {'word' : 'sort.vim', 'action__path' : ''}], - \ 'so', g:has_lua), 'v:val.word'), ['sort.vim', 'source/r'] - ShouldEqual map(unite#filters#sorter_rank#_sort( - \ [{'word' : 'spammers.txt', 'action__path' : ''}, - \ {'word' : 'thread_parsing.py', 'action__path' : ''}], - \ 'pars', g:has_lua), 'v:val.word'), - \ ['thread_parsing.py', 'spammers.txt'] - endfor - End - endif - - It tests group feature. - ShouldEqual unite#candidates#_group_post_filters([ - \ {'word' : 'foo', 'group' : 'bar'}, - \ {'word' : 'bar', 'group' : 'baz'}, - \ {'word' : 'qux', 'group' : 'baz'}]), [ - \ {'word' : 'bar', 'is_dummy' : 1}, - \ {'word' : 'foo', 'group' : 'bar'}, - \ {'word' : 'baz', 'is_dummy' : 1}, - \ {'word' : 'bar', 'group' : 'baz'}, - \ {'word' : 'qux', 'group' : 'baz'}, - \] - End -End - -Fin - -" Restore 'cpoptions' {{{ -let &cpo = s:save_cpo -" }}} - -" vim:foldmethod=marker:fen: diff --git a/vest/test-source.vim b/vest/test-source.vim deleted file mode 100644 index f2856f09..00000000 --- a/vest/test-source.vim +++ /dev/null @@ -1,81 +0,0 @@ -scriptencoding utf-8 - -" Saving 'cpoptions' {{{ -let s:save_cpo = &cpo -set cpo&vim -" }}} - -let g:kind = { - \ 'name' : 'hoge', - \ 'default_action' : 'open', - \ 'action_table': {}, - \ } -let g:kind.action_table.open = { - \ 'is_selectable' : 1, - \ } -function! g:kind.action_table.open.func(candidate) - echo 'hoge' -endfunction - -let g:source = { - \ 'name' : 'hoge', - \ 'is_volatile' : 1, - \ 'variables' : {'foo' : 'foo'} - \} -function! g:source.gather_candidates(args, context) "{{{ - " Add dummy candidate. - let g:candidates = [ a:context.input ] - - call map(g:candidates, '{ - \ "word" : v:val, - \ "source" : "hoge", - \ "kind" : "hoge", - \}') - - return g:candidates -endfunction"}}} - -Context Source.run() - It defines kind - Should unite#define_kind(g:kind) == 0 - End - - It defines source - Should unite#define_source(g:source) == 0 - Should !empty(unite#get_all_sources(g:source.name)) - End - - It undefines kind - Should unite#undef_kind(g:kind.name) == 0 - End - - It undefines source - Should unite#undef_source(g:source.name) == 0 - Should empty(unite#get_all_sources(g:source.name)) - Should unite#define_source(g:source) == 0 - End - - It call do_candidates_action - let g:candidates = unite#get_candidates( - \ [['grep', fnamemodify(expand(''), ':h'), '', 'hoge']]) - End - - It get candidates - call unite#custom_max_candidates('file_mru', 1) - let g:candidates = unite#get_candidates(['file_mru']) - ShouldEqual len(g:candidates), len(readfile( - \ unite#helper#get_data_directory() . '/file_mru'))-1 - - let g:candidates = unite#get_candidates([ - \ ['grep', 'unite.vim/plugin', '', 'vim']]) - call unite#action#do_candidates('replace', g:candidates) - End -End - -Fin - -" Restore 'cpoptions' {{{ -let &cpo = s:save_cpo -" }}} - -" vim:foldmethod=marker:fen: