From 6dbaa1c769c3a0464ec72e4224cbd76c0356a2bf Mon Sep 17 00:00:00 2001 From: Ulf Jasper Date: Tue, 29 May 2012 21:42:49 +0200 Subject: [PATCH] icalendar-tests: Fix Bug#11525 -- Add icalendar-import-format-uid 2012-05-29 Ulf Jasper * calendar/icalendar.el (icalendar-export-region): Export UID properly. 2012-05-29 Leo Liu * calendar/icalendar.el (icalendar-import-format): Add `icalendar-import-format-uid' (Bug#11525). (icalendar-import-format-uid): New. (icalendar--parse-summary-and-rest, icalendar--format-ical-event): Export UID. --- lisp/ChangeLog | 12 ++++ lisp/calendar/icalendar.el | 50 ++++++++++++---- test/ChangeLog | 12 ++++ test/automated/icalendar-tests.el | 98 ++++++++++++++++++++----------- 4 files changed, 127 insertions(+), 45 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 83d3f3e4677..b31cc2cef5f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,15 @@ +2012-05-29 Ulf Jasper + + * calendar/icalendar.el + (icalendar-export-region): Export UID properly. + +2012-05-29 Leo + * calendar/icalendar.el (icalendar-import-format): Add + `icalendar-import-format-uid' (Bug#11525). + (icalendar-import-format-uid): New. + (icalendar--parse-summary-and-rest, icalendar--format-ical-event): + Export UID. + 2012-05-29 Stefan Monnier * emacs-lisp/pcase.el (pcase--expand): Accept different sets of vars in diff --git a/lisp/calendar/icalendar.el b/lisp/calendar/icalendar.el index f1549ec20b1..5dc687d001b 100644 --- a/lisp/calendar/icalendar.el +++ b/lisp/calendar/icalendar.el @@ -130,6 +130,7 @@ In case of a formatting STRING the following specifiers can be used: %s Summary, see `icalendar-import-format-summary' %t Status, see `icalendar-import-format-status' %u URL, see `icalendar-import-format-url' +%U UID, see `icalendar-import-format-uid' A formatting FUNCTION will be called with a VEVENT as its only argument. It must return a string. See @@ -179,6 +180,14 @@ the URL." :type 'string :group 'icalendar) +(defcustom icalendar-import-format-uid + "\n UID: %s" + "Format string defining how the UID element is formatted. +This applies only if the UID is not empty! `%s' is replaced by +the UID." + :type 'string + :group 'icalendar) + (defcustom icalendar-import-format-status "\n Status: %s" "Format string defining how the status element is formatted. @@ -1017,7 +1026,8 @@ FExport diary data into iCalendar file: ") (org (cdr (assoc 'org other-elements))) (sta (cdr (assoc 'sta other-elements))) (sum (cdr (assoc 'sum other-elements))) - (url (cdr (assoc 'url other-elements)))) + (url (cdr (assoc 'url other-elements))) + (uid (cdr (assoc 'uid other-elements)))) (if cla (setq contents (concat contents "\nCLASS:" cla))) (if des @@ -1031,10 +1041,12 @@ FExport diary data into iCalendar file: ") ;;(if sum ;; (setq contents (concat contents "\nSUMMARY:" sum))) (if url - (setq contents (concat contents "\nURL:" url)))) + (setq contents (concat contents "\nURL:" url))) - (setq header (concat "\nBEGIN:VEVENT\nUID:" - (icalendar--create-uid entry-full contents))) + (setq header (concat "\nBEGIN:VEVENT\nUID:" + (or uid + (icalendar--create-uid entry-full + contents))))) (setq result (concat result header contents "\nEND:VEVENT"))) ;; handle errors (error @@ -1098,7 +1110,8 @@ Returns an alist." ;; can't do anything nil ;; split summary-and-rest - (let* ((s icalendar-import-format) + (let* ((case-fold-search nil) + (s icalendar-import-format) (p-cla (or (string-match "%c" icalendar-import-format) -1)) (p-des (or (string-match "%d" icalendar-import-format) -1)) (p-loc (or (string-match "%l" icalendar-import-format) -1)) @@ -1106,9 +1119,10 @@ Returns an alist." (p-sum (or (string-match "%s" icalendar-import-format) -1)) (p-sta (or (string-match "%t" icalendar-import-format) -1)) (p-url (or (string-match "%u" icalendar-import-format) -1)) - (p-list (sort (list p-cla p-des p-loc p-org p-sta p-sum p-url) '<)) + (p-uid (or (string-match "%U" icalendar-import-format) -1)) + (p-list (sort (list p-cla p-des p-loc p-org p-sta p-sum p-url p-uid) '<)) (ct 0) - pos-cla pos-des pos-loc pos-org pos-sta pos-sum pos-url) + pos-cla pos-des pos-loc pos-org pos-sta pos-sum pos-url pos-uid) (dotimes (i (length p-list)) ;; Use 'ct' to keep track of current position in list (cond ((and (>= p-cla 0) (= (nth i p-list) p-cla)) @@ -1131,7 +1145,10 @@ Returns an alist." (setq pos-sum (* 2 ct))) ((and (>= p-url 0) (= (nth i p-list) p-url)) (setq ct (+ ct 1)) - (setq pos-url (* 2 ct)))) ) + (setq pos-url (* 2 ct))) + ((and (>= p-uid 0) (= (nth i p-list) p-uid)) + (setq ct (+ ct 1)) + (setq pos-uid (* 2 ct)))) ) (mapc (lambda (ij) (setq s (icalendar--rris (car ij) (cadr ij) s t t))) (list @@ -1149,13 +1166,15 @@ Returns an alist." (list "%t" (concat "\\(" icalendar-import-format-status "\\)??")) (list "%u" - (concat "\\(" icalendar-import-format-url "\\)??")))) + (concat "\\(" icalendar-import-format-url "\\)??")) + (list "%U" + (concat "\\(" icalendar-import-format-uid "\\)??")))) ;; Need the \' regexp in order to detect multi-line items (setq s (concat "\\`" (icalendar--rris "%s" "\\(.*?\\)" s nil t) "\\'")) (if (string-match s summary-and-rest) - (let (cla des loc org sta sum url) + (let (cla des loc org sta sum url uid) (if (and pos-sum (match-beginning pos-sum)) (setq sum (substring summary-and-rest (match-beginning pos-sum) @@ -1184,13 +1203,18 @@ Returns an alist." (setq url (substring summary-and-rest (match-beginning pos-url) (match-end pos-url)))) + (if (and pos-uid (match-beginning pos-uid)) + (setq uid (substring summary-and-rest + (match-beginning pos-uid) + (match-end pos-uid)))) (list (if cla (cons 'cla cla) nil) (if des (cons 'des des) nil) (if loc (cons 'loc loc) nil) (if org (cons 'org org) nil) (if sta (cons 'sta sta) nil) ;;(if sum (cons 'sum sum) nil) - (if url (cons 'url url) nil)))))))) + (if url (cons 'url url) nil) + (if uid (cons 'uid uid) nil)))))))) ;; subroutines for icalendar-export-region (defun icalendar--convert-ordinary-to-ical (nonmarker entry-main) @@ -1864,6 +1888,7 @@ buffer `*icalendar-errors*'." (if (functionp icalendar-import-format) (funcall icalendar-import-format event) (let ((string icalendar-import-format) + (case-fold-search nil) (conversion-list '(("%c" CLASS icalendar-import-format-class) ("%d" DESCRIPTION icalendar-import-format-description) @@ -1871,7 +1896,8 @@ buffer `*icalendar-errors*'." ("%o" ORGANIZER icalendar-import-format-organizer) ("%s" SUMMARY icalendar-import-format-summary) ("%t" STATUS icalendar-import-format-status) - ("%u" URL icalendar-import-format-url)))) + ("%u" URL icalendar-import-format-url) + ("%U" UID icalendar-import-format-uid)))) ;; convert the specifiers in the format string (mapc (lambda (i) (let* ((spec (car i)) diff --git a/test/ChangeLog b/test/ChangeLog index ba6162ca241..f5fa81f4a5a 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,15 @@ +2012-05-29 Ulf Jasper + + * automated/icalendar-tests.el (icalendar-tests--test-import): + Include UID in import tests (Bug#11525). + (icalendar-import-non-recurring, icalendar-import-rrule) + (icalendar-import-duration, icalendar-import-bug-6766): Adjust to + UID-import change. + (icalendar-import-with-uid): New. + (icalendar-tests--test-cycle, icalendar-tests--do-test-cycle): + Include UID in cycle tests. + (icalendar-cycle, icalendar-real-world): UID-import change. + 2012-05-21 Glenn Morris * automated/Makefile.in (setwins): Scrap superfluous subshell. diff --git a/test/automated/icalendar-tests.el b/test/automated/icalendar-tests.el index 503ea22d2b8..dbf262d9f77 100644 --- a/test/automated/icalendar-tests.el +++ b/test/automated/icalendar-tests.el @@ -682,7 +682,7 @@ Argument EXPECTED-AMERICAN expected american style diary string." (unless (eq (char-before) ?\n) (insert "\n")) (insert "END:VEVENT\nEND:VCALENDAR\n")) - (let ((icalendar-import-format "%s%d%l%o%t%u%c") + (let ((icalendar-import-format "%s%d%l%o%t%u%c%U") (icalendar-import-format-summary "%s") (icalendar-import-format-location "\n Location: %s") (icalendar-import-format-description "\n Desc: %s") @@ -690,6 +690,7 @@ Argument EXPECTED-AMERICAN expected american style diary string." (icalendar-import-format-status "\n Status: %s") (icalendar-import-format-url "\n URL: %s") (icalendar-import-format-class "\n Class: %s") + (icalendar-import-format-uid "\n UID: %s") calendar-date-style) (when expected-iso (setq calendar-date-style 'iso) @@ -751,14 +752,17 @@ DTSTAMP:20031103T011641Z "&%%(and (diary-block 2004 7 19 2004 8 27)) Sommerferien Status: TENTATIVE Class: PRIVATE + UID: 748f2da0-0d9b-11d8-97af-b4ec8686ea61 " "&%%(and (diary-block 19 7 2004 27 8 2004)) Sommerferien Status: TENTATIVE Class: PRIVATE + UID: 748f2da0-0d9b-11d8-97af-b4ec8686ea61 " "&%%(and (diary-block 7 19 2004 8 27 2004)) Sommerferien Status: TENTATIVE Class: PRIVATE + UID: 748f2da0-0d9b-11d8-97af-b4ec8686ea61 ") (icalendar-tests--test-import "UID @@ -782,13 +786,16 @@ LAST-MODIFIED " "&2004/11/23 14:00-14:30 folded summary Status: TENTATIVE - Class: PRIVATE\n" + Class: PRIVATE + UID: 04979712-3902-11d9-93dd-8f9f4afe08da\n" "&23/11/2004 14:00-14:30 folded summary Status: TENTATIVE - Class: PRIVATE\n" + Class: PRIVATE + UID: 04979712-3902-11d9-93dd-8f9f4afe08da\n" "&11/23/2004 14:00-14:30 folded summary Status: TENTATIVE - Class: PRIVATE\n") + Class: PRIVATE + UID: 04979712-3902-11d9-93dd-8f9f4afe08da\n") (icalendar-tests--test-import "UID @@ -810,13 +817,16 @@ DTSTAMP " "&2004/11/23 14:45-15:45 another example Status: TENTATIVE - Class: PRIVATE\n" + Class: PRIVATE + UID: 6161a312-3902-11d9-b512-f764153bb28b\n" "&23/11/2004 14:45-15:45 another example Status: TENTATIVE - Class: PRIVATE\n" + Class: PRIVATE + UID: 6161a312-3902-11d9-b512-f764153bb28b\n" "&11/23/2004 14:45-15:45 another example Status: TENTATIVE - Class: PRIVATE\n")) + Class: PRIVATE + UID: 6161a312-3902-11d9-b512-f764153bb28b\n")) (ert-deftest icalendar-import-rrule () (icalendar-tests--test-import @@ -879,7 +889,6 @@ RRULE:FREQ=MONTHLY;UNTIL=20050819; "DTSTART;VALUE=DATE:20040815 DTEND;VALUE=DATE:20040816 SUMMARY:Maria Himmelfahrt -UID:CC56BEA6-49D2-11D8-8833-00039386D1C2-RID RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=8 " "&%%(and (diary-anniversary 2004 8 15)) Maria Himmelfahrt\n" @@ -982,11 +991,14 @@ SEQUENCE:1 CREATED:20041127T183329 " "&%%(and (diary-cyclic 1 2001 12 21) (diary-block 2001 12 21 2001 12 29)) Urlaub - Class: PUBLIC\n" + Class: PUBLIC + UID: 20041127T183329Z-18215-1001-4536-49109@andromeda\n" "&%%(and (diary-cyclic 1 21 12 2001) (diary-block 21 12 2001 29 12 2001)) Urlaub - Class: PUBLIC\n" + Class: PUBLIC + UID: 20041127T183329Z-18215-1001-4536-49109@andromeda\n" "&%%(and (diary-cyclic 1 12 21 2001) (diary-block 12 21 2001 12 29 2001)) Urlaub - Class: PUBLIC\n")) + Class: PUBLIC + UID: 20041127T183329Z-18215-1001-4536-49109@andromeda\n")) (ert-deftest icalendar-import-bug-6766 () ;;bug#6766 -- multiple byday values in a weekly rrule @@ -1016,20 +1028,26 @@ UID:8814e3f9-7482-408f-996c-3bfe486a1263 "&%%(and (memq (calendar-day-of-week date) '(1 3 4 5)) (diary-cyclic 1 2010 4 21)) 11:30-12:00 Scrum Status: CONFIRMED Class: PUBLIC + UID: 8814e3f9-7482-408f-996c-3bfe486a1262 &%%(and (memq (calendar-day-of-week date) '(2 4)) (diary-cyclic 1 2010 4 22)) Tues + Thurs thinking Class: PUBLIC + UID: 8814e3f9-7482-408f-996c-3bfe486a1263 " "&%%(and (memq (calendar-day-of-week date) '(1 3 4 5)) (diary-cyclic 1 21 4 2010)) 11:30-12:00 Scrum Status: CONFIRMED Class: PUBLIC + UID: 8814e3f9-7482-408f-996c-3bfe486a1262 &%%(and (memq (calendar-day-of-week date) '(2 4)) (diary-cyclic 1 22 4 2010)) Tues + Thurs thinking Class: PUBLIC + UID: 8814e3f9-7482-408f-996c-3bfe486a1263 " "&%%(and (memq (calendar-day-of-week date) '(1 3 4 5)) (diary-cyclic 1 4 21 2010)) 11:30-12:00 Scrum Status: CONFIRMED Class: PUBLIC + UID: 8814e3f9-7482-408f-996c-3bfe486a1262 &%%(and (memq (calendar-day-of-week date) '(2 4)) (diary-cyclic 1 4 22 2010)) Tues + Thurs thinking Class: PUBLIC + UID: 8814e3f9-7482-408f-996c-3bfe486a1263 ")) (ert-deftest icalendar-import-multiple-vcalendars () @@ -1074,6 +1092,17 @@ END:VCALENDAR "&23/7/2011 event-1\n&24/7/2011 event-2\n&25/7/2011 event-3a\n&25/7/2011 event-3b\n" "&7/23/2011 event-1\n&7/24/2011 event-2\n&7/25/2011 event-3a\n&7/25/2011 event-3b\n")) +(ert-deftest icalendar-import-with-uid () + "Perform import test with uid." + (icalendar-tests--test-import + "UID:1234567890uid +SUMMARY:non-recurring +DTSTART;VALUE=DATE-TIME:20030919T090000 +DTEND;VALUE=DATE-TIME:20030919T113000" + "&2003/9/19 09:00-11:30 non-recurring\n UID: 1234567890uid\n" + "&19/9/2003 09:00-11:30 non-recurring\n UID: 1234567890uid\n" + "&9/19/2003 09:00-11:30 non-recurring\n UID: 1234567890uid\n")) + ;; ====================================================================== ;; Cycle ;; ====================================================================== @@ -1089,14 +1118,15 @@ Argument INPUT icalendar event string." (unless (eq (char-before) ?\n) (insert "\n")) (insert "END:VEVENT\nEND:VCALENDAR\n")) - (let ((icalendar-import-format "%s%d%l%o%t%u%c") + (let ((icalendar-import-format "%s%d%l%o%t%u%c%U") (icalendar-import-format-summary "%s") (icalendar-import-format-location "\n Location: %s") (icalendar-import-format-description "\n Desc: %s") (icalendar-import-format-organizer "\n Organizer: %s") (icalendar-import-format-status "\n Status: %s") (icalendar-import-format-url "\n URL: %s") - (icalendar-import-format-class "\n Class: %s")) + (icalendar-import-format-class "\n Class: %s") + (icalendar-import-format-class "\n UID: %s")) (dolist (calendar-date-style '(iso european american)) (icalendar-tests--do-test-cycle))))) @@ -1120,8 +1150,8 @@ Argument INPUT icalendar event string." (save-excursion (find-file temp-ics) (goto-char (point-min)) - (when (re-search-forward "\nUID:.*\n" nil t) - (replace-match "\n")) + ;;(when (re-search-forward "\nUID:.*\n" nil t) + ;;(replace-match "\n")) (let ((cycled (buffer-substring-no-properties (point-min) (point-max)))) (should (string= org-input cycled))))) ;; clean up @@ -1134,14 +1164,17 @@ Argument INPUT icalendar event string." (delete-file temp-ics)))) (ert-deftest icalendar-cycle () - "Perform cycling tests." + "Perform cycling tests. +Take care to avoid auto-generated UIDs here." (icalendar-tests--test-cycle - "DTSTART;VALUE=DATE-TIME:20030919T090000 + "UID:dummyuid +DTSTART;VALUE=DATE-TIME:20030919T090000 DTEND;VALUE=DATE-TIME:20030919T113000 SUMMARY:Cycletest ") (icalendar-tests--test-cycle - "DTSTART;VALUE=DATE-TIME:20030919T090000 + "UID:blah +DTSTART;VALUE=DATE-TIME:20030919T090000 DTEND;VALUE=DATE-TIME:20030919T113000 SUMMARY:Cycletest DESCRIPTION:beschreibung! @@ -1149,7 +1182,8 @@ LOCATION:nowhere ORGANIZER:ulf ") (icalendar-tests--test-cycle - "DTSTART;VALUE=DATE:19190909 + "UID:4711 +DTSTART;VALUE=DATE:19190909 DTEND;VALUE=DATE:19190910 RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=09;BYMONTHDAY=09 SUMMARY:and diary-anniversary @@ -1222,12 +1256,14 @@ END:VCALENDAR" Location: Cccc Organizer: MAILTO:aaaaaaa@aaaaaaa.com Status: CONFIRMED + UID: 040000008200E00074C5B7101A82E0080000000080B6DE661216C301000000000000000010000000DB823520692542408ED02D7023F9DFF9 " "&5/9/2003 10:30-15:30 On-Site Interview Desc: 10:30am - Blah Location: Cccc Organizer: MAILTO:aaaaaaa@aaaaaaa.com Status: CONFIRMED + UID: 040000008200E00074C5B7101A82E0080000000080B6DE661216C301000000000000000010000000DB823520692542408ED02D7023F9DFF9 ") ;; 2003-06-18 a @@ -1268,12 +1304,14 @@ END:VALARM" Location: 555 or TN 555-5555 ID 5555 & NochWas (see below) Organizer: MAILTO:xxx@xxxxx.com Status: CONFIRMED + UID: 040000008200E00074C5B7101A82E00800000000608AA7DA9835C3010000000000000000100000007C3A6D65EE726E40B7F3D69A23BD567E " "&6/23/2003 11:00-12:00 Dress Rehearsal for XXXX-XXXX Desc: 753 Zeichen hier radiert Location: 555 or TN 555-5555 ID 5555 & NochWas (see below) Organizer: MAILTO:xxx@xxxxx.com Status: CONFIRMED + UID: 040000008200E00074C5B7101A82E00800000000608AA7DA9835C3010000000000000000100000007C3A6D65EE726E40B7F3D69A23BD567E ") ;; 2003-06-18 b -- uses timezone (icalendar-tests--test-import @@ -1338,12 +1376,14 @@ END:VCALENDAR" Location: 123 or TN 123-1234 ID abcd & SonstWo (see below) Organizer: MAILTO:bbb@bbbbb.com Status: CONFIRMED + UID: 040000008200E00074C5B7101A82E00800000000608AA7DA9835C3010000000000000000100000007C3A6D65EE726E40B7F3D69A23BD567E " "&6/23/2003 17:00-18:00 Updated: Dress Rehearsal for ABC01-15 Desc: Viele Zeichen standen hier früher Location: 123 or TN 123-1234 ID abcd & SonstWo (see below) Organizer: MAILTO:bbb@bbbbb.com Status: CONFIRMED + UID: 040000008200E00074C5B7101A82E00800000000608AA7DA9835C3010000000000000000100000007C3A6D65EE726E40B7F3D69A23BD567E ") ;; export 2004-10-28 block entries (icalendar-tests--test-export @@ -1567,8 +1607,6 @@ VERSION PRODID :-//Mozilla.org/NONSGML Mozilla Calendar V1.0//EN BEGIN:VEVENT -UID - :04979712-3902-11d9-93dd-8f9f4afe08da SUMMARY :Jjjjj & Wwwww STATUS @@ -1587,8 +1625,6 @@ LAST-MODIFIED :20041118T013640Z END:VEVENT BEGIN:VEVENT -UID - :6161a312-3902-11d9-b512-f764153bb28b SUMMARY :BB Aaaaaaaa Bbbbb STATUS @@ -1605,8 +1641,6 @@ DTSTAMP :20041118T013641Z END:VEVENT BEGIN:VEVENT -UID - :943a4d7e-3902-11d9-9ce7-c9addeadf928 SUMMARY :Hhhhhhhh STATUS @@ -1623,8 +1657,6 @@ DTSTAMP :20041118T013831Z END:VEVENT BEGIN:VEVENT -UID - :fe53615e-3902-11d9-9dd8-9d38a155bf41 SUMMARY :MMM Aaaaaaaaa STATUS @@ -1645,8 +1677,6 @@ DTSTAMP :20041118T014117Z END:VEVENT BEGIN:VEVENT -UID - :87c928ee-3901-11d9-b21f-b45042155024 SUMMARY :Rrrr/Cccccc ii Aaaaaaaa DESCRIPTION @@ -1669,8 +1699,6 @@ LAST-MODIFIED :20041118T014203Z END:VEVENT BEGIN:VEVENT -UID - :e8f331ae-3902-11d9-9948-dfdcb66a2872 SUMMARY :Wwww aa hhhh STATUS @@ -1790,11 +1818,13 @@ DTSTAMP Desc: abcdef Status: CONFIRMED Class: PRIVATE + UID: b60d398e-1dd1-11b2-a159-cf8cb05139f4 " "&%%(and (diary-block 2 6 2005 2 6 2005)) Waitangi Day Desc: abcdef Status: CONFIRMED Class: PRIVATE + UID: b60d398e-1dd1-11b2-a159-cf8cb05139f4 ") ;; 2005-03-01 lt @@ -1805,8 +1835,10 @@ UID:6AFA7558-6994-11D9-8A3A-000A95A0E830-RID DTSTAMP:20050118T210335Z DURATION:P7D" nil - "&%%(and (diary-block 17 2 2005 23 2 2005)) Hhhhhh Aaaaa ii Aaaaaaaa\n" - "&%%(and (diary-block 2 17 2005 2 23 2005)) Hhhhhh Aaaaa ii Aaaaaaaa\n") + "&%%(and (diary-block 17 2 2005 23 2 2005)) Hhhhhh Aaaaa ii Aaaaaaaa + UID: 6AFA7558-6994-11D9-8A3A-000A95A0E830-RID\n" + "&%%(and (diary-block 2 17 2005 2 23 2005)) Hhhhhh Aaaaa ii Aaaaaaaa + UID: 6AFA7558-6994-11D9-8A3A-000A95A0E830-RID\n") ;; 2005-03-23 lt (icalendar-tests--test-export -- 2.39.2