Change the default command prefix to “C-c =”.
[pelican-mode.git] / pelican-mode-test.el
1 ;;; pelican-mode-test.el --- Tests pelican-mode -*- lexical-binding: t; -*-
2 ;;
3 ;; Copyright (C) 2017 Joe Wreschnig
4 ;;
5 ;; Author: Joe Wreschnig
6 ;;
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 2 of the License, or
10 ;; (at your option) any later version.
11 ;;
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.
16 ;;
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/>.
19
20 \f
21
22 ;;; Commentary:
23 ;;
24 ;; This file contains test cases for pelican-mode. Unless you’re
25 ;; hacking on it you shouldn’t need to edit or run this file.
26
27 \f
28
29 ;;; Code:
30
31 (require 'ert)
32 (require 'pelican-mode)
33
34 (defun pelican-mode-test-article (mode expected1 expected2)
35 "Create an article in MODE and perform some edits.
36
37 After the first edits, the buffer should contain EXPECTED1; after
38 the second, EXPECTED2."
39 (with-temp-buffer
40 (rename-buffer "pelican-test.rst")
41 (funcall mode)
42 (pelican-mode)
43
44 (should (not (pelican-mode-find-root)))
45 (should (not (pelican-mode-page-p)))
46 (should (equal "pelican-test" (pelican-mode-default-slug)))
47
48 (insert "Not really a Pelican article.")
49 (pelican-mode-insert-article-header "Testing" "a, b, c")
50 (pelican-mode-set-field :test "hello world")
51 (pelican-mode-set-field :date "1111-11-11 11:11:11")
52 (should (equal (buffer-string) expected1))
53
54 (pelican-mode-publish)
55 (pelican-mode-set-fields
56 :title "More Tests"
57 :date "2222-22-22 22:22:22")
58 (pelican-mode-remove-field "test")
59 (should (equal (buffer-string) expected2))))
60
61 (ert-deftest pelican-mode-test-rst-mode ()
62 (pelican-mode-test-article
63 #'rst-mode
64 "\
65 Testing
66 #######
67
68 :date: 1111-11-11 11:11:11
69 :status: draft
70 :slug: pelican-test
71 :tags: a, b, c
72 :test: hello world
73
74 Not really a Pelican article."
75
76 "\
77 More Tests
78 ##########
79
80 :date: 2222-22-22 22:22:22
81 :slug: pelican-test
82 :tags: a, b, c
83
84 Not really a Pelican article."))
85
86 (ert-deftest pelican-mode-test-org-mode ()
87 (pelican-mode-test-article
88 #'org-mode
89 "\
90 #+TITLE: Testing
91 #+DATE: 1111-11-11 11:11:11
92 #+PROPERTY: STATUS draft
93 #+PROPERTY: SLUG pelican-test
94 #+PROPERTY: TAGS a, b, c
95 #+PROPERTY: TEST hello world
96
97 Not really a Pelican article."
98
99 "\
100 #+TITLE: More Tests
101 #+DATE: 2222-22-22 22:22:22
102 #+PROPERTY: SLUG pelican-test
103 #+PROPERTY: TAGS a, b, c
104
105 Not really a Pelican article."))
106
107 ;;; pelican-mode-test.el ends here