From c9586c17fd94ebfb8dd712f30dcf224ea130a8f9 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Mon, 7 Aug 2017 19:11:13 +0200 Subject: [PATCH] Add test cases. Change -publish-draft to -publish, as it also publishes hidden pages. --- Makefile | 34 ++++++++++++++ pelican-mode-test.el | 107 +++++++++++++++++++++++++++++++++++++++++++ pelican-mode.el | 34 ++++++++------ 3 files changed, 161 insertions(+), 14 deletions(-) create mode 100644 Makefile create mode 100644 pelican-mode-test.el diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..04f5e88 --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +#!/usr/bin/make -f +# +# This is free and unencumbered software released into the public +# domain. +# +# Anyone is free to copy, modify, publish, use, compile, sell, or +# distribute this software, either in source code form or as a +# compiled binary, for any purpose, commercial or non-commercial, and +# by any means. + +EMACS ?= $(firstword $(shell command -v /Applications/Emacs.app/Contents/MacOS/Emacs emacs)) +SRC := pelican-mode.el +OBJ := $(SRC:.el=.elc) +DIR := $(dir $(lastword $(MAKEFILE_LIST))) +TESTS := $(SRC:.el=.test.stamp) + +.INTERMEDIATE: $(TESTS) + +all: $(OBJ) test + +clean: + rm -f $(OBJ) $(TESTS) + +test: $(TESTS) + +%.elc: %.el + $(EMACS) -Q -batch -L $(DIR) -f batch-byte-compile $< + +%.test.stamp: %-test.elc %.elc + $(EMACS) -Q -batch -L $(DIR) -eval "(checkdoc-file \"$*.el\")" + $(EMACS) -Q -batch -L $(DIR) -l $< -f ert-run-tests-batch-and-exit + touch $@ + +.PHONY: all clean test diff --git a/pelican-mode-test.el b/pelican-mode-test.el new file mode 100644 index 0000000..e50f0bb --- /dev/null +++ b/pelican-mode-test.el @@ -0,0 +1,107 @@ +;;; pelican-mode-test.el --- Tests pelican-mode -*- lexical-binding: t; -*- +;; +;; Copyright (C) 2017 Joe Wreschnig +;; +;; Author: Joe Wreschnig +;; +;; This program 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 2 of the License, or +;; (at your option) any later version. +;; +;; This program 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 this program. If not, see . + + + +;;; Commentary: +;; +;; This file contains test cases for pelican-mode. Unless you're +;; hacking on it you shouldn't need to edit or run this file. + + + +;;; Code: + +(require 'ert) +(require 'pelican-mode) + +(defun pelican-mode-test-article (mode expected1 expected2) + "Create an article in MODE and perform some edits. + +After the first edits, the buffer should contain EXPECTED1; after +the second, EXPECTED2." + (with-temp-buffer + (rename-buffer "pelican-test.rst") + (funcall mode) + (pelican-mode) + + (should (not (pelican-mode-find-root))) + (should (not (pelican-mode-page-p))) + (should (equal "pelican-test" (pelican-mode-default-slug))) + + (insert "Not really a Pelican article.") + (pelican-mode-insert-article-header "Testing" "a, b, c") + (pelican-mode-set-field :test "hello world") + (pelican-mode-set-field :date "1111-11-11 11:11:11") + (should (equal (buffer-string) expected1)) + + (pelican-mode-publish) + (pelican-mode-set-fields + :title "More Tests" + :date "2222-22-22 22:22:22") + (pelican-mode-remove-field "test") + (should (equal (buffer-string) expected2)))) + +(ert-deftest pelican-mode-test-rst-mode () + (pelican-mode-test-article + #'rst-mode + "\ +Testing +####### + +:date: 1111-11-11 11:11:11 +:status: draft +:slug: pelican-test +:tags: a, b, c +:test: hello world + +Not really a Pelican article." + + "\ +More Tests +########## + +:date: 2222-22-22 22:22:22 +:slug: pelican-test +:tags: a, b, c + +Not really a Pelican article.")) + +(ert-deftest pelican-mode-test-org-mode () + (pelican-mode-test-article + #'org-mode + "\ +#+TITLE: Testing +#+DATE: 1111-11-11 11:11:11 +#+PROPERTY: STATUS draft +#+PROPERTY: SLUG pelican-test +#+PROPERTY: TAGS a, b, c +#+PROPERTY: TEST hello world + +Not really a Pelican article." + + "\ +#+TITLE: More Tests +#+DATE: 2222-22-22 22:22:22 +#+PROPERTY: SLUG pelican-test +#+PROPERTY: TAGS a, b, c + +Not really a Pelican article.")) + +;;; pelican-mode-test.el ends here diff --git a/pelican-mode.el b/pelican-mode.el index 60089cd..5fa2179 100644 --- a/pelican-mode.el +++ b/pelican-mode.el @@ -82,7 +82,7 @@ for editing articles or pages: (,(kbd "C-c P f") . pelican-set-field) (,(kbd "C-c P h") . pelican-make-html) (,(kbd "C-c P n") . pelican-mode-insert-header) - (,(kbd "C-c P p") . pelican-mode-publish-draft) + (,(kbd "C-c P p") . pelican-mode-publish) (,(kbd "C-c P u") . pelican-make-rsync-upload))) ;;;###autoload @@ -215,19 +215,22 @@ than the modification date." (interactive "P") (pelican-mode-set-field (if original :date :modified) 'now)) -(defun pelican-mode-publish-draft () - "Remove draft status from a Pelican article." +(defun pelican-mode-publish () + "Remove draft or hidden status from a Pelican article." (interactive) (pelican-mode-remove-field :status) (pelican-mode-update-date :date)) -(defun pelican-mode-insert-draft-article-header (title tags) - "Insert a Pelican header for a draft with a TITLE and TAGS." +(defun pelican-mode-insert-article-header (title tags) + "Insert a Pelican header for an article with a TITLE and TAGS." (interactive "sArticle title: \nsTags: ") - (apply #'pelican-mode-set-fields - `(:title ,title - ,@pelican-mode-default-article-fields - :tags ,tags))) + (save-excursion + (goto-char 0) + (insert "\n") + (apply #'pelican-mode-set-fields + `(:title ,title + ,@pelican-mode-default-article-fields + :tags ,tags)))) (defun pelican-mode-insert-page-header (title &optional hidden) "Insert a Pelican header for a page with a TITLE. @@ -235,10 +238,13 @@ than the modification date." If HIDDEN is non-nil, the page is marked hidden; otherwise it has no status." (interactive "sPage title: \nP") - (apply #'pelican-mode-set-fields - (append - (list :title title :status (when hidden "hidden")) - pelican-mode-default-page-fields))) + (save-excursion + (goto-char 0) + (insert "\n") + (apply #'pelican-mode-set-fields + (append + (list :title title :status (when hidden "hidden")) + pelican-mode-default-page-fields)))) (defun pelican-mode-insert-header () "Insert a Pelican header for a page or article." @@ -246,7 +252,7 @@ has no status." (call-interactively (if (pelican-mode-page-p) #'pelican-mode-insert-page-header - #'pelican-mode-insert-draft-article-header))) + #'pelican-mode-insert-article-header))) (defun pelican-make (target) "Execute TARGET in a Makefile at the root of the site." -- 2.30.2