Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Nov 27, 2014
1 parent cc046a2 commit 6f67937
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 220 deletions.
78 changes: 78 additions & 0 deletions 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:
44 changes: 44 additions & 0 deletions 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:
47 changes: 47 additions & 0 deletions 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:
85 changes: 0 additions & 85 deletions vest/test-matcher.vim

This file was deleted.

54 changes: 0 additions & 54 deletions vest/test-sorter.vim

This file was deleted.

81 changes: 0 additions & 81 deletions vest/test-source.vim

This file was deleted.

0 comments on commit 6f67937

Please sign in to comment.