Thanks to Stefan Monnier for the comments in Bug#74994 leading to most of these changes. Improvements in diary-icalendar.el and related changes: * lisp/calendar/diary-icalendar.el (icalendar-save-binary-atttachment): Rename to `diary-icalendar-save-binary-attachment'. Document internal require. (diary-icalendar-attendee-skeleton-command): Rename to `diary-icalendar-attendee-format-function'. (diary-icalendar-vevent-skeleton-command): Rename to `diary-icalendar-vevent-format-function'. (diary-icalendar-vjournal-skeleton-command): Rename to `diary-icalendar-vjournal-format-function'. (diary-icalendar-vtodo-skeleton-command): Rename to `diary-icalendar-vtodo-format-function'. * doc/emacs/calendar.texi (Diary iCalendar Import) * lisp/calendar/icalendar.el (icalendar-import-format) (icalendar-import-format-summary, icalendar-import-format-description) (icalendar-import-format-location, icalendar-import-format-organizer) (icalendar-import-format-url, icalendar-import-format-uid) (icalendar-import-format-status, icalendar-import-format-class): Update references to renamed functions. (diary-icalendar-attendee-format-function): Fix quoted function name. (diary-icalendar-attendee-format-function) (diary-icalendar-vevent-format-function) (diary-icalendar-vjournal-format-function) (diary-icalendar-vtodo-format-function) (diary-icalendar-after-mailcap-viewer-hook): Improve docstrings. (diary-icalendar-skip-addresses-regexp): Ensure default value is a regexp. (diary-icalendar-description-regexp): Fix :type declaration to agree with default. (diary-icalendar-format-date): Replace unnecessary `calendar-dlet' with `dlet'. (diary-icalendar-vevent-format-function) (diary-icalendar-vjournal-format-function) (diary-icalendar-vtodo-format-function) (diary-icalendar-format-entry) (diary-icalendar-import-buffer-to-buffer) (diary-icalendar--entry-import) (diary-icalendar-import-buffer) (diary-icalendar-import-file): Change "non-marking" to "nonmarking" in variable names for consistency (cf. `diary-nonmarking-symbol'). (diary-icalendar-attendee-skeleton): Remove unnecessary call to `skeleton-insert'. (diary-icalendar-vevent-skeleton) (diary-icalendar-vjournal-skeleton) (diary-icalendar-vtodo-skeleton): Don't insert return values of `let' forms. (diary-icalendar-parse-entry): Call `diary-icalendar-other-properties-parser' with type and properties as arguments, instead of dynamic binding. (diary-icalendar-other-properties-parser): Document the new calling convention. * test/lisp/calendar/diary-icalendar-tests.el (diary-icalendar-test-parse-@-location): Accept the new arguments. Clarify `declare-function' usage: * lisp/calendar/icalendar-parser.el (icalendar-read-time) (icalendar-period-end, icalendar-parse-calendar) (icalendar-index-insert, icalendar-index-get) * lisp/calendar/icalendar-ast.el (icalendar-printable-value-type-symbol-p) (icalendar-ast-node-valid-value-p) * lisp/calendar/icalendar-utils.el (icalendar-date-time-add) (icalendar-dates-until, icalendar-date-time-variant): Move `declare-function' forms to corresponding `require' forms. Improve debugging with icalendar-ast.el macros: * lisp/calendar/icalendar-ast.el (icalendar-make-value-node-of): Add explanatory comment to require. (icalendar--make-param--list, icalendar--make-param--nonlist) (icalendar--make-property--list, icalendar--make-property--nonlist): New functions. (icalendar-make-param, icalendar-make-property): Use them to reduce code generated by these macros. Add (declare (debug ...)) forms. (icalendar-make-component, icalendar-make-node-from-templates): Add (declare (debug ...)) forms. * test/lisp/calendar/icalendar-ast-tests.el: New file. Various other minor changes: * lisp/calendar/icalendar-macs.el (icalendar-define-type): Improve docstring. (icalendar-define-property): Fix deprecation warning: replace 'any' with 'not-newline' in rx definition. * test/lisp/calendar/icalendar-recur-tests.el (icalendar-test-rrule-test): Pass tags on to `ert-deftest' and mark several tests as expensive. * lisp/calendar/calendar.el (diary-date-insertion-form): Remove constants from :set-after list. * lisp/calendar/diary-lib.el (diary-time-regexp): Clarify FIXME comment. * lisp/calendar/icalendar-parser.el (icalendar-x-name): Fix indentation. (icalendar-cal-address): Improve docstring.
113 lines
5.2 KiB
EmacsLisp
113 lines
5.2 KiB
EmacsLisp
;;; tests/icalendar-ast.el --- Tests for icalendar-ast -*- lexical-binding: t; -*-
|
|
;; Copyright (C) 2025 Free Software Foundation, Inc.
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
;; it under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
;; (at your option) any later version.
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;; GNU General Public License for more details.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
;;; Code:
|
|
(require 'icalendar-ast)
|
|
(require 'icalendar-parser)
|
|
(require 'cl-lib)
|
|
(eval-when-compile (require 'icalendar-macs))
|
|
|
|
|
|
;; Tests for the high-level construction macros:
|
|
(ert-deftest iat:make-param/nonlist ()
|
|
"Test that `icalendar-make-param' works as documented with a single value."
|
|
(let ((cnparam-node (ical:make-param ical:cnparam "John Doe")))
|
|
(should (ical:param-node-p cnparam-node))
|
|
(should (eq 'ical:cnparam (ical:ast-node-type cnparam-node)))
|
|
(ical:with-param cnparam-node
|
|
(should (cl-typep value 'ical:text))
|
|
(should (equal value "John Doe")))))
|
|
|
|
(ert-deftest iat:make-param/list ()
|
|
"Test that `icalendar-make-param' works as documented with a list of values."
|
|
(let ((deltoparam-node (ical:make-param ical:deltoparam
|
|
(list "mailto:minionA@example.com"
|
|
"mailto:minionB@example.com"))))
|
|
(should (ical:param-node-p deltoparam-node))
|
|
(should (eq 'ical:deltoparam (ical:ast-node-type deltoparam-node)))
|
|
(ical:with-param deltoparam-node
|
|
(should (and (listp value-nodes) (length= value-nodes 2)))
|
|
(should (seq-every-p
|
|
(lambda (n) (eq 'ical:cal-address (ical:ast-node-type n)))
|
|
value-nodes))
|
|
(should (equal "mailto:minionA@example.com" (car values)))
|
|
(should (equal "mailto:minionB@example.com" (cadr values))))))
|
|
|
|
(ert-deftest iat:make-property/nonlist ()
|
|
"Test that `icalendar-make-property' works as documented with a single value."
|
|
(let ((attendee-node
|
|
(ical:make-property ical:attendee "mailto:hermes@planetexpress.com"
|
|
(ical:cnparam "H. Conrad"))))
|
|
(should (ical:property-node-p attendee-node))
|
|
(should (eq 'ical:attendee (ical:ast-node-type attendee-node)))
|
|
(ical:with-property attendee-node
|
|
((ical:cnparam :first cnparam-node :value cn))
|
|
(should (eq value-type 'ical:cal-address))
|
|
(should (equal value "mailto:hermes@planetexpress.com"))
|
|
(should (eq 'ical:cnparam (ical:ast-node-type cnparam-node)))
|
|
(should (equal cn "H. Conrad")))))
|
|
|
|
(ert-deftest iat:make-property/list ()
|
|
"Test that `icalendar-make-property' works as documented with a list of values."
|
|
(let ((rdate-node (icalendar-make-property icalendar-rdate
|
|
(list '(2 1 2025) '(3 1 2025)))))
|
|
(should (ical:property-node-p rdate-node))
|
|
(should (eq 'ical:rdate (ical:ast-node-type rdate-node)))
|
|
(ical:with-property rdate-node
|
|
((ical:valuetypeparam :first valtype-node :value valtype))
|
|
(should (and (listp value-nodes) (length= value-nodes 2)))
|
|
(should (seq-every-p
|
|
(lambda (n) (eq 'ical:date (ical:ast-node-type n)))
|
|
value-nodes))
|
|
(should (equal '(2 1 2025) (car values)))
|
|
(should (equal '(3 1 2025) (cadr values)))
|
|
(should (ical:ast-node-p valtype-node))
|
|
(should (eq 'ical:valuetypeparam (ical:ast-node-type valtype-node)))
|
|
(should (eq 'ical:date valtype)))))
|
|
|
|
(ert-deftest iat:make-component ()
|
|
"Test that `icalendar-make-component' works as documented."
|
|
(let* ((others (list (icalendar-make-property ical:dtstart '(9 6 3003))
|
|
(icalendar-make-property ical:rrule '((FREQ DAILY)))))
|
|
(vevent-node (icalendar-make-component ical:vevent
|
|
(ical:summary "Party")
|
|
(ical:location "Robot House")
|
|
(@ others))))
|
|
(should (ical:component-node-p vevent-node))
|
|
(should (eq 'ical:vevent (ical:ast-node-type vevent-node)))
|
|
(ical:with-component vevent-node
|
|
((ical:uid :first uid-node)
|
|
(ical:dtstamp :first dtstamp-node)
|
|
(ical:summary :value summary)
|
|
(ical:location :value location)
|
|
(ical:dtstart :first dtstart-node :value dtstart)
|
|
(ical:rrule :first rrule-node :value rrule))
|
|
(should (and (ical:ast-node-p uid-node)
|
|
(ical:ast-node-p dtstamp-node)))
|
|
(should (equal summary "Party"))
|
|
(should (equal location "Robot House"))
|
|
(should (equal dtstart '(9 6 3003)))
|
|
(should (equal rrule '((FREQ DAILY)))))))
|
|
|
|
;; TODO: properties, components too
|
|
|
|
;; Local Variables:
|
|
;; read-symbol-shorthands: (("iat:" . "icalendar-ast-test-") ("ical:" . "icalendar-"))
|
|
;; End:
|
|
;;; icalendar-ast-tests.el ends here
|