tp-note 1.19.6

Minimalistic note taking: save and edit your clipboard content as a note file
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
#!/bin/sh

TESTOUTPUT="test_output"
PWD="$(pwd)/$TESTOUTPUT"
unset TPNOTELANG

# Tidy up
rm -r "$PWD"
mkdir -p "$PWD"

# Prepare toml
# Generate new config file.
cargo run -- -V -b -c "$PWD/tpnote.toml"
# Remove all `date` lines of all templates.
TP_NOTE_TEST_TOML="$PWD/tpnote-tmp.toml"
grep -v -e ^date:  "$PWD/tpnote.toml" > "$TP_NOTE_TEST_TOML"


## Test 1: Synchronize meta data and filename
INPUT_FILENAME="$PWD/123-abc--edf.md"
cat - > "$INPUT_FILENAME" <<'EOF'
---
title: "xxx"
subtitle: "yyy"
...
EOF

LANG="en_US.UTF-8" LOGNAME="myuser" \
cargo run -- --batch --config "$TP_NOTE_TEST_TOML" \
    "$INPUT_FILENAME"  >/dev/null 2>&1

OUTPUT_FILENAME="$PWD/123-xxx--yyy.md"

if diff "$OUTPUT_FILENAME"  "test1-synchronize-expected-output"
then
    echo Commandline test 1 succeeded.
    rm "$OUTPUT_FILENAME"
else
    echo Commandline test 1 failed.
    exit 1
fi



## Test 2: Create a new note

LANG="en_US.UTF-8" LOGNAME="myuser" \
cargo run -- --batch \
    --config "$TP_NOTE_TEST_TOML" "$PWD" >/dev/null 2>&1

OUTPUT_FILENAME="$PWD/$(date +%Y%m%d)-$TESTOUTPUT--Note.md"

if diff "$OUTPUT_FILENAME" "test2-new-expected-output"
then
    echo Commandline test 2 succeeded.
    rm "$OUTPUT_FILENAME"
else
    echo Commandline test 2 failed.
    exit 1
fi



## Test 3: Create a new note annotating some existing file

INPUT_FILENAME="$PWD/test3-annotate+clipboard-input-dummy.pdf"

# Input file can be empty
:>"$INPUT_FILENAME"

echo '[ab:cd"ef](https://getreu.net)' | \
LANG="en_US.UTF-8" LOGNAME="myuser" \
	cargo run -- --batch \
	    --config "$TP_NOTE_TEST_TOML" \
	    "$INPUT_FILENAME" >/dev/null 2>&1

# the + is not considered to be a secure char, therefor ommitted
OUTPUT_FILENAME="$PWD/test3-annotate+clipboard-input-dummy.pdf--URL.md"

if diff "$OUTPUT_FILENAME" "test3-annotate+clipboard-expected-output"
then
echo Commandline test 3 succeeded.
    rm "$INPUT_FILENAME"
    rm "$OUTPUT_FILENAME"
else
    echo Commandline test 3 failed.
    exit 1
fi




## Test 4: Create a new note, based on a markdown link supplied by clipboard

# Tp-Note ignores the clipboard in batch mode, we pass it as
# environment variable instead.

echo '[ab:cd"ef](https://getreu.net)' | \
LANG="en_US.UTF-8" LOGNAME="myuser" \
	cargo run -- --batch \
    		--config  "$TP_NOTE_TEST_TOML" "$PWD" >/dev/null 2>&1

OUTPUT_FILENAME="$PWD/$(date +%Y%m%d)-ab_cd ef--URL.md"

if diff "$OUTPUT_FILENAME" "test4-clipboard-expected-output"
then
    echo Commandline test 4 succeeded.
    rm "$OUTPUT_FILENAME"
else
    echo Commandline test 4 failed.
    exit 1
fi



## Test 5: Create a new note, based on a string supplied by clipboard

#echo -n 'Good morning' | xclip -selection clipboard

echo 'Good morning' | \
LANG="en_US.UTF-8" LOGNAME="myuser" \
	cargo run -- --batch \
    		--config  "$TP_NOTE_TEST_TOML" "$PWD" >/dev/null 2>&1

OUTPUT_FILENAME="$PWD/$(date +%Y%m%d)-Good morning--Note.md"

