mirror of
https://github.com/freitass/todo.txt-vim.git
synced 2025-11-14 21:03:46 -05:00
Testing date functions
This commit is contained in:
@@ -10,6 +10,12 @@ let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" Export Context Dictionary for unit testing {{{1
|
||||
function! s:get_SID()
|
||||
return matchstr(expand('<sfile>'), '<SNR>\d\+_')
|
||||
endfunction
|
||||
let s:SID = s:get_SID()
|
||||
delfunction s:get_SID
|
||||
|
||||
function! todo#__context__()
|
||||
return { 'sid': s:SID, 'scope': s: }
|
||||
endfunction
|
||||
@@ -26,8 +32,12 @@ function! s:TodoTxtRemovePriority()
|
||||
:s/^(\w)\s\+//ge
|
||||
endfunction
|
||||
|
||||
function! s:TodoTxtGetCurrentDate()
|
||||
return strftime('%Y-%m-%d')
|
||||
endfunction
|
||||
|
||||
function! TodoTxtPrependDate()
|
||||
normal! 0"=strftime("%Y-%m-%d ")
|
||||
execute 'normal! 0"='.string(s:TodoTxtGetCurrentDate().' ').'
|
||||
P'
|
||||
endfunction
|
||||
|
||||
|
||||
3
test/tc_date.todo.txt
Normal file
3
test/tc_date.todo.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
# lorem_ipsum
|
||||
example task
|
||||
# end_lorem_ipsum
|
||||
38
test/tc_date.vim
Normal file
38
test/tc_date.vim
Normal file
@@ -0,0 +1,38 @@
|
||||
let s:here = expand('<sfile>:p:h')
|
||||
let s:context = todo#__context__()
|
||||
let s:context['data'] = s:here . '/tc_date.todo.txt'
|
||||
let s:tc = unittest#testcase#new('Date', s:context)
|
||||
|
||||
let s:LEADER = mapleader
|
||||
let s:TODAY = strftime("%Y-%m-%d")
|
||||
|
||||
function! s:tc.test_current_date()
|
||||
call self.assert_equal(s:TODAY, self.call('s:TodoTxtGetCurrentDate', []))
|
||||
endfunction
|
||||
|
||||
let s:DATE_INSERTED = [
|
||||
\ s:TODAY . ' example task',
|
||||
\ ]
|
||||
|
||||
let s:DATE_INSERTED_VISUAL = [
|
||||
\ s:TODAY . ' example task',
|
||||
\ ]
|
||||
|
||||
function! s:tc.test_insert_date_normal_mode()
|
||||
call self.data.goto('lorem_ipsum')
|
||||
execute 'normal ' . s:LEADER . 'd'
|
||||
call self.assert_equal(s:DATE_INSERTED, self.data.get('lorem_ipsum'))
|
||||
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'))
|
||||
endfunction
|
||||
|
||||
function! s:tc.test_insert_date_visual_mode()
|
||||
call self.data.visual_execute('call TodoTxtPrependDate()', 'lorem_ipsum')
|
||||
call self.assert_equal(s:DATE_INSERTED_VISUAL, self.data.get('lorem_ipsum'))
|
||||
endfunction
|
||||
|
||||
unlet s:tc
|
||||
Reference in New Issue
Block a user