From 77cfafb9f0ff73b72f3feb4d58ad57a76120d45b Mon Sep 17 00:00:00 2001 From: Leandro Freitas Date: Thu, 14 May 2015 14:55:31 -0300 Subject: [PATCH] Fixes #37. Inserting date on new tasks --- autoload/todo/txt.vim | 4 +++- test/tc_date.todo.txt | 4 ++++ test/tc_date.vim | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/autoload/todo/txt.vim b/autoload/todo/txt.vim index 6c59ee4..24f2cfd 100644 --- a/autoload/todo/txt.vim +++ b/autoload/todo/txt.vim @@ -26,7 +26,9 @@ function! s:get_current_date() endfunction function! todo#txt#prepend_date() - if exists('g:todo_existing_date') && g:todo_existing_date == 'n' + let current_line = getline('.') + if (current_line =~ '^\(([a-zA-Z]) \)\?\d\{2,4\}-\d\{2\}-\d\{2\} ') && + exists('g:todo_existing_date') && g:todo_existing_date == 'n' return endif execute 's/^\(([a-zA-Z]) \)\?\(\d\{2,4\}-\d\{2\}-\d\{2\} \)\?/\1' . s:get_current_date() . ' /' diff --git a/test/tc_date.todo.txt b/test/tc_date.todo.txt index a6d6eac..beb7d5e 100644 --- a/test/tc_date.todo.txt +++ b/test/tc_date.todo.txt @@ -22,3 +22,7 @@ example task # existing_date_do_nothing 2014-05-06 example task # end_existing_date_do_nothing + +# non_existing_date_do_nothing +new todo line +# end_non_existing_date_do_nothing diff --git a/test/tc_date.vim b/test/tc_date.vim index fed665d..c43fc1c 100644 --- a/test/tc_date.vim +++ b/test/tc_date.vim @@ -26,6 +26,10 @@ let s:DATE_INSERTED_DO_NOTHING = [ \ '2014-05-06 example task', \ ] +let s:NON_EXISTING_DATE_INSERTED_DO_NOTHING = [ + \ s:TODAY . ' new todo line', + \ ] + function! s:tc.test_insert_date_normal_mode() call self.data.goto('lorem_ipsum') call todo#txt#prepend_date() @@ -70,4 +74,11 @@ function! s:tc.test_insert_with_existing_date_and_priority() unlet g:todo_existing_date endfunction +function! s:tc.test_insert_with_existing_date_and_priority() + let g:todo_existing_date = 'n' + call self.data.execute('call todo#txt#prepend_date()', 'non_existing_date_do_nothing') + call self.assert_equal(s:NON_EXISTING_DATE_INSERTED_DO_NOTHING, self.data.get('non_existing_date_do_nothing')) + unlet g:todo_existing_date +endfunction + unlet s:tc