Permalink
Browse files

Implement mv funvtions

  • Loading branch information...
1 parent 40be51a commit a2968a6faffbce5c2dde82dd52ffa600107e0721 @kmnk committed Oct 11, 2012
Showing with 160 additions and 0 deletions.
  1. +55 −0 autoload/giti/mv.vim
  2. +1 −0 test/autoload/giti/test_all.vim
  3. +104 −0 test/autoload/giti/test_mv.vim
View
55 autoload/giti/mv.vim
@@ -0,0 +1,55 @@
+" File: mv.vim
+" Author: kmnk <kmnknmk+vim@gmail.com>
+" Version: 0.1.0
+" License: MIT Licence
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+" variables {{{
+" }}}
+
+function! giti#mv#run(param) abort"{{{
+ return s:run('', a:param)
+endfunction"}}}
+
+function! giti#mv#force(param)"{{{
+ return s:run('-f', a:param)
+endfunction"}}}
+
+function! giti#mv#verbose(param)"{{{
+ return s:run('-v', a:param)
+endfunction"}}}
+
+" local functions {{{
+function! s:run(option, param) abort"{{{
+ if !has_key(a:param, 'source') || len(a:param.source) <= 0
+ throw 'source is required'
+ endif
+
+ if (!has_key(a:param, 'destination') || len(a:param.destination) <= 0)
+\ && (!has_key(a:param, 'destination_directory') || len(a:param.destination_directory) <= 0)
+ throw 'destination is required'
+ endif
+
+ let source = a:param.source
+ let destination
+\ = has_key(a:param, 'destination') ? a:param.destination
+\ : ''
+ let destination_directory
+\ = has_key(a:param, 'destination_directory') ? a:param.destination_directory
+\ : ''
+
+ let option = len(a:option) <= 0 ? ''
+\ : ' ' . a:option
+
+ return giti#system('' != destination
+\ ? printf('mv%s %s %s', option, source, destination)
+\ : printf('mv%s %s ... %s', option, source, destination_directory)
+\ )
+endfunction"}}}
+" }}}
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
+" __END__
View
1 test/autoload/giti/test_all.vim
@@ -10,6 +10,7 @@ execute 'source' s:here . '/test_diff.vim'
execute 'source' s:here . '/test_fetch.vim'
execute 'source' s:here . '/test_log.vim'
execute 'source' s:here . '/test_merge.vim'
+execute 'source' s:here . '/test_mv.vim'
execute 'source' s:here . '/test_pull.vim'
execute 'source' s:here . '/test_push.vim'
execute 'source' s:here . '/test_rebase.vim'
View
104 test/autoload/giti/test_mv.vim
@@ -0,0 +1,104 @@
+let s:tc = unittest#testcase#new('autoloda/giti/mv.vim')
+
+function! s:tc.SETUP()"{{{
+endfunction"}}}
+function! s:tc.TEARDOWN()"{{{
+endfunction"}}}
+
+function! s:tc.test_run()"{{{
+ call giti#mv#run({
+\ 'source' : 'hoge',
+\ 'destination' : 'fuga',
+\ })
+ call self.assert_match('mv hoge fuga', b:system_called_with)
+
+ call giti#mv#run({
+\ 'source' : 'hoge',
+\ 'destination_directory' : 'piyo',
+\ })
+ call self.assert_match('mv hoge ... piyo', b:system_called_with)
+
+ call giti#mv#run({
+\ 'source' : 'hoge',
+\ 'destination' : 'fuga',
+\ 'destination_directory' : 'piyo',
+\ })
+ call self.assert_match('mv hoge fuga', b:system_called_with)
+
+ call self.assert_throw('source is required', '
+\ call giti#mv#run({"destination" : "fuga"})
+\ ')
+
+ call self.assert_throw('destination is required', '
+\ call giti#mv#run({"source" : "hoge"})
+\ ')
+
+ call self.assert_throw('E118', 'call giti#mv#run("", "")')
+ call self.assert_throw('E119', 'call giti#mv#run()')
+endfunction"}}}
+
+function! s:tc.test_force()"{{{
+ call giti#mv#force({
+\ 'source' : 'hoge',
+\ 'destination' : 'fuga',
+\ })
+ call self.assert_match('mv -f hoge fuga', b:system_called_with)
+
+ call giti#mv#force({
+\ 'source' : 'hoge',
+\ 'destination_directory' : 'piyo',
+\ })
+ call self.assert_match('mv -f hoge ... piyo', b:system_called_with)
+
+ call giti#mv#force({
+\ 'source' : 'hoge',
+\ 'destination' : 'fuga',
+\ 'destination_directory' : 'piyo',
+\ })
+ call self.assert_match('mv -f hoge fuga', b:system_called_with)
+
+ call self.assert_throw('source is required', '
+\ call giti#mv#force({"destination" : "fuga"})
+\ ')
+
+ call self.assert_throw('destination is required', '
+\ call giti#mv#force({"source" : "hoge"})
+\ ')
+
+ call self.assert_throw('E118', 'call giti#mv#force("", "")')
+ call self.assert_throw('E119', 'call giti#mv#force()')
+endfunction"}}}
+
+function! s:tc.test_verbose()"{{{
+ call giti#mv#verbose({
+\ 'source' : 'hoge',
+\ 'destination' : 'fuga',
+\ })
+ call self.assert_match('mv -v hoge fuga', b:system_called_with)
+
+ call giti#mv#verbose({
+\ 'source' : 'hoge',
+\ 'destination_directory' : 'piyo',
+\ })
+ call self.assert_match('mv -v hoge ... piyo', b:system_called_with)
+
+ call giti#mv#verbose({
+\ 'source' : 'hoge',
+\ 'destination' : 'fuga',
+\ 'destination_directory' : 'piyo',
+\ })
+ call self.assert_match('mv -v hoge fuga', b:system_called_with)
+
+ call self.assert_throw('source is required', '
+\ call giti#mv#verbose({"destination" : "fuga"})
+\ ')
+
+ call self.assert_throw('destination is required', '
+\ call giti#mv#verbose({"source" : "hoge"})
+\ ')
+
+ call self.assert_throw('E118', 'call giti#mv#verbose("", "")')
+ call self.assert_throw('E119', 'call giti#mv#verbose()')
+endfunction"}}}
+
+unlet s:tc

0 comments on commit a2968a6

Please sign in to comment.