plantuml-mode/test/plantuml-preview-test.el

42 lines
1.4 KiB
EmacsLisp
Raw Normal View History

;;; plantuml-mode-preview-test.el --- PlantUML Mode preview tests -*- lexical-binding: t; -*-
;; Author: Carlo Sciolla (skuro)
;; Maintainer: Carlo Sciolla (skuro)
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;;; Code:
2017-08-27 12:51:23 +02:00
(defun assert-preview-content (expected)
"Assert the contents of the preview buffer to be equal to EXPECTED."
(should (equal (replace-regexp-in-string " " "~" expected)
(replace-regexp-in-string " " "~" (read-preview-buffer)))))
(defun assert-preview (puml output &optional format)
2017-08-27 12:23:37 +02:00
"Run PlantUML on the source PUML and asserts the result to be
equal to OUTPUT. Can choose the output FORMAT (default: utxt)."
2016-12-25 20:30:50 +01:00
(if format
(setq plantuml-output-type format)
(setq plantuml-output-type "utxt"))
2017-08-27 12:51:23 +02:00
(plantuml-preview-string nil (read-test-file puml))
(sleep-for 3)
2017-08-27 12:51:23 +02:00
(assert-preview-content (read-test-file output)))
2017-08-27 12:27:07 +02:00
(defmacro test-and-cleanup-preview (&rest forms)
"Run the test described in FORMS and eventually cleanup the preview buffer."
`(unwind-protect
(progn
2017-08-27 13:02:55 +02:00
(setq-local plantuml-jar-path plantuml-test-jar-path)
2017-08-27 12:27:07 +02:00
,@forms)
(cleanup-preview)))
(ert-deftest preview-utxt-test ()
2017-08-27 12:27:07 +02:00
(test-and-cleanup-preview
2017-08-27 13:02:55 +02:00
(assert-preview "a-b.puml" "a-b.txt")
2017-08-27 12:27:07 +02:00
(assert-preview "unicode.puml" "unicode.txt")))
(provide 'plantuml-mode-preview-test)
;;; plantuml-mode-preview-test.el ends here