Merge branch 'the1ts/master'
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
@@ -242,6 +242,13 @@ cleanup()
|
||||
exit 0
|
||||
}
|
||||
|
||||
cleaninput()
|
||||
{
|
||||
# Cleanup the input
|
||||
# Replace newlines with spaces
|
||||
input=`echo $input | tr -d '\n'`
|
||||
}
|
||||
|
||||
archive()
|
||||
{
|
||||
#defragment blank lines
|
||||
@@ -587,6 +594,7 @@ case $action in
|
||||
shift
|
||||
input=$*
|
||||
fi
|
||||
cleaninput $input
|
||||
|
||||
if [[ $TODOTXT_DATE_ON_ADD = 1 ]]; then
|
||||
now=`date '+%Y-%m-%d'`
|
||||
@@ -628,6 +636,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"
|
||||
@@ -855,6 +865,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
|
||||
@@ -925,6 +936,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
|
||||
|
||||
Reference in New Issue
Block a user