diff --git a/autoload/todo/txt.vim b/autoload/todo/txt.vim index d87f420..feaad6e 100644 --- a/autoload/todo/txt.vim +++ b/autoload/todo/txt.vim @@ -26,7 +26,7 @@ function! s:get_current_date() endfunction function! todo#txt#prepend_date() - execute 'normal! 0"='.string(s:get_current_date().' ').' P' + execute 's/^\(([a-zA-Z]) \)\?/\1' . s:get_current_date() . ' /' endfunction function! todo#txt#mark_as_done() diff --git a/test/tc_date.todo.txt b/test/tc_date.todo.txt index d7ef348..72966e4 100644 --- a/test/tc_date.todo.txt +++ b/test/tc_date.todo.txt @@ -1,3 +1,12 @@ # lorem_ipsum example task # end_lorem_ipsum + +# date_after_priority +(A) Call Mom +# end_date_after_priority + +# date_after_priority_visual +(A) Call Mom +(B) Call Dad +# end_date_after_priority_visual diff --git a/test/tc_date.vim b/test/tc_date.vim index 9da7349..02f817c 100644 --- a/test/tc_date.vim +++ b/test/tc_date.vim @@ -13,8 +13,13 @@ let s:DATE_INSERTED = [ \ s:TODAY . ' example task', \ ] -let s:DATE_INSERTED_VISUAL = [ - \ s:TODAY . ' example task', +let s:DATE_INSERTED_AFTER_PRIORITY = [ + \ '(A) ' . s:TODAY . ' Call Mom', + \ ] + +let s:DATE_INSERTED_AFTER_PRIORITY_VISUAL = [ + \ '(A) ' . s:TODAY . ' Call Mom', + \ '(B) ' . s:TODAY . ' Call Dad', \ ] function! s:tc.test_insert_date_normal_mode() @@ -26,12 +31,24 @@ endfunction function! s:tc.test_insert_date_insert_mode() call self.data.goto('lorem_ipsum') execute 'normal idate ' - call self.assert_equal(s:DATE_INSERTED_VISUAL, self.data.get('lorem_ipsum')) + call self.assert_equal(s:DATE_INSERTED, self.data.get('lorem_ipsum')) endfunction function! s:tc.test_insert_date_visual_mode() call self.data.visual_execute('call todo#txt#prepend_date()', 'lorem_ipsum') - call self.assert_equal(s:DATE_INSERTED_VISUAL, self.data.get('lorem_ipsum')) + call self.assert_equal(s:DATE_INSERTED, self.data.get('lorem_ipsum')) +endfunction + +function! s:tc.test_insert_date_after_priority_normal_mode() + call self.data.goto('date_after_priority') + call self.data.execute('call todo#txt#prepend_date()', 'date_after_priority') + call self.assert_equal(s:DATE_INSERTED_AFTER_PRIORITY, self.data.get('date_after_priority')) +endfunction + +function! s:tc.test_insert_date_after_priority_visual_mode() + call self.data.goto('date_after_priority_visual') + call self.data.visual_execute('call todo#txt#prepend_date()', 'date_after_priority_visual') + call self.assert_equal(s:DATE_INSERTED_AFTER_PRIORITY_VISUAL, self.data.get('date_after_priority_visual')) endfunction unlet s:tc