* Handle missing EOL in todo.txt This can happen easily with certain editors (such as Mousepad) that do not automatically add a newline character at the end of a file. In _addto(), ensure a trailing newline via sed (taken from https://unix.stackexchange.com/a/31955/18876). Fixes #294 * Tests: Add basic coverage of move * Handle missing EOL in todo.txt for move, too This can happen easily with certain editors (such as Mousepad) that do not automatically add a newline character at the end of a file. * Refactoring: Extract fixMissingEndOfLine() * FIX: Compatibility: sed \+ multi not supported on MacOS Use the POSIX \{1,\} instead. Co-authored-by: Ali Karbassi <ali@karbassi.com>
127 lines
2.2 KiB
Bash
Executable File
127 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
test_description='basic add and list functionality
|
|
|
|
This test just makes sure the basic add and list
|
|
command work, including support for filtering.
|
|
'
|
|
. ./test-lib.sh
|
|
|
|
#
|
|
# Add and list
|
|
#
|
|
test_todo_session 'basic add/list' <<EOF
|
|
>>> todo.sh add notice the daisies
|
|
1 notice the daisies
|
|
TODO: 1 added.
|
|
|
|
>>> todo.sh list
|
|
1 notice the daisies
|
|
--
|
|
TODO: 1 of 1 tasks shown
|
|
|
|
>>> todo.sh add smell the roses
|
|
2 smell the roses
|
|
TODO: 2 added.
|
|
|
|
>>> todo.sh list
|
|
1 notice the daisies
|
|
2 smell the roses
|
|
--
|
|
TODO: 2 of 2 tasks shown
|
|
EOF
|
|
|
|
#
|
|
# Filter
|
|
#
|
|
test_todo_session 'basic list filtering' <<EOF
|
|
>>> todo.sh list daisies
|
|
1 notice the daisies
|
|
--
|
|
TODO: 1 of 2 tasks shown
|
|
|
|
>>> todo.sh list smell
|
|
2 smell the roses
|
|
--
|
|
TODO: 1 of 2 tasks shown
|
|
EOF
|
|
|
|
test_todo_session 'case-insensitive filtering' <<EOF
|
|
>>> todo.sh add smell the uppercase Roses
|
|
3 smell the uppercase Roses
|
|
TODO: 3 added.
|
|
|
|
>>> todo.sh list roses
|
|
2 smell the roses
|
|
3 smell the uppercase Roses
|
|
--
|
|
TODO: 2 of 3 tasks shown
|
|
EOF
|
|
|
|
test_todo_session 'add with symbols' <<EOF
|
|
>>> todo.sh add "~@#$%^&*()-_=+[{]}|;:',<.>/?"
|
|
4 ~@#$%^&*()-_=+[{]}|;:',<.>/?
|
|
TODO: 4 added.
|
|
|
|
>>> todo.sh add '\`!\\"'
|
|
5 \`!\\"
|
|
TODO: 5 added.
|
|
|
|
>>> todo.sh list
|
|
1 notice the daisies
|
|
2 smell the roses
|
|
3 smell the uppercase Roses
|
|
5 \`!\\"
|
|
4 ~@#$%^&*()-_=+[{]}|;:',<.>/?
|
|
--
|
|
TODO: 5 of 5 tasks shown
|
|
EOF
|
|
|
|
#
|
|
# Advanced add
|
|
#
|
|
|
|
cat /dev/null > todo.txt
|
|
test_todo_session 'add with spaces' <<EOF
|
|
>>> todo.sh add "notice the three spaces"
|
|
1 notice the three spaces
|
|
TODO: 1 added.
|
|
|
|
>>> todo.sh add notice how the spaces get lost
|
|
2 notice how the spaces get lost
|
|
TODO: 2 added.
|
|
|
|
>>> todo.sh list
|
|
2 notice how the spaces get lost
|
|
1 notice the three spaces
|
|
--
|
|
TODO: 2 of 2 tasks shown
|
|
EOF
|
|
|
|
cat /dev/null > todo.txt
|
|
test_todo_session 'add with CR' <<EOF
|
|
>>> todo.sh add "smell the
|
|
Carriage Return"
|
|
1 smell the Carriage Return
|
|
TODO: 1 added.
|
|
|
|
>>> todo.sh list
|
|
1 smell the Carriage Return
|
|
--
|
|
TODO: 1 of 1 tasks shown
|
|
EOF
|
|
|
|
echo -n 'this is a first task without newline' > todo.txt
|
|
test_todo_session 'add to file without EOL' <<EOF
|
|
>>> todo.sh add "a second task"
|
|
2 a second task
|
|
TODO: 2 added.
|
|
|
|
>>> todo.sh list
|
|
2 a second task
|
|
1 this is a first task without newline
|
|
--
|
|
TODO: 2 of 2 tasks shown
|
|
EOF
|
|
|
|
test_done
|