File: t2000-multiline.sh

package info (click to toggle)
todotxt-cli 2.11.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, trixie
  • size: 1,312 kB
  • sloc: sh: 5,393; makefile: 67
file content (136 lines) | stat: -rwxr-xr-x 2,684 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash

test_description='Multi-line functionality'

. ./test-lib.sh

## Replace test
# Create the expected file
echo "1 smell the cheese
TODO: Replaced task with:
1 eat apples eat oranges drink milk">"$HOME/expect.multi"

test_expect_success 'multiline squash 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
drink milk" > "$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 "2 eat apples eat oranges drink milk
TODO: 2 added.">"$HOME/expect.multi"

test_expect_success 'multiline squash 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
drink milk" > "$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 drink milk">"$HOME/expect.multi"

test_expect_success 'multiline squash 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
drink milk" > "$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 drink milk smell the cheese">"$HOME/expect.multi"

test_expect_success 'multiline squash 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
drink milk" > "$HOME/output.multi"

# Test output against expected
diff "$HOME/output.multi" "$HOME/expect.multi"
if [ $? -ne 0 ]; then
  exit 1
else
  exit 0
fi
)
'

## Multiple line addition
# Create the expected file
echo "2 eat apples
TODO: 2 added." > "$HOME/expect.multi"
echo "3 eat oranges
TODO: 3 added." >>"$HOME/expect.multi"
echo "4 drink milk
TODO: 4 added." >>"$HOME/expect.multi"

test_expect_success 'actual multiline add' '
(
# Run addm
"$HOME/bin/todo.sh" addm "eat apples
eat oranges
drink milk" > "$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