aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/lisp/calendar/icalendar-tests.el130
1 files changed, 126 insertions, 4 deletions
diff --git a/test/lisp/calendar/icalendar-tests.el b/test/lisp/calendar/icalendar-tests.el
index d496878205b..2beab614c87 100644
--- a/test/lisp/calendar/icalendar-tests.el
+++ b/test/lisp/calendar/icalendar-tests.el
@@ -183,6 +183,7 @@
183(ert-deftest icalendar--parse-vtimezone () 183(ert-deftest icalendar--parse-vtimezone ()
184 "Test method for `icalendar--parse-vtimezone'." 184 "Test method for `icalendar--parse-vtimezone'."
185 (let (vtimezone result) 185 (let (vtimezone result)
186 ;; testcase: valid timezone with rrule
186 (setq vtimezone (icalendar-tests--get-ical-event "BEGIN:VTIMEZONE 187 (setq vtimezone (icalendar-tests--get-ical-event "BEGIN:VTIMEZONE
187TZID:thename 188TZID:thename
188BEGIN:STANDARD 189BEGIN:STANDARD
@@ -204,6 +205,8 @@ END:VTIMEZONE
204 (message (cdr result)) 205 (message (cdr result))
205 (should (string= "STD-02:00DST-03:00,M3.5.0/03:00:00,M10.5.0/04:00:00" 206 (should (string= "STD-02:00DST-03:00,M3.5.0/03:00:00,M10.5.0/04:00:00"
206 (cdr result))) 207 (cdr result)))
208
209 ;; testcase: name of tz contains comma
207 (setq vtimezone (icalendar-tests--get-ical-event "BEGIN:VTIMEZONE 210 (setq vtimezone (icalendar-tests--get-ical-event "BEGIN:VTIMEZONE
208TZID:anothername, with a comma 211TZID:anothername, with a comma
209BEGIN:STANDARD 212BEGIN:STANDARD
@@ -225,7 +228,8 @@ END:VTIMEZONE
225 (message (cdr result)) 228 (message (cdr result))
226 (should (string= "STD-02:00DST-03:00,M3.2.1/03:00:00,M10.2.1/04:00:00" 229 (should (string= "STD-02:00DST-03:00,M3.2.1/03:00:00,M10.2.1/04:00:00"
227 (cdr result))) 230 (cdr result)))
228 ;; offsetfrom = offsetto 231
232 ;; testcase: offsetfrom = offsetto
229 (setq vtimezone (icalendar-tests--get-ical-event "BEGIN:VTIMEZONE 233 (setq vtimezone (icalendar-tests--get-ical-event "BEGIN:VTIMEZONE
230TZID:Kolkata, Chennai, Mumbai, New Delhi 234TZID:Kolkata, Chennai, Mumbai, New Delhi
231X-MICROSOFT-CDO-TZID:23 235X-MICROSOFT-CDO-TZID:23
@@ -245,7 +249,10 @@ END:VTIMEZONE
245 (should (string= "Kolkata, Chennai, Mumbai, New Delhi" (car result))) 249 (should (string= "Kolkata, Chennai, Mumbai, New Delhi" (car result)))
246 (message (cdr result)) 250 (message (cdr result))
247 (should (string= "STD-05:30DST-05:30,M1.1.1/00:00:00,M1.1.1/00:00:00" 251 (should (string= "STD-05:30DST-05:30,M1.1.1/00:00:00,M1.1.1/00:00:00"
248 (cdr result))))) 252 (cdr result)))
253
254 ;; FIXME: add testcase that covers changes for fix of bug#34315
255 ))
249 256
250(ert-deftest icalendar--convert-ordinary-to-ical () 257(ert-deftest icalendar--convert-ordinary-to-ical ()
251 "Test method for `icalendar--convert-ordinary-to-ical'." 258 "Test method for `icalendar--convert-ordinary-to-ical'."
@@ -482,17 +489,132 @@ END:VEVENT
482 (should (equal '(0 0 10 1 8 2013 4 t 10800) 489 (should (equal '(0 0 10 1 8 2013 4 t 10800)
483 (icalendar--decode-isodatetime "20130801T100000"))) 490 (icalendar--decode-isodatetime "20130801T100000")))
484 491
492 ;; testcase: no time zone in input, shift by -1 days
493 ;; 1 Jan 2013 10:00 -> 31 Dec 2012
494 (should (equal '(0 0 10 31 12 2012 1 nil 7200)
495 (icalendar--decode-isodatetime "20130101T100000" -1)))
496 ;; 1 Aug 2013 10:00 (DST) -> 31 Jul 2012 (DST)
497 (should (equal '(0 0 10 31 7 2013 3 t 10800)
498 (icalendar--decode-isodatetime "20130801T100000" -1)))
499
500
485 ;; testcase: UTC time zone specifier in input -> convert to local time 501 ;; testcase: UTC time zone specifier in input -> convert to local time
486 ;; 31 Dec 2013 23:00 UTC -> 1 Jan 2013 01:00 EET 502 ;; 31 Dec 2013 23:00 UTC -> 1 Jan 2014 01:00 EET
487 (should (equal '(0 0 1 1 1 2014 3 nil 7200) 503 (should (equal '(0 0 1 1 1 2014 3 nil 7200)
488 (icalendar--decode-isodatetime "20131231T230000Z"))) 504 (icalendar--decode-isodatetime "20131231T230000Z")))
489 ;; 1 Aug 2013 10:00 UTC -> 1 Aug 2013 13:00 EEST 505 ;; 1 Aug 2013 10:00 UTC -> 1 Aug 2013 13:00 EEST
490 (should (equal '(0 0 13 1 8 2013 4 t 10800) 506 (should (equal '(0 0 13 1 8 2013 4 t 10800)
491 (icalendar--decode-isodatetime "20130801T100000Z"))) 507 (icalendar--decode-isodatetime "20130801T100000Z")))
492 508
509 ;; testcase: override timezone with Central European Time, 1 Jan 2013 10:00 -> 1 Jan 2013 11:00
510 (should (equal '(0 0 11 1 1 2013 2 nil 7200)
511 (icalendar--decode-isodatetime "20130101T100000" nil
512 '(3600 "CET"))))
513 ;; testcase: override timezone (UTC-02:00), 1 Jan 2013 10:00 -> 1 Jan 2013 14:00
514 (should (equal '(0 0 14 1 1 2013 2 nil 7200)
515 (icalendar--decode-isodatetime "20130101T100000" nil -7200)))
516
517 ;; FIXME: add testcase that covers changes for fix of bug#34315
518
519 )
520 ;; restore time-zone even if something went terribly wrong
521 (setenv "TZ" tz))))
522
523(ert-deftest icalendar--convert-tz-offset ()
524 "Test `icalendar--convert-tz-offset'."
525 (let ((tz (getenv "TZ")))
526 (unwind-protect
527 (progn
528 ;; Use Eastern European Time (UTC+2, UTC+3 daylight saving)
529 (setenv "TZ" "EET-2EEST,M3.5.0/3,M10.5.0/4")
530
531 ;; testcase: artificial input
532 (should (equal '("DST-03:00" . "M5.1.1/01:23:45")
533 (icalendar--convert-tz-offset
534 '((DTSTART nil "________T012345") ;
535 (TZOFFSETFROM nil "+0200")
536 (TZOFFSETTO nil "+0300")
537 (RRULE nil "FREQ=YEARLY;INTERVAL=1;BYDAY=1MO;BYMONTH=5"))
538 t)))
539
540 ;; testcase: Europe/Berlin Standard
541 (should (equal '("STD-01:00" . "M10.5.0/03:00:00")
542 (icalendar--convert-tz-offset
543 '((TZOFFSETFROM nil "+0200")
544 (TZOFFSETTO nil "+0100")
545 (TZNAME nil CET)
546 (DTSTART nil "19701025T030000")
547 (RRULE nil "FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU"))
548 nil)))
549
550 ;; testcase: Europe/Berlin DST
551 (should (equal '("DST-02:00" . "M3.5.0/02:00:00")
552 (icalendar--convert-tz-offset
553 '((TZOFFSETFROM nil "+0100")
554 (TZOFFSETTO nil "+0200")
555 (TZNAME nil CEST)
556 (DTSTART nil "19700329T020000")
557 (RRULE nil "FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU"))
558 t)))
559
560 ;; testcase: dtstart is mandatory
561 (should (null (icalendar--convert-tz-offset
562 '((TZOFFSETFROM nil "+0100")
563 (TZOFFSETTO nil "+0200")
564 (RRULE nil "FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU"))
565 t)))
566
567 ;; FIXME: rrule and rdate are NOT mandatory! Must fix code
568 ;; before activating these testcases
569 ;; ;; testcase: no rrule and no rdate => no result
570 ;; (should (null (icalendar--convert-tz-offset
571 ;; '((TZOFFSETFROM nil "+0100")
572 ;; (TZOFFSETTO nil "+0200")
573 ;; (DTSTART nil "19700329T020000"))
574 ;; t)))
575 ;; ;; testcase: no rrule with rdate => no result
576 ;; (should (null (icalendar--convert-tz-offset
577 ;; '((TZOFFSETFROM nil "+0100")
578 ;; (TZOFFSETTO nil "+0200")
579 ;; (DTSTART nil "18840101T000000")
580 ;; (RDATE nil "18840101T000000"))
581 ;; t)))
493 ) 582 )
494 ;; restore time-zone even if something went terribly wrong 583 ;; restore time-zone even if something went terribly wrong
495 (setenv "TZ" tz))) ) 584 (setenv "TZ" tz))))
585
586(ert-deftest icalendar--decode-isoduration ()
587 "Test `icalendar--decode-isoduration'."
588
589 ;; testcase: 7 days
590 (should (equal '(0 0 0 7 0 0)
591 (icalendar--decode-isoduration "P7D")))
592
593 ;; testcase: 7 days, one second -- to be fixed with bug#34315
594 ;; (should (equal '(1 0 0 7 0 0)
595 ;; (icalendar--decode-isoduration "P7DT1S")))
596
597 ;; testcase: 3 hours, 2 minutes, one second
598 (should (equal '(1 2 3 0 0 0)
599 (icalendar--decode-isoduration "PT3H2M1S")))
600
601 ;; testcase: 99 days, 3 hours, 2 minutes, one second -- to be fixed with bug#34315
602 ;; (should (equal '(1 2 3 99 0 0)
603 ;; (icalendar--decode-isoduration "P99DT3H2M1S")))
604
605 ;; testcase: 2 weeks
606 (should (equal '(0 0 0 14 0 0)
607 (icalendar--decode-isoduration "P2W")))
608
609 ;; testcase: rfc2445, section 4.3.6: 15 days, 5 hours and 20 seconds -- to be fixed with bug#34315
610 ;; (should (equal '(20 0 5 15 0 0)
611 ;; (icalendar--decode-isoduration "P15DT5H0M20S")))
612
613 ;; testcase: rfc2445, section 4.3.6: 7 weeks
614 (should (equal '(0 0 0 49 0 0)
615 (icalendar--decode-isoduration "P7W")))
616 )
617
496 618
497;; ====================================================================== 619;; ======================================================================
498;; Export tests 620;; Export tests