From e9deb6fff3d56b166ab702828bd1a716c2bf567f Mon Sep 17 00:00:00 2001
From: Lars Henriksen <LarsHenriksen@get2net.dk>
Date: Tue, 7 Apr 2020 21:29:26 +0200
Subject: Extend use of note file for iCal import

iCal import to an item note file is extended from DESCRIPTION to
LOCATION, COMMENT and STATUS for both events and todos.

Addresses GitHub issue #9.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
---
 test/Makefile.am        |  2 ++
 test/data/ical-009.ical | 13 +++++++
 test/data/ical-012.ical | 93 +++++++++++++++++++++++++++++++++++++++++++++++++
 test/ical-009.sh        | 24 +++++++------
 test/ical-012.sh        | 76 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 198 insertions(+), 10 deletions(-)
 create mode 100644 test/data/ical-012.ical
 create mode 100755 test/ical-012.sh

(limited to 'test')

diff --git a/test/Makefile.am b/test/Makefile.am
index 6b04d86..8a62a0c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -59,6 +59,7 @@ TESTS = \
 	ical-009.sh \
 	ical-010.sh \
 	ical-011.sh \
+	ical-012.sh \
 	next-001.sh \
 	next-002.sh \
 	next-003.sh \
@@ -134,5 +135,6 @@ EXTRA_DIST = \
 	data/ical-007.ical \
 	data/ical-008.ical \
 	data/ical-009.ical \
+	data/ical-012.ical \
 	data/todo \
 	data/todo-export
diff --git a/test/data/ical-009.ical b/test/data/ical-009.ical
index 73e9037..39ae422 100644
--- a/test/data/ical-009.ical
+++ b/test/data/ical-009.ical
@@ -63,6 +63,19 @@ BEGIN:VTODO
 PRIORITY:1
 SUMMARY:an unescaped comma: ,
 END:VTODO
+BEGIN:VEVENT
+DTSTART:20200406T221300
+DURATION:PT0H15M0S
+SUMMARY:Invalid STATUS
+STATUS:confirmed
+END:VEVENT
+BEGIN:VEVENT
+DTSTART:20200406T221300
+DURATION:PT0H15M0S
+SUMMARY:LOCATION twice
+LOCATION:first
+LOCATION:second
+END:VEVENT
 BEGIN:VTODO
 SUMMARY:finally\, missing end of item
 END:VCALENDAR
diff --git a/test/data/ical-012.ical b/test/data/ical-012.ical
new file mode 100644
index 0000000..09385fb
--- /dev/null
+++ b/test/data/ical-012.ical
@@ -0,0 +1,93 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+
+BEGIN:VEVENT
+DTSTART:20200404T204500
+DURATION:PT1H30M0S
+SUMMARY:event with one-line description
+DESCRIPTION:event with one-line description
+END:VEVENT
+
+BEGIN:VEVENT
+DTSTART:20200404T204500
+DURATION:PT1H30M0S
+SUMMARY:description and location
+DESCRIPTION:event with description\nand location
+LOCATION: Right here
+END:VEVENT
+
+BEGIN:VEVENT
+DTSTART:20200404T084100
+DURATION:PT1H30M0S
+SUMMARY:No description. Comment and status
+COMMENT:Event without description: a comment\nstreching over\nthree lines
+STATUS:CONFIRMED
+END:VEVENT
+
+BEGIN:VEVENT
+DTSTART:20200404T084100
+DURATION:PT1H30M0S
+SUMMARY:Empty description
+DESCRIPTION:
+END:VEVENT
+
+BEGIN:VEVENT
+DTSTART:20200404T084100
+DURATION:PT1H30M0S
+SUMMARY:Empty description\, but comment
+DESCRIPTION:
+COMMENT:event with empty description
+END:VEVENT
+
+BEGIN:VEVENT
+DTSTART:20200404T204500
+DURATION:PT1H30M0S
+SUMMARY:description\, status\, comment and location
+DESCRIPTION:event with\ndescription\nstatus\ncomment\nand location
+LOCATION: Right here
+COMMENT:just a repetition of description:\nevent with\ndescription\nstatus\ncomment\nand location
+STATUS:CANCELLED
+END:VEVENT
+
+BEGIN:VTODO
+PRIORITY:2
+SUMMARY:todo with one-line description
+DESCRIPTION:todo with one-line description
+END:VTODO
+
+BEGIN:VTODO
+PRIORITY:3
+SUMMARY:description and location
+DESCRIPTION:todo with description\nand location
+LOCATION: Right here
+END:VTODO
+
+BEGIN:VTODO
+PRIORITY:4
+SUMMARY:Comment and status
+COMMENT:Todo with out description. A comment\nstreching over\nthree lines
+STATUS:NEEDS-ACTION
+END:VTODO
+
+BEGIN:VTODO
+PRIORITY:5
+SUMMARY:Empty description
+DESCRIPTION:
+END:VTODO
+
+BEGIN:VTODO
+PRIORITY:6
+SUMMARY:Empty description\,but status
+DESCRIPTION:
+STATUS:COMPLETED
+END:VTODO
+
+BEGIN:VTODO
+SUMMARY:todo with description\, status\, comment and location
+DESCRIPTION:todo with\ndescription\nstatus\ncomment\nand location\,\nbut no priority
+LOCATION: Right here
+COMMENT:mostly a repetition of description:\ntodo with\ndescription\nstatus\ncomment\nand location
+STATUS:IN-PROCESS
+END:VTODO
+
+END:VCALENDAR
diff --git a/test/ical-009.sh b/test/ical-009.sh
index 31dc283..d912f5c 100755
--- a/test/ical-009.sh
+++ b/test/ical-009.sh
@@ -7,27 +7,31 @@ if [ "$1" = 'actual' ]; then
   mkdir .calcurse || exit 1
   cp "$DATA_DIR/conf" .calcurse || exit 1
   out=$("$CALCURSE" -D "$PWD/.calcurse" -i "$DATA_DIR/ical-009.ical" 2>&1)