if diff "$OUTPUT_FILENAME" "test5-clipboard-expected-output"
then
    echo Commandline test 5 succeeded.
    rm "$OUTPUT_FILENAME"
else
    echo Commandline test 5 failed.
    exit 1
fi




## Test 6: Create a new note annotating some existing file
INPUT_FILENAME="$PWD/test6-annotate-input-dummy.pdf"

# Input file can be empty
:>"$INPUT_FILENAME"

LANG="en_US.UTF-8" LOGNAME="myuser" \
    cargo run -- --batch \
    --config "$TP_NOTE_TEST_TOML" \
    "$INPUT_FILENAME" >/dev/null 2>&1

OUTPUT_FILENAME="$PWD/test6-annotate-input-dummy.pdf--Note.md"

if diff "$OUTPUT_FILENAME" "test6-annotate-expected-output"
then
echo Commandline test 6 succeeded.
    rm "$INPUT_FILENAME"
    rm "$OUTPUT_FILENAME"
else
    echo Commandline test 6 failed.
    exit 1
fi



## Test 7: Pin sort tag
INPUT_FILENAME="$PWD/123-abc--edf.md"
cat - > "$INPUT_FILENAME" <<'EOF'
---
title: "xxx"
subtitle: "yyy"
sort_tag: "111-"
file_ext: "md"
...
EOF

LANG="en_US.UTF-8" LOGNAME="myuser" \
cargo run -- --batch --config "$TP_NOTE_TEST_TOML" \
    "$INPUT_FILENAME"  >/dev/null 2>&1

OUTPUT_FILENAME="$PWD/111-xxx--yyy.md"

if diff "$OUTPUT_FILENAME"  "test7-tag-expected-output"
then
    echo Commandline test 7 succeeded.
    rm "$OUTPUT_FILENAME"
else
    echo Commandline test 7 failed.
    exit 1
fi



## Test 8: stream note content with front matter

INPUT_DATA="---
title: 'aaa'
subtitle: 'bbb'
date: '2020-01-02'
lang: 'en'
revision: '2.0'
sort_tag: '222-'
file_ext: 'mdtxt'
my_own_var: 'foo'
...
EOF
"

echo "$INPUT_DATA" | \
LANG="en_US.UTF-8" LOGNAME="myuser" \
cargo run -- --batch --config "$TP_NOTE_TEST_TOML" \
    "$PWD"  >/dev/null 2>&1

OUTPUT_FILENAME="$PWD/222-aaa--bbb.mdtxt"

if diff "$OUTPUT_FILENAME"  "test8-stream-content-expected-output"
then
    echo Commandline test 8 succeeded.
    rm "$OUTPUT_FILENAME"
else
    echo Commandline test 8 failed.
    exit 1
fi



## Test 9: Create 2 notes with same header

LANG="en_US.UTF-8" LOGNAME="myuser" \
cargo run -- --batch \
    --config "$TP_NOTE_TEST_TOML" "$PWD" >/dev/null 2>&1

LANG="en_US.UTF-8" LOGNAME="myuser" \
cargo run -- --batch \
    --config "$TP_NOTE_TEST_TOML" "$PWD" >/dev/null 2>&1

OUTPUT_FILENAME="$PWD/$(date +%Y%m%d)-$TESTOUTPUT--Note.md"
OUTPUT_FILENAME2="$PWD/$(date +%Y%m%d)-$TESTOUTPUT--Note(1).md"
if diff "$OUTPUT_FILENAME2" "test9-new-new-expected-output"
then
    echo Commandline test 9 succeeded.
    rm "$OUTPUT_FILENAME"
    rm "$OUTPUT_FILENAME2"
else
    echo Commandline test 9 failed.
    exit 1
fi




## Test 10: Export note
INPUT_FILENAME="$PWD/123-abc--edf.md"
cat - > "$INPUT_FILENAME" <<'EOF'
---
title: "xxx"
subtitle: "yyy"
sort_tag: "111-"
file_ext: "md"
...
EOF

LANG="en_US.UTF-8" LOGNAME="myuser" \
cargo run -- --batch --config "$TP_NOTE_TEST_TOML" \
    "$INPUT_FILENAME"  >/dev/null 2>&1

INPUT2_FILENAME="$PWD/111-xxx--yyy.md"

