Fix for <Leader>x and other minor issues

Fixed a bug in <Leader>x (todo#PrependDate) introduced last commit.
Fixed case sensitivity bug in todo#ToggleMarkAsDone() and todo#UnMarkAsDone()
Fixed errors being reported for repeat#set if vim-repeat plugin is not installed.
Fixed modeline in .vim files to work (only works on first/last 5 lines of file), and made the modelines consistent across all files.
New unit tests for todo#ToggleMarkAsDone()
Minor fixes for README.md and man page
Fix anchoring of RegExp in todo#ToggleMarkAsDone
Fixed a bug in overdue highlighting that resulted in the current date being matched on round dates like the 20th and 30th.
Added more unit tests for overdue date highlighting.
Corrected RegExp anchoring on today date highlighting.
Added a few bash scripts to make running unit tests easier and more reliable, including testing with ignorecase user preference set.
This commit is contained in:
fretep
2017-09-19 23:45:56 +10:00
parent c2ad4bc58b
commit c8092640df
11 changed files with 295 additions and 45 deletions

16
tests/clean-vim.sh Normal file
View File

@@ -0,0 +1,16 @@
#/bin/bash
# Start a clean vim for testing development.
REPO_TOP=$(git rev-parse --show-toplevel)
cd "${REPO_TOP}"
vim -Nu <(cat <<EOF
filetype off
set rtp+=~/.vim/bundle/vader.vim
set rtp+=./
filetype plugin indent on
syntax enable
EOF
) tests/todo.txt

46
tests/runtests.sh Normal file
View File

@@ -0,0 +1,46 @@
#/bin/bash
REPO_TOP=$(git rev-parse --show-toplevel)
cd "${REPO_TOP}"
echo "Basic environment"
echo "-----------------"
vim -Nu <(cat <<EOF
filetype off
set rtp+=~/.vim/bundle/vader.vim
set rtp+=./
filetype plugin indent on
syntax enable
EOF
) +Vader! tests/*.vader && echo Success || exit 1
# Run through variations of user preferences that might mess with us.
echo
echo "Ignore case enabled"
echo "-------------------"
vim -Nu <(cat <<EOF
filetype off
set rtp+=~/.vim/bundle/vader.vim
set rtp+=./
filetype plugin indent on
syntax enable
set ignorecase
EOF
) +Vader! tests/*.vader && echo Success || exit 1
echo
echo "no hyphen in iskeyword"
echo "----------------------"
vim -Nu <(cat <<EOF
filetype off
set rtp+=~/.vim/bundle/vader.vim
set rtp+=./
filetype plugin indent on
syntax enable
set iskeyword+=-
EOF
) +Vader! tests/*.vader && echo Success || exit 1
echo
echo "All tests are passing."
echo

118
tests/todo.txt Normal file
View File

@@ -0,0 +1,118 @@
x Test todo.txt file with a number of test cases from the vader unit tests for quick manual checks.
x . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 L01
x 345678901234567890123456789012345678901234567890123456789012345678901234567890 L02
x (A) Done due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L03
Active due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L04
x 345678901234567890123456789012345678901234567890123456789012345678901234567890 L05
x . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 L06
x . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 L01
x 345678901234567890123456789012345678901234567890123456789012345678901234567890 L02
(A) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L03
(B) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L04
(C) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L05
(D) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L06
(E) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L07
(F) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L08
(G) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L09
(H) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L10
(I) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L11
(J) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L12
(K) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L13
(L) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L14
(M) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L15
(N) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L16
(O) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L17
(P) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L18
(Q) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L19
(R) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L20
(S) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L21
(T) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L22
(U) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L23
(V) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L24
(W) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L25
(X) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L26
(Y) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L27
(Z) Priorit due:2000-01-01 due:2050-01-01 2017-09-10 +Project @Context key:value L28
x 345678901234567890123456789012345678901234567890123456789012345678901234567890 L29
x . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 L30
x . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 L01
x 345678901234567890123456789012345678901234567890123456789012345678901234567890 L02
X Done tasks must start with a lowercase x then space L03
xDone tasks must start with a lowercase x then space L04
XDone tasks must start with a lowercase x then space L05
(a) Priority must start with an uppercase letter in rounds followed by space L06
(A)Priority must start with an uppercase letter in rounds followed by space L07
A Priority must start with an uppercase letter in rounds followed by space L08
a Priority must start with an uppercase letter in rounds followed by space L09
Priority (A) must start with an uppercase letter in rounds followed by space L10
due:2050-01-01 keys are valid on the start of the line L11
due:2010-01-01 overdue dates are valid on the start of the line L12
2010-01-01 dates are valid on the start of the line L13
x . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 L14
x 345678901234567890123456789012345678901234567890123456789012345678901234567890 L15
Invalid dates 17-10-05 20100101 01-01-2010 2010/01/01 10/01/01 2010-01-01-2010 L16
@Contexts are valid on the start of the line L17
+Projects are valid on the start of the line L18
The key: syntax must be followed by a value, same for due: L19
due: syntax must be a whole word notdue:2010-01-01 pro@jects and con+texts also L20
x 345678901234567890123456789012345678901234567890123456789012345678901234567890 L21
x . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 L22
x 2017-09-18 Complete task
x 2017-09-18 2017-09-01 Completed task with a created date
x 2017-09-18 (A) Completed priority task
x 2017-09-18 2017-09-01 (A) Completed priority task with a created date
X 2017-09-18 Not to be confused for a complete task
Active task
2017-09-01 Active task with a created date
(A) Active priority task
(A) 2017-09-01 Active priority task with a created date
X 2017-09-18 Not to be confused for a complete task
XNot to be confused for a complete task
x 2017-09-18 Rules are not clear on leading whitespace, see comments in test
Tricky incomplete task x 2017-09-18
active dUE:2051-01-01 cAsE EXP:24 GIV:01
overdue due:2001-01-01 EXP:02 GIV:02
notdue overdue:2011-11-11 invalid key EXP:33 GIV:03
overdue duE:2009-01-01 cAsE EXP:18 GIV:04
xoverdue due:2001-02-01 This is not done (must be lower x) EXP:03 GIV:05
overdue due:2012-01-01 \|| no tasks the between bars ||/ EXP:21 GIV:06
x done due:2011-11-11 topmost done task EXP:44 GIV:07
notdue due: 2011-11-11 space invalidates due: EXP:34 GIV:08
overdue due:2005-01-01 +Project @Context EXP:10 GIV:09
overdue due:2002-01-01 @Context EXP:04 GIV:10
overdue due:2004-02-01 EXP:09 GIV:11
notdue due: due:2011-MM-DD EXP:35 GIV:12
overdue due:2000-01-01 cursor here for top, most overdue EXP:01 GIV:13
notdue due:2011-11-1 EXP:36 GIV:14
active due:2059-01-01 bottommost active task EXP:32 GIV:15
overdue due:2006-01-01 EXP:12 GIV:16
overdue due:2007-02-01 +Project EXP:15 GIV:17
active due:2056-01-01 EXP:29 GIV:18
notdue due:2011-1-11 EXP:37 GIV:19
x done due:2011-11-11 EXP:45 GIV:20
overdue dUe:2008-02-01 cAsE EXP:17 GIV:21
X overdue due:2002-02-01 This is not done (must be lower x) EXP:05 GIV:22
+Project overdue due:2003-02-01 project at start of line EXP:07 GIV:23
notdue due:2011 EXP:38 GIV:24
active DUe:2052-01-01 cAsE EXP:25 GIV:25
overdue due:2007-01-01 EXP:14 GIV:26
overdue Due:2008-01-01 cAsE EXP:16 GIV:27
notdue @Project EXP:39 GIV:28
active due:2055-01-01 EXP:28 GIV:29
active due:2057-01-01 EXP:30 GIV:30
overdue DuE:2009-02-01 cAsE EXP:19 GIV:31
notdue @Context EXP:40 GIV:32
x done due:2011-11-11 bottommost done task cursor here bottom EXP:46 GIV:33
active DUE:2053-01-01 cAsE EXP:26 GIV:34
active key:value due:2054-01-01 leading key:value EXP:27 GIV:35
active due:2058-01-01 EXP:31 GIV:36
notdue key:value EXP:41 GIV:37
overdue due:2017-01-01 Last overdue task when sorted EXP:22 GIV:38
overdue due:2010-12-31 /|| no tasks the between bars ||\ EXP:20 GIV:39
active due:2050-01-01 cursor here with "notoverdue" setting EXP:23 GIV:40
notdue due:invalid invalid due date EXP:42 GIV:41
overdue 2011-11-11 due:2005-02-01 leading date EXP:11 GIV:42
due:2004-01-01 overdue due: at start of line EXP:08 GIV:43
notdue notdue:2011-11-11 invalid key EXP:43 GIV:44
overdue due:2006-02-01 due:2011-11-11 two dates, choose first EXP:13 GIV:45
@Context overdue due:2003-01-01 context at start of line EXP:06 GIV:46

View File

@@ -3,7 +3,6 @@
" Author: Peter (fretep) <githib.5678@9ox.net>
" Licence: Vim licence
" Website: http://github.com/dbeniamine/todo.txt.vim
" vim: ts=2 sw=2 sts=2 expandtab :help tw=78 cc=80 foldmethod=marker
" [Vader](https://github.com/junegunn/vader.vim) is a simple unit testing
" plugin for VIM.
@@ -416,8 +415,74 @@ Execute (16-12-31 should NOT match with reference 17-12-31):
Execute (2016-12-31 should NOT match with reference 17-12-31):
Assert '2016-12-31' !~ b:rex
" Make sure current date doesn't match
Before:
let b:rex = todo#GetDateRegexForPastDates(strftime("%Y"), strftime("%m"), strftime("%d"))
Execute (Log generated RegExp):
Log b:rex
Execute (Current date should not match):
Assert strftime("%Y-%m-%d") !~ b:rex
" Incorrectly matching current date, some breakpoints that previously were found to be an issue
Before:
let b:rex = todo#GetDateRegexForPastDates(2017,09,20)
Execute (Log generated RegExp):
Log b:rex
Execute (2017-09-19 should match with reference 2017-09-20):
Assert '2017-09-19' =~ b:rex
Execute (2017-09-20 should NOT match with reference 2017-09-20):
Assert '2017-09-20' !~ b:rex
Before:
let b:rex = todo#GetDateRegexForPastDates(2017,09,30)
Execute (Log generated RegExp):
Log b:rex
Execute (2017-09-29 should match with reference 2017-09-30):
Assert '2017-09-29' =~ b:rex
Execute (2017-09-30 should NOT match with reference 2017-09-30):
Assert '2017-09-30' !~ b:rex
" file: autoload/todo.vim {{{1
" function! todo#ToggleMarkAsDone(status) {{{2
" NOTES:
" - Rules on leading whitespace is not clear, and really could be taken
" either way. Current behaviour is to treat leading whitespace as valid.
" TODO: Ensure behavior of leading whitespace is consistent for everything
" including priorities (which are currently not).
" - FIXME: Incorrect handling of priorities is expected below, see #21.
Given todo (Tasks):
x 2017-09-18 Complete task
x 2017-09-18 2017-09-01 Completed task with a created date
x 2017-09-18 (A) Completed priority task
x 2017-09-18 2017-09-01 (A) Completed priority task with a created date
X 2017-09-18 Not to be confused for a complete task
Active task
2017-09-01 Active task with a created date
(A) Active priority task
(A) 2017-09-01 Active priority task with a created date
X 2017-09-18 Not to be confused for a complete task
XNot to be confused for a complete task
x 2017-09-18 Rules are not clear on leading whitespace, see comments in test
Tricky incomplete task x 2017-09-18
Execute (Toggle completed):
global/./call todo#ToggleMarkAsDone('')
execute "%substitute/" . strftime("%Y-%m-%d") . "/**TODAY**/"
Expect todo (Toggled tasks with today as **TODAY**):
Complete task
2017-09-01 Completed task with a created date
(A) Completed priority task
2017-09-01 (A) Completed priority task with a created date
x **TODAY** X 2017-09-18 Not to be confused for a complete task
x **TODAY** Active task
x **TODAY** 2017-09-01 Active task with a created date
x (A) **TODAY** Active priority task
x (A) **TODAY** 2017-09-01 Active priority task with a created date
x **TODAY** X 2017-09-18 Not to be confused for a complete task
x **TODAY** XNot to be confused for a complete task
Rules are not clear on leading whitespace, see comments in test
x **TODAY** Tricky incomplete task x 2017-09-18
" function: todo#SortDue() {{{2
Before:
@@ -678,3 +743,4 @@ Then (Is cursor on first non-overdue task?):
After:
unlet g:TodoTxtSortDueDateCursorPos
" vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab foldmethod=marker