-  echo "$out" | sed -n '4,5p'
-  log=$(echo "$out" | awk '$1 == "See" {print $2}')
-  cat "$log" | sed '1,17d'
-  cat $PWD/.calcurse/notes/* | wc
+  # Print the import report (stdout).
+  echo "$out" | awk '$1 == "Import"; $2 == "apps"'
+  # Find the log file and print the log messages (stderr).
+  logfile=$(echo "$out" | awk '$1 == "See" { print $2 }')
+  sed '1,18d' "$logfile"
+  # One empty note file.
+  cat "$PWD/.calcurse/notes"/* | wc | awk '{ print $1 $2 $3 }'
   rm -rf .calcurse || exit 1
 elif [ "$1" = 'expected' ]; then
   cat <<EOD
-Import process report: 0068 lines read
-2 apps / 0 events / 1 todo / 10 skipped
-
+Import process report: 0081 lines read
+2 apps / 0 events / 1 todo / 12 skipped
 VEVENT [12]: could not retrieve event start time.
 VEVENT [17]: recurrence frequency not recognized.
-VEVENT [23]: malformed summary line
+VEVENT [23]: malformed summary line.
 VTODO [28]: item priority is invalid (must be between 0 and 9).
 VEVENT [32]: malformed exceptions line.
 VEVENT [39]: line break in summary.
 VEVENT [44]: malformed description line.
 VEVENT [50]: malformed description.
 VTODO [62]: malformed summary.
-VTODO [66]: The ical file seems to be malformed. The end of item was not found.
-      1       0       1
+VEVENT [66]: invalid status value.
+VEVENT [72]: only one location allowed.
+VTODO [79]: The ical file seems to be malformed. The end of item was not found.
+101
 EOD
 else
   ./run-test "$0"
diff --git a/test/ical-012.sh b/test/ical-012.sh
new file mode 100755
index 0000000..9175db9
--- /dev/null
+++ b/test/ical-012.sh
@@ -0,0 +1,76 @@
+#!/bin/sh
+# Note file creation. Eleven note files are created for 6 apps and 6 todos.
+# To produce a fixed, predictable directory listing it is necessary that the
+# notes are of different sizes (except for the vevent and vtodo empty note which
+# is shared).
+
+. "${TEST_INIT:-./test-init.sh}"
+
+if [ "$1" = 'actual' ]; then
+  mkdir .calcurse &&
+  cp "$DATA_DIR/conf" .calcurse || exit 1
+  "$CALCURSE" -D "$PWD/.calcurse" -i "$DATA_DIR/ical-012.ical"
+  (cd  "$PWD/.calcurse/notes/"; cat $(ls -S1))
+  rm -rf .calcurse || exit 1
+elif [ "$1" = 'expected' ]; then
+  cat <<EOD
+Import process report: 0093 lines read
+6 apps / 0 events / 6 todos / 0 skipped
+todo with
+description
+status
+comment
+and location,
+but no priority
+-- 
+Location:  Right here
+Comment: mostly a repetition of description:
+    todo with
+    description
+    status
+    comment
+    and location
+Status: IN-PROCESS
+event with
+description
+status
+comment
+and location
+-- 
+Location:  Right here
+Comment: just a repetition of description:
+    event with
+    description
+    status
+    comment
+    and location
+Status: CANCELLED
+Comment: Todo with out description. A comment
+    streching over
+    three lines
+Status: NEEDS-ACTION
+Comment: Event without description: a comment
+    streching over
+    three lines
+Status: CONFIRMED
+event with description
+and location
+-- 
+Location:  Right here
+todo with description
+and location
+-- 
+Location:  Right here
+
+-- 
+Comment: event with empty description
+event with one-line description
+todo with one-line description
+
+-- 
+Status: COMPLETED
+
+EOD
+else
+  ./run-test "$0"
+fi
-- 
cgit v1.2.3-70-g09d2