Tiny refactoring
[org-mode.git] / testing / lisp / test-org-capture.el
blob6b86410307dade39223a23a1c331d7476be1b919
1 ;;; test-org-capture.el --- Tests for org-capture.el -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2015 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ;;; Commentary:
22 ;; Unit tests for Org Capture library.
24 ;;; Code:
26 (require 'org-capture)
28 (ert-deftest test-org-capture/fill-template ()
29 "Test `org-capture-fill-template' specifications."
31 ;; When working on these tests consider to also change
32 ;; `test-org-feed/fill-template'.
34 ;; %(sexp) placeholder.
35 (should
36 (equal "success!\n"
37 (org-capture-fill-template "%(concat \"success\" \"!\")")))
38 ;; %<...> placeholder.
39 (should
40 (equal (concat (format-time-string "%Y") "\n")
41 (org-capture-fill-template "%<%Y>")))
42 ;; %t and %T placeholders.
43 (should
44 (equal (concat (format-time-string (org-time-stamp-format nil nil)) "\n")
45 (org-capture-fill-template "%t")))
46 (should
47 (equal (concat (format-time-string (org-time-stamp-format t nil)) "\n")
48 (org-capture-fill-template "%T")))
49 ;; %u and %U placeholders.
50 (should
51 (equal
52 (concat (format-time-string (org-time-stamp-format nil t)) "\n")
53 (org-capture-fill-template "%u")))
54 (should
55 (equal
56 (concat (format-time-string (org-time-stamp-format t t)) "\n")
57 (org-capture-fill-template "%U")))
58 ;; %i placeholder. Make sure sexp placeholders are not expanded
59 ;; when they are inserted through this one.
60 (should
61 (equal "success!\n"
62 (let ((org-store-link-plist nil))
63 (org-capture-fill-template "%i" "success!"))))
64 (should
65 (equal "%(concat \"no \" \"evaluation\")\n"
66 (let ((org-store-link-plist nil))
67 (org-capture-fill-template
68 "%i" "%(concat \"no \" \"evaluation\")"))))
69 ;; Test %-escaping with \ character.
70 (should
71 (equal "%i\n"
72 (let ((org-store-link-plist nil))
73 (org-capture-fill-template "\\%i" "success!"))))
74 (should
75 (equal "\\success!\n"
76 (let ((org-store-link-plist nil))
77 (org-capture-fill-template "\\\\%i" "success!"))))
78 (should
79 (equal "\\%i\n"
80 (let ((org-store-link-plist nil))
81 (org-capture-fill-template "\\\\\\%i" "success!"))))
82 ;; More than one placeholder in the same template.
83 (should
84 (equal "success! success! success! success!\n"
85 (let ((org-store-link-plist nil))
86 (org-capture-fill-template "%i %i %i %i" "success!"))))
87 ;; %(sexp) placeholder with an input containing the traps %, " and )
88 ;; all at once which is complicated to parse.
89 (should
90 (equal
91 "5 % Less (See Item \"3)\" Somewhere)\n"
92 (let ((org-store-link-plist nil))
93 (org-capture-fill-template
94 "%(capitalize \"%i\")"
95 "5 % less (see item \"3)\" somewhere)")))))
100 (provide 'test-org-capture)
101 ;;; test-org-capture.el ends here