Bug Fix: Issue 1
Added a cleanitem function, this replaces newlines with a space. Currently this is used in the add, append, prepend and replace actions.
This commit is contained in:
105
tests/t2000-multiline.sh
Executable file
105
tests/t2000-multiline.sh
Executable file
@@ -0,0 +1,105 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='Multi-line functionality'
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
## Replace test
|
||||||
|
# Create the expected file
|
||||||
|
echo "1: smell the cheese
|
||||||
|
replaced with
|
||||||
|
1: eat apples eat oranges">$HOME/expect.multi
|
||||||
|
|
||||||
|
test_expect_success 'multiline item replace' '
|
||||||
|
(
|
||||||
|
# Prepare single line todo file
|
||||||
|
cat /dev/null > $HOME/todo.txt
|
||||||
|
"$HOME/bin/todo.sh" add smell the cheese
|
||||||
|
|
||||||
|
# Run replace
|
||||||
|
"$HOME/bin/todo.sh" replace 1 "eat apples
|
||||||
|
eat oranges" > $HOME/output.multi
|
||||||
|
|
||||||
|
# Test output against expected
|
||||||
|
diff "$HOME/output.multi" "$HOME/expect.multi"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
## Add test
|
||||||
|
# Create the expected file
|
||||||
|
echo "TODO: 'eat apples eat oranges' added on line 2.">$HOME/expect.multi
|
||||||
|
|
||||||
|
test_expect_success 'multiline item add' '
|
||||||
|
(
|
||||||
|
# Prepare single line todo file
|
||||||
|
cat /dev/null > $HOME/todo.txt
|
||||||
|
"$HOME/bin/todo.sh" add smell the cheese
|
||||||
|
|
||||||
|
# Run add
|
||||||
|
"$HOME/bin/todo.sh" add "eat apples
|
||||||
|
eat oranges" > $HOME/output.multi
|
||||||
|
|
||||||
|
# Test output against expected
|
||||||
|
diff "$HOME/output.multi" "$HOME/expect.multi"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
## Append test
|
||||||
|
# Create the expected file
|
||||||
|
echo "1: smell the cheese eat apples eat oranges">$HOME/expect.multi
|
||||||
|
|
||||||
|
test_expect_success 'multiline item append' '
|
||||||
|
(
|
||||||
|
# Prepare single line todo file
|
||||||
|
cat /dev/null > $HOME/todo.txt
|
||||||
|
"$HOME/bin/todo.sh" add smell the cheese
|
||||||
|
|
||||||
|
# Run append
|
||||||
|
"$HOME/bin/todo.sh" append 1 "eat apples
|
||||||
|
eat oranges" > $HOME/output.multi
|
||||||
|
|
||||||
|
# Test output against expected
|
||||||
|
diff "$HOME/output.multi" "$HOME/expect.multi"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
## Prepend test
|
||||||
|
# Create the expected file
|
||||||
|
echo "1: eat apples eat oranges smell the cheese">$HOME/expect.multi
|
||||||
|
|
||||||
|
test_expect_success 'multiline item prepend' '
|
||||||
|
(
|
||||||
|
# Prepare single line todo file
|
||||||
|
cat /dev/null > $HOME/todo.txt
|
||||||
|
"$HOME/bin/todo.sh" add smell the cheese
|
||||||
|
|
||||||
|
# Run prepend
|
||||||
|
"$HOME/bin/todo.sh" prepend 1 "eat apples
|
||||||
|
eat oranges" > $HOME/output.multi
|
||||||
|
|
||||||
|
# Test output against expected
|
||||||
|
diff "$HOME/output.multi" "$HOME/expect.multi"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_done
|
||||||
12
todo.sh
12
todo.sh
@@ -240,6 +240,13 @@ cleanup()
|
|||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleaninput()
|
||||||
|
{
|
||||||
|
# Cleanup the input
|
||||||
|
# Replace newlines with spaces
|
||||||
|
input=`echo $input | tr -d '\n'`
|
||||||
|
}
|
||||||
|
|
||||||
archive()
|
archive()
|
||||||
{
|
{
|
||||||
#defragment blank lines
|
#defragment blank lines
|
||||||
@@ -579,6 +586,7 @@ case $action in
|
|||||||
shift
|
shift
|
||||||
input=$*
|
input=$*
|
||||||
fi
|
fi
|
||||||
|
cleaninput $input
|
||||||
|
|
||||||
if [[ $TODOTXT_DATE_ON_ADD = 1 ]]; then
|
if [[ $TODOTXT_DATE_ON_ADD = 1 ]]; then
|
||||||
now=`date '+%Y-%m-%d'`
|
now=`date '+%Y-%m-%d'`
|
||||||
@@ -620,6 +628,8 @@ case $action in
|
|||||||
else
|
else
|
||||||
input=$*
|
input=$*
|
||||||
fi
|
fi
|
||||||
|
cleaninput $input
|
||||||
|
|
||||||
if sed -i.bak $item" s|^.*|& $input|" "$TODO_FILE"; then
|
if sed -i.bak $item" s|^.*|& $input|" "$TODO_FILE"; then
|
||||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||||
@@ -847,6 +857,7 @@ case $action in
|
|||||||
else
|
else
|
||||||
input=$*
|
input=$*
|
||||||
fi
|
fi
|
||||||
|
cleaninput $input
|
||||||
|
|
||||||
# Test for then set priority
|
# Test for then set priority
|
||||||
if [ `sed "$item!d" "$TODO_FILE"|grep -c "^(\\w)"` -eq 1 ]; then
|
if [ `sed "$item!d" "$TODO_FILE"|grep -c "^(\\w)"` -eq 1 ]; then
|
||||||
@@ -917,6 +928,7 @@ note: PRIORITY must be anywhere from A to Z."
|
|||||||
else
|
else
|
||||||
input=$*
|
input=$*
|
||||||
fi
|
fi
|
||||||
|
cleaninput $input
|
||||||
|
|
||||||
# If priority isn't set replace, if it is remove priority, replace then add priority again
|
# If priority isn't set replace, if it is remove priority, replace then add priority again
|
||||||
if [ -z $priority ]; then
|
if [ -z $priority ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user