diff --git a/autoload/todo/txt.vim b/autoload/todo/txt.vim index 78769e2..d87f420 100644 --- a/autoload/todo/txt.vim +++ b/autoload/todo/txt.vim @@ -79,7 +79,9 @@ function! todo#txt#sort_by_project() range endfunction function! todo#txt#sort_by_date() range - execute a:firstline . "," . a:lastline . "sort /\\d\\{2,4\\}-\\d\\{2\\}-\\d\\{2\\}/ r" + let l:date_regex = "\\d\\{2,4\\}-\\d\\{2\\}-\\d\\{2\\}" + execute a:firstline . "," . a:lastline . "sort /" . l:date_regex . "/ r" + execute a:firstline . "," . a:lastline . "g!/" . l:date_regex . "/m" . a:lastline endfunction " Increment and Decrement The Priority diff --git a/test/tc_sort_date.todo.txt b/test/tc_sort_date.todo.txt index 82220bd..1144c24 100644 --- a/test/tc_sort_date.todo.txt +++ b/test/tc_sort_date.todo.txt @@ -3,3 +3,10 @@ (B) 2012-04-16 2015-04-16 (A) 2013-03-16 2013-03-10 # end_lorem_ipsum +# task_with_no_date +2013-03-15 task with date +task with no date +2013-03-15 task with date +2013-03-15 task with date +task with no date +# end_task_with_no_date diff --git a/test/tc_sort_date.vim b/test/tc_sort_date.vim index 817818b..8041c0d 100644 --- a/test/tc_sort_date.vim +++ b/test/tc_sort_date.vim @@ -10,9 +10,22 @@ let s:SORTED_TASKS = [ \ '(A) 2013-03-16 2013-03-10', \ ] -function! s:tc.test_sort_by_context() +let s:SORTED_TASKS_WITH_NO_DATE = [ + \ '2013-03-15 task with date', + \ '2013-03-15 task with date', + \ '2013-03-15 task with date', + \ 'task with no date', + \ 'task with no date', + \ ] + +function! s:tc.test_sort_by_date() call self.data.visual_execute('call todo#txt#sort_by_date()', 'lorem_ipsum') call self.assert_equal(s:SORTED_TASKS, self.data.get('lorem_ipsum')) endfunction +function! s:tc.test_sort_by_date_with_tasks_without_date() + call self.data.visual_execute('call todo#txt#sort_by_date()', 'task_with_no_date') + call self.assert_equal(s:SORTED_TASKS_WITH_NO_DATE, self.data.get('task_with_no_date')) +endfunction + unlet s:tc