Skip to content
Browse files

Add tests of unite#kinds#giti#log

del unused line
  • Loading branch information...
1 parent 06527d3 commit aec546e23772b63b339f52874e58d2e173cadbc6 @kmnk committed Nov 8, 2012
View
18 autoload/unite/kinds/giti/log.vim
@@ -34,9 +34,9 @@ function! s:kind.action_table.view.func(candidate)"{{{
call giti#print( 'Hash: ' . data.hash)
call giti#print( 'ParentHash: ' . data.parent_hash)
call giti#print(printf('Author: %s <%s> - %s',
-\ data.author.name, data.author.mail, data.author.date))
+\ data.author.name, data.author.mail, data.author.date))
call giti#print(printf('Committer: %s <%s> - %s',
-\ data.committer.name, data.committer.mail, data.committer.date))
+\ data.committer.name, data.committer.mail, data.committer.date))
call giti#print( 'Comment: ' . data.comment)
endfunction"}}}
@@ -72,7 +72,7 @@ function! s:kind.action_table.diff.func(candidates)"{{{
return
endif
- call giti#new_buffer({
+ return giti#new_buffer({
\ 'method' : giti#edit_command(),
\ 'string' : diff,
\ 'filetype' : 'diff',
@@ -156,6 +156,18 @@ function! s:is_graph_only_line(candidate)"{{{
endfunction"}}}
" }}}
+" context getter {{{
+function! s:get_SID()
+ return matchstr(expand('<sfile>'), '<SNR>\d\+_')
+endfunction
+let s:SID = s:get_SID()
+delfunction s:get_SID
+
+function! unite#kinds#giti#log#__context__()
+ return { 'sid': s:SID, 'scope': s: }
+endfunction
+"}}}
+
let &cpo = s:save_cpo
unlet s:save_cpo
" __END__
View
1 test/autoload/unite/kinds/giti/test_all.vim
@@ -2,3 +2,4 @@ let s:here = expand('<sfile>:p:h')
execute 'source' s:here . '/branch/test_all.vim'
execute 'source' s:here . '/test_branch.vim'
execute 'source' s:here . '/test_config.vim'
+execute 'source' s:here . '/test_log.vim'
View
222 test/autoload/unite/kinds/giti/test_log.vim
@@ -0,0 +1,222 @@
+let s:tc = unittest#testcase#new('autoload/unite/kinds/giti/log.vim',
+\ unite#kinds#giti#log#__context__())
+
+function! s:tc.SETUP()"{{{
+endfunction"}}}
+function! s:tc.TEARDOWN()"{{{
+endfunction"}}}
+
+function! s:tc.test_define()"{{{
+ call self.assert_equal(
+\ type({}),
+\ type(unite#kinds#giti#log#define()),
+\ )
+ call self.assert_throw('E118', 'call self.call("unite#kinds#giti#log#define", [""])')
+endfunction"}}}
+
+function! s:tc.kind_should_have()"{{{
+ let kind = self.get('s:kind')
+ call self.assert_equal(type({}), type(kind))
+ call self.assert_equal('giti/log', kind.name)
+ call self.assert_equal(type(''), type(kind.default_action))
+ call self.assert_equal(type({}), type(kind.action_table))
+ call self.assert_equal(type({}), type(kind.alias_table))
+endfunction"}}}
+
+function! s:tc.test_kind_action_view()"{{{
+ let kind = self.get('s:kind')
+ let view = kind.action_table.view
+ call self.assert_equal(type({}), type(view))
+ call self.assert_equal(type(''), type(view.description))
+ call self.assert_equal(view.is_selectable, 0)
+ call self.assert_equal(view.is_quit, 0)
+ call self.assert_equal(view.is_invalidate_cache, 0)
+ call self.assert_equal(type(function('tr')), type(view.func))
+
+ let candidate = {
+\ 'action__data' : {
+\ 'hash' : 'hoge',
+\ 'parent_hash' : 'fuga',
+\ 'author' : {'name' : 'foo', 'mail' : 'bar', 'date' : 'baz'},
+\ 'committer' : {'name' : 'foo', 'mail' : 'bar', 'date' : 'baz'},
+\ 'comment' : 'piyo',
+\ }
+\ }
+ call view.func(candidate)
+endfunction"}}}
+
+function! s:tc.setup_kind_action_diff()"{{{
+ function! giti#diff#specify(param)"{{{
+ let b:diff_specify_called_with = a:param
+ return 'mocked giti#diff#specify'
+ endfunction"}}}
+endfunction"}}}
+function! s:tc.teardown_kind_action_diff()"{{{
+ let paths = split(globpath(&rtp, 'autoload/giti/diff.vim'), '\n')
+ execute 'source ' . paths[0]
+endfunction"}}}
+function! s:tc.test_kind_action_diff()"{{{
+ let kind = self.get('s:kind')
+ let diff = kind.action_table.diff
+ call self.assert_equal(type({}), type(diff))
+ call self.assert_equal(type(''), type(diff.description))
+ call self.assert_equal(diff.is_selectable, 1)
+ call self.assert_equal(diff.is_quit, 1)
+ call self.assert_equal(diff.is_invalidate_cache, 0)
+ call self.assert_equal(type(function('tr')), type(diff.func))
+
+ let candidates = map(range(2), '
+\ {
+\ "action__data" : {
+\ "hash" : "hoge" . v:val,
+\ "parent_hash" : "fuga" . v:val,
+\ "author" : {"name" : "foo" . v:val, "mail" : "bar" . v:val, "date" : "baz" . v:val},
+\ "committer" : {"name" : "foo" . v:val, "mail" : "bar" . v:val, "date" : "baz" . v:val},
+\ "comment" : "piyo" . v:val,
+\ },
+\ "action__file" : "qux" . v:val
+\ }
+\ ')
+ call self.assert(diff.func([candidates[0]]))
+ call self.assert_equal(
+\ { 'from' : candidates[0].action__data.parent_hash,
+\ 'to' : candidates[0].action__data.hash,
+\ 'files' : [candidates[0].action__file]
+\ },
+\ b:diff_specify_called_with
+\ )
+
+ call self.assert(diff.func(candidates))
+ call self.assert_equal(
+\ { 'from' : candidates[1].action__data.hash,
+\ 'to' : candidates[0].action__data.hash,
+\ 'files' : [candidates[0].action__file]
+\ },
+\ b:diff_specify_called_with
+\ )
+endfunction"}}}
+
+function! s:tc.setup_kind_action_revert()"{{{
+ function! giti#revert#run(hashes)"{{{
+ let b:revert_run_called_with = a:hashes
+ return 'mocked giti#revert#run'
+ endfunction"}}}
+endfunction"}}}
+function! s:tc.teardown_kind_action_revert()"{{{
+ let paths = split(globpath(&rtp, 'autoload/giti/revert.vim'), '\n')
+ execute 'source ' . paths[0]
+endfunction"}}}
+function! s:tc.test_kind_action_revert()"{{{
+ let kind = self.get('s:kind')
+ let revert = kind.action_table.revert
+ call self.assert_equal(type({}), type(revert))
+ call self.assert_equal(type(''), type(revert.description))
+ call self.assert_equal(revert.is_selectable, 0)
+ call self.assert_equal(revert.is_quit, 1)
+ call self.assert_equal(revert.is_invalidate_cache, 0)
+ call self.assert_equal(type(function('tr')), type(revert.func))
+
+ let candidate = {
+\ "action__data" : {
+\ "hash" : "hoge",
+\ },
+\ }
+ call revert.func(candidate)
+ call self.assert_equal(
+\ [ candidate.action__data.hash ],
+\ b:revert_run_called_with
+\ )
+endfunction"}}}
+
+function! s:tc.setup_kind_action_vimdiff()"{{{
+ function! giti#diff#view_vim_diff(hashes)"{{{
+ let b:diff_view_vim_diff_called_with = a:hashes
+ return 'mocked giti#diff#view_vim_diff'
+ endfunction"}}}
+endfunction"}}}
+function! s:tc.teardown_kind_action_vimdiff()"{{{
+ let paths = split(globpath(&rtp, 'autoload/giti/diff.vim'), '\n')
+ execute 'source ' . paths[0]
+endfunction"}}}
+function! s:tc.test_kind_action_vimdiff()"{{{
+ let kind = self.get('s:kind')
+ let vimdiff = kind.action_table.vimdiff
+ call self.assert_equal(type({}), type(vimdiff))
+ call self.assert_equal(type(''), type(vimdiff.description))
+ call self.assert_equal(vimdiff.is_selectable, 1)
+ call self.assert_equal(vimdiff.is_quit, 1)
+ call self.assert_equal(vimdiff.is_invalidate_cache, 0)
+ call self.assert_equal(type(function('tr')), type(vimdiff.func))
+
+ let candidates = map(range(2), '
+\ {
+\ "action__data" : {
+\ "hash" : "hoge" . v:val,
+\ "parent_hash" : "fuga" . v:val,
+\ "author" : {"name" : "foo" . v:val, "mail" : "bar" . v:val, "date" : "baz" . v:val},
+\ "committer" : {"name" : "foo" . v:val, "mail" : "bar" . v:val, "date" : "baz" . v:val},
+\ "comment" : "piyo" . v:val,
+\ },
+\ "action__file" : "qux" . v:val
+\ }
+\ ')
+ call vimdiff.func([candidates[0]])
+ call self.assert_equal(
+\ { 'from' : candidates[0].action__data.parent_hash,
+\ 'to' : candidates[0].action__data.hash,
+\ 'file' : candidates[0].action__file
+\ },
+\ b:diff_view_vim_diff_called_with
+\ )
+
+ call vimdiff.func(candidates)
+ call self.assert_equal(
+\ { 'from' : candidates[1].action__data.hash,
+\ 'to' : candidates[0].action__data.hash,
+\ 'file' : candidates[0].action__file
+\ },
+\ b:diff_view_vim_diff_called_with
+\ )
+endfunction"}}}
+
+function! s:tc.setup_kind_action_reset_hard()"{{{
+ function! giti#reset#hard(param)"{{{
+ let b:reset_hard_called_with = a:param
+ return 'mocked giti#reset#hard'
+ endfunction"}}}
+endfunction"}}}
+function! s:tc.teardown_kind_action_reset_hard()"{{{
+ let paths = split(globpath(&rtp, 'autoload/giti/reset.vim'), '\n')
+ execute 'source ' . paths[0]
+endfunction"}}}
+function! s:tc.test_kind_action_reset_hard()"{{{
+ let kind = self.get('s:kind')
+ let reset_hard = kind.action_table.reset_hard
+ call self.assert_equal(type({}), type(reset_hard))
+ call self.assert_equal(type(''), type(reset_hard.description))
+ call self.assert_equal(reset_hard.is_selectable, 0)
+ call self.assert_equal(reset_hard.is_quit, 1)
+ call self.assert_equal(reset_hard.is_invalidate_cache, 0)
+ call self.assert_equal(type(function('tr')), type(reset_hard.func))
+
+ let candidate = {
+\ "action__data" : {
+\ "hash" : "hoge",
+\ },
+\ }
+ call reset_hard.func(candidate)
+ call self.assert_equal(
+\ { 'hash' : candidate.action__data.hash },
+\ b:reset_hard_called_with
+\ )
+endfunction"}}}
+
+function! s:tc.test_kind_alias_table_has()"{{{
+ let kind = self.get('s:kind')
+ let table = kind.alias_table
+ call self.assert_equal(table.di, 'diff')
+ call self.assert_equal(table.vdi, 'vimdiff')
+ call self.assert_equal(table.reset_hard, 'reset')
+endfunction"}}}
+
+unlet s:tc

0 comments on commit aec546e

Please sign in to comment.
Something went wrong with that request. Please try again.