LANG="en_US.UTF-8" LOGNAME="myuser" \
cargo run -- --batch --config "$TP_NOTE_TEST_TOML" \
     --export "" \
    "$INPUT2_FILENAME"  >/dev/null 2>&1

OUTPUT_FILENAME="$PWD/111-xxx--yyy.md.html"

if diff "$OUTPUT_FILENAME"  "test10-html-expected-output"
then
    echo Commandline test 10 succeeded.
    rm "$INPUT2_FILENAME"
    rm "$OUTPUT_FILENAME"
else
    echo Commandline test 10 failed.
    exit 1
fi



## Test 11: Do not synchronize meta data and filename
INPUT_FILENAME="$PWD/123-abc--edf.md"
cat - > "$INPUT_FILENAME" <<'EOF'
---
title: "xxx"
subtitle: "yyy"
...
EOF

LANG="en_US.UTF-8" LOGNAME="myuser" \
	cargo run -- --batch --no-sync --config "$TP_NOTE_TEST_TOML" \
    "$INPUT_FILENAME"  >/dev/null 2>&1

OUTPUT_FILENAME="$PWD/123-abc--edf.md"

if diff "$OUTPUT_FILENAME"  "test1-synchronize-expected-output"
then
    echo Commandline test 11 succeeded.
    rm "$OUTPUT_FILENAME"
else
    echo Commandline test 11 failed.
    exit 1
fi



## Test 12: Add header
INPUT_FILENAME="$PWD/20220312-abc-- edf.md"
cat - > "$INPUT_FILENAME" <<'EOF'
Only body
EOF

LANG="en_US.UTF-8" LOGNAME="myuser" \
	cargo run -- --batch --add-header --config "$TP_NOTE_TEST_TOML" \
    "$INPUT_FILENAME"  >/dev/null 2>&1

OUTPUT_FILENAME="$PWD/20220312-abc--edf.md"

if diff "$OUTPUT_FILENAME"  "test12-add-header-expected-output"
then
    echo Commandline test 12 succeeded.
    rm "$OUTPUT_FILENAME"
else
    echo Commandline test 12 failed.
    exit 1
fi


## Test 13: Copy counter and sync
INPUT_FILENAME="$PWD/20220312-abc--edf(4).md"
cat - > "$INPUT_FILENAME" <<'EOF'
---
title: abc
subtitle: edf
---
Body
EOF


OUTPUT_FILENAME=$(LANG="en_US.UTF-8" LOGNAME="myuser" \
	cargo run -- --batch --add-header --config "$TP_NOTE_TEST_TOML" \
    "$INPUT_FILENAME"| tail -n 1)  >/dev/null 2>&1
        
if [ "$INPUT_FILENAME" = "$OUTPUT_FILENAME" ]
then
    echo Commandline test 13 succeeded.
    rm "$OUTPUT_FILENAME"
else
    echo Commandline test 13 failed.
    exit 1
fi



## Test 14:  Compilation --no-default-features

cargo check --no-default-features >/dev/null

if [ $? -eq 0 ]
then
    echo Commandline test 14 succeeded.
else
    echo Commandline test 14 failed.
    exit 1
fi



## Test 15:  Compilation --no-default-features --features renderer
cargo check --no-default-features --features message-box >/dev/null

if [ $? -eq 0 ]
then
    echo Commandline test 15 succeeded.
else
    echo Commandline test 15 failed.
    exit 1
fi



## Test 16:  Compilation --no-default-features --features viewer
cargo check --no-default-features --features viewer >/dev/null

if [ $? -eq 0 ]
then
    echo Commandline test 16 succeeded.
else
    echo Commandline test 16 failed.
    exit 1
fi



## Test 17:  Compilation --no-default-features --features message-box
cargo check --no-default-features --features message-box >/dev/null

if [ $? -eq 0 ]
then
    echo Commandline test 17 succeeded.
else
    echo Commandline test 17 failed.
    exit 1
fi



## Test 18:  Compilation --no-default-features --features read-clipboard
cargo check --no-default-features --features read-clipboard >/dev/null

if [ $? -eq 0 ]
then
    echo Commandline test 18 succeeded.
else
    echo Commandline test 18 failed.
    exit 1
fi





exit 0