summaryrefslogtreecommitdiff
path: root/tests/test-calendar-sync--split-events.el
blob: a5a957c312fd5e7d0a00d2556ccc820bdd348d89 (plain)
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
;;; test-calendar-sync--split-events.el --- Tests for VEVENT block splitter -*- lexical-binding: t; -*-

;;; Commentary:
;; Tests for calendar-sync--split-events.
;; Splits raw .ics content into individual VEVENT block strings.

;;; Code:

(require 'ert)
(require 'testutil-calendar-sync)
(require 'calendar-sync)

;;; Normal Cases

(ert-deftest test-calendar-sync--split-events-normal-single ()
  "Single VEVENT returns one-element list."
  (let* ((ics "BEGIN:VCALENDAR\nBEGIN:VEVENT\nSUMMARY:Test\nEND:VEVENT\nEND:VCALENDAR")
         (result (calendar-sync--split-events ics)))
    (should (= 1 (length result)))
    (should (string-match-p "SUMMARY:Test" (car result)))))

(ert-deftest test-calendar-sync--split-events-normal-multiple ()
  "Multiple VEVENTs return corresponding list."
  (let* ((ics (concat "BEGIN:VCALENDAR\n"
                      "BEGIN:VEVENT\nSUMMARY:First\nEND:VEVENT\n"
                      "BEGIN:VEVENT\nSUMMARY:Second\nEND:VEVENT\n"
                      "END:VCALENDAR"))
         (result (calendar-sync--split-events ics)))
    (should (= 2 (length result)))
    (should (string-match-p "First" (nth 0 result)))
    (should (string-match-p "Second" (nth 1 result)))))

;;; Boundary Cases

(ert-deftest test-calendar-sync--split-events-boundary-empty-calendar ()
  "Calendar with no VEVENTs returns empty list."
  (let ((ics "BEGIN:VCALENDAR\nVERSION:2.0\nEND:VCALENDAR"))
    (should (null (calendar-sync--split-events ics)))))

(ert-deftest test-calendar-sync--split-events-boundary-preserves-content ()
  "Each extracted block contains BEGIN:VEVENT through END:VEVENT."
  (let* ((ics "BEGIN:VEVENT\nUID:abc\nSUMMARY:Test\nEND:VEVENT")
         (result (calendar-sync--split-events ics)))
    (should (string-prefix-p "BEGIN:VEVENT" (car result)))
    (should (string-suffix-p "END:VEVENT" (car result)))))

;;; Error Cases

(ert-deftest test-calendar-sync--split-events-error-empty-string ()
  "Empty string returns empty list."
  (should (null (calendar-sync--split-events ""))))

(provide 'test-calendar-sync--split-events)
;;; test-calendar-sync--split-events.el ends here