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:
Paul Mansfield
2009-09-02 23:30:14 +01:00
parent 7baf051942
commit 229737bd2f
2 changed files with 118 additions and 1 deletions

105
tests/t2000-multiline.sh Executable file
View 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
View File

@@ -240,6 +240,13 @@ cleanup()
exit 0
}
cleaninput()
{
# Cleanup the input
# Replace newlines with spaces
input=`echo $input | tr -d '\n'`
}
archive()
{
#defragment blank lines
@@ -579,6 +586,7 @@ case $action in
shift
input=$*
fi
cleaninput $input
if [[ $TODOTXT_DATE_ON_ADD = 1 ]]; then
now=`date '+%Y-%m-%d'`
@@ -620,6 +628,8 @@ case $action in
else
input=$*
fi
cleaninput $input
if sed -i.bak $item" s|^.*|& $input|" "$TODO_FILE"; then
newtodo=$(sed "$item!d" "$TODO_FILE")
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
@@ -847,6 +857,7 @@ case $action in
else
input=$*
fi
cleaninput $input
# Test for then set priority
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
input=$*
fi
cleaninput $input
# If priority isn't set replace, if it is remove priority, replace then add priority again
if [ -z $priority ]; then