Before adding any more features to todo_completion, I feel like I need test coverage, so this is a first stab at testing the completion results, via a new test function test_todo_completion. Some basic tests showcase the capabilities. Note: test-lib.sh now uses arrays, therefore all tests must use /bin/bash, not /bin/sh to avoid errors when sourcing test-lib. For consistency with todo.sh, we should have used Bash everywhere, anyway. Also note that t2000-multiline.sh needs some more quoting to avoid "Bash: ambiguous redirect" errors.
104 lines
1.5 KiB
Bash
Executable File
104 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
test_description='deduplicate functionality
|
||
|
||
Ensure we can deduplicate items successfully.
|
||
'
|
||
. ./test-lib.sh
|
||
|
||
cat > todo.txt <<EOF
|
||
duplicated
|
||
two
|
||
x done
|
||
duplicated
|
||
double task
|
||
double task
|
||
three
|
||
EOF
|
||
|
||
test_todo_session 'deduplicate and preserve line numbers' <<EOF
|
||
>>> todo.sh deduplicate
|
||
TODO: 2 duplicate task(s) removed
|
||
|
||
>>> todo.sh -p ls
|
||
5 double task
|
||
1 duplicated
|
||
7 three
|
||
2 two
|
||
3 x done
|
||
--
|
||
TODO: 5 of 5 tasks shown
|
||
EOF
|
||
|
||
test_todo_session 'deduplicate without duplicates' <<EOF
|
||
>>> todo.sh deduplicate
|
||
TODO: No duplicate tasks found
|
||
EOF
|
||
|
||
cat > todo.txt <<EOF
|
||
duplicated
|
||
two
|
||
x done
|
||
duplicated
|
||
double task
|
||
double task
|
||
three
|
||
EOF
|
||
test_todo_session 'deduplicate and delete lines' <<EOF
|
||
>>> todo.sh -n deduplicate
|
||
TODO: 2 duplicate task(s) removed
|
||
|
||
>>> todo.sh -p ls
|
||
4 double task
|
||
1 duplicated
|
||
5 three
|
||
2 two
|
||
3 x done
|
||
--
|
||
TODO: 5 of 5 tasks shown
|
||
EOF
|
||
|
||
cat > todo.txt <<EOF
|
||
one
|
||
duplicated
|
||
three
|
||
duplicated
|
||
duplicated
|
||
six
|
||
duplicated
|
||
EOF
|
||
test_todo_session 'deduplicate more than two occurrences' <<EOF
|
||
>>> todo.sh deduplicate
|
||
TODO: 3 duplicate task(s) removed
|
||
|
||
>>> todo.sh -p ls
|
||
2 duplicated
|
||
1 one
|
||
6 six
|
||
3 three
|
||
--
|
||
TODO: 4 of 4 tasks shown
|
||
EOF
|
||
|
||
cat > todo.txt <<EOF
|
||
normal task
|
||
a [1mbold[0m task
|
||
something else
|
||
a [1mbold[0m task
|
||
something more
|
||
EOF
|
||
test_todo_session 'deduplicate with non-printable duplicates' <<EOF
|
||
>>> todo.sh deduplicate
|
||
TODO: 1 duplicate task(s) removed
|
||
|
||
>>> todo.sh -p ls
|
||
2 a [1mbold[0m task
|
||
1 normal task
|
||
3 something else
|
||
5 something more
|
||
--
|
||
TODO: 4 of 4 tasks shown
|
||
EOF
|
||
|
||
test_done
|