Better test docs and cleanup
This commit is contained in:
parent
17fc31d7f8
commit
bb33ce840f
|
@ -246,7 +246,9 @@ to choose where to display it:
|
||||||
- else -> new window"
|
- else -> new window"
|
||||||
(let ((b (get-buffer plantuml-preview-buffer)))
|
(let ((b (get-buffer plantuml-preview-buffer)))
|
||||||
(when b
|
(when b
|
||||||
(kill-buffer b)))
|
(with-current-buffer b
|
||||||
|
(setq buffer-read-only nil)
|
||||||
|
(erase-buffer))))
|
||||||
|
|
||||||
(let* ((imagep (and (display-images-p)
|
(let* ((imagep (and (display-images-p)
|
||||||
(plantuml-is-image-output-p)))
|
(plantuml-is-image-output-p)))
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(defun assert-preview (puml output &optional format)
|
(defun assert-preview (puml output &optional format)
|
||||||
|
"Run PlantUML on the source PUML and asserts the result to be
|
||||||
|
equal to OUTPUT. Can choose the output FORMAT (default: utxt)."
|
||||||
(if format
|
(if format
|
||||||
(setq plantuml-output-type format)
|
(setq plantuml-output-type format)
|
||||||
(setq plantuml-output-type "utxt"))
|
(setq plantuml-output-type "utxt"))
|
||||||
|
@ -18,13 +20,19 @@
|
||||||
(replace-regexp-in-string " " "~" (read-preview-buffer)))))
|
(replace-regexp-in-string " " "~" (read-preview-buffer)))))
|
||||||
|
|
||||||
(ert-deftest preview-utxt-test ()
|
(ert-deftest preview-utxt-test ()
|
||||||
(setq-local plantuml-jar-path plantuml-test-jar-path)
|
(unwind-protect
|
||||||
(assert-preview "a-b.puml" "a-b.txt"))
|
(progn
|
||||||
|
(setq-local plantuml-jar-path plantuml-test-jar-path)
|
||||||
|
(assert-preview "a-b.puml" "a-b.txt"))
|
||||||
|
(cleanup-preview)))
|
||||||
|
|
||||||
(ert-deftest preview-unicode-test ()
|
(ert-deftest preview-unicode-test ()
|
||||||
(setq-local plantuml-jar-path plantuml-test-jar-path)
|
(unwind-protect
|
||||||
(setq-local plantuml-output-type "utxt")
|
(progn
|
||||||
(assert-preview "unicode.puml" "unicode.txt"))
|
(setq-local plantuml-jar-path plantuml-test-jar-path)
|
||||||
|
(setq-local plantuml-output-type "utxt")
|
||||||
|
(assert-preview "unicode.puml" "unicode.txt")))
|
||||||
|
(cleanup-preview))
|
||||||
|
|
||||||
(provide 'plantuml-mode-preview-test)
|
(provide 'plantuml-mode-preview-test)
|
||||||
|
|
||||||
|
|
|
@ -22,17 +22,38 @@
|
||||||
(defvar plantuml-test-jar-path
|
(defvar plantuml-test-jar-path
|
||||||
(f-join package-code-path "bin/plantuml.jar"))
|
(f-join package-code-path "bin/plantuml.jar"))
|
||||||
|
|
||||||
|
(defun test-file-path (path)
|
||||||
|
"Translate the relative test path PATH in an absolute path."
|
||||||
|
(f-join plantuml-test-resources-path path))
|
||||||
|
|
||||||
|
(defun cleanup-preview ()
|
||||||
|
"Kill the preview buffer"
|
||||||
|
(let ((proc (get-buffer-process plantuml-preview-buffer)))
|
||||||
|
(when proc
|
||||||
|
(set-process-query-on-exit-flag proc nil))
|
||||||
|
(kill-buffer plantuml-preview-buffer)))
|
||||||
|
|
||||||
(defun read-buffer (bufname)
|
(defun read-buffer (bufname)
|
||||||
|
"Read the contents of buffer BUFNAME."
|
||||||
(with-current-buffer (get-buffer bufname)
|
(with-current-buffer (get-buffer bufname)
|
||||||
(buffer-string)))
|
(buffer-string)))
|
||||||
|
|
||||||
(defun read-preview-buffer ()
|
(defun read-preview-buffer ()
|
||||||
|
"Read the contents of the PlantUML preview buffer."
|
||||||
(read-buffer plantuml-preview-buffer))
|
(read-buffer plantuml-preview-buffer))
|
||||||
|
|
||||||
(defun read-test-file (path)
|
(defun read-test-file (path)
|
||||||
(f-read (f-join plantuml-test-resources-path path) 'utf-8))
|
"Fetch the string content of the test file at relative path PATH."
|
||||||
|
(f-read (test-file-path path) 'utf-8))
|
||||||
|
|
||||||
|
(defun open-test-file-in-buf (test-file)
|
||||||
|
"Visit TEST-FILE in a new buffer."
|
||||||
|
(message "buffer list before: %s" (buffer-list))
|
||||||
|
(find-file (test-file-path test-file))
|
||||||
|
(message "buffer list after: %s" (buffer-list)))
|
||||||
|
|
||||||
(defun load-plantuml-mode ()
|
(defun load-plantuml-mode ()
|
||||||
|
"Load the plantuml-mode package."
|
||||||
(require 'plantuml-mode (f-expand "plantuml-mode.el" package-code-path)))
|
(require 'plantuml-mode (f-expand "plantuml-mode.el" package-code-path)))
|
||||||
|
|
||||||
(load-plantuml-mode)
|
(load-plantuml-mode)
|
||||||
|
|
Loading…
Reference in New Issue