blob: 737d2af0d94b8483a81971a4ff0b5678b74382c6 (
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
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
|
;;; test-calendar-sync--get-all-property-lines.el --- Tests for get-all-property-lines -*- lexical-binding: t; -*-
;;; Commentary:
;; Unit tests for calendar-sync--get-all-property-lines function.
;; Like get-property-line but returns ALL matching lines.
;; Needed because ATTENDEE appears multiple times in an event.
;; Covers Normal, Boundary, and Error cases.
;;; Code:
(require 'ert)
(require 'testutil-calendar-sync)
(require 'calendar-sync)
;;; Normal Cases
(ert-deftest test-calendar-sync--get-all-property-lines-normal-multiple ()
"Test extracting multiple ATTENDEE lines."
(let ((event "BEGIN:VEVENT\nATTENDEE;CN=Alice:mailto:alice@example.com\nATTENDEE;CN=Bob:mailto:bob@example.com\nEND:VEVENT"))
(let ((result (calendar-sync--get-all-property-lines event "ATTENDEE")))
(should (= 2 (length result)))
(should (string-match-p "Alice" (nth 0 result)))
(should (string-match-p "Bob" (nth 1 result))))))
(ert-deftest test-calendar-sync--get-all-property-lines-normal-single ()
"Test extracting single matching line."
(let ((event "BEGIN:VEVENT\nATTENDEE;CN=Alice:mailto:alice@example.com\nSUMMARY:Test\nEND:VEVENT"))
(let ((result (calendar-sync--get-all-property-lines event "ATTENDEE")))
(should (= 1 (length result)))
(should (string-match-p "Alice" (car result))))))
;;; Boundary Cases
(ert-deftest test-calendar-sync--get-all-property-lines-boundary-no-match ()
"Test no matching property returns empty list."
(let ((event "BEGIN:VEVENT\nSUMMARY:Test\nEND:VEVENT"))
(should (null (calendar-sync--get-all-property-lines event "ATTENDEE")))))
(ert-deftest test-calendar-sync--get-all-property-lines-boundary-continuation ()
"Test handling of continuation lines (lines starting with space)."
(let ((event "BEGIN:VEVENT\nATTENDEE;CN=Very Long Name;PARTSTAT=ACCEPTED:\n mailto:longname@example.com\nSUMMARY:Test\nEND:VEVENT"))
(let ((result (calendar-sync--get-all-property-lines event "ATTENDEE")))
(should (= 1 (length result)))
(should (string-match-p "longname@example.com" (car result))))))
;;; Error Cases
(ert-deftest test-calendar-sync--get-all-property-lines-error-nil-event ()
"Test nil event returns nil."
(should (null (calendar-sync--get-all-property-lines nil "ATTENDEE"))))
(ert-deftest test-calendar-sync--get-all-property-lines-error-nil-property ()
"Test nil property returns nil."
(should (null (calendar-sync--get-all-property-lines "BEGIN:VEVENT\nEND:VEVENT" nil))))
(ert-deftest test-calendar-sync--get-all-property-lines-error-empty-event ()
"Test empty event string returns nil."
(should (null (calendar-sync--get-all-property-lines "" "ATTENDEE"))))
;;; Boundary Cases — position advancement
(ert-deftest test-calendar-sync--get-all-property-lines-property-at-end-no-newline ()
"Boundary: a match at end of string with no trailing newline still returns it.
Exercises the end-equals-length branch of position advancement."
(let ((result (calendar-sync--get-all-property-lines
"ATTENDEE:foo@example.com" "ATTENDEE")))
(should (= 1 (length result)))
(should (string-match-p "foo@example.com" (car result)))))
(ert-deftest test-calendar-sync--get-all-property-lines-second-match-after-continuation ()
"Boundary: a first match with a continuation does not hide the second match."
(let ((result (calendar-sync--get-all-property-lines
"ATTENDEE:a\n more\nATTENDEE:b\nSUMMARY:x" "ATTENDEE")))
(should (= 2 (length result)))
(should (string-match-p "more" (nth 0 result)))
(should (string-match-p "ATTENDEE:b" (nth 1 result)))))
(provide 'test-calendar-sync--get-all-property-lines)
;;; test-calendar-sync--get-all-property-lines.el ends here
|