2016-11-11 10:51:49 +00:00
|
|
|
;;; test-helper.el --- PlantUML Mode test initialization -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
;; Author: Carlo Sciolla (skuro)
|
|
|
|
;; Maintainer: Carlo Sciolla (skuro)
|
|
|
|
;; URL: https://github.com/skuro/plantuml-mode
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'f)
|
|
|
|
|
|
|
|
(defvar package-test-path
|
|
|
|
(f-dirname (f-this-file)))
|
|
|
|
|
|
|
|
(defvar package-code-path
|
|
|
|
(f-parent package-test-path))
|
|
|
|
|
2016-11-11 11:53:41 +00:00
|
|
|
(defvar plantuml-test-resources-path
|
|
|
|
(f-join package-code-path "test/resources"))
|
|
|
|
|
|
|
|
(defvar plantuml-test-jar-path
|
|
|
|
(f-join package-code-path "bin/plantuml.jar"))
|
|
|
|
|
|
|
|
(defun read-buffer (bufname)
|
|
|
|
(with-current-buffer (get-buffer bufname)
|
|
|
|
(buffer-string)))
|
|
|
|
|
|
|
|
(defun read-preview-buffer ()
|
|
|
|
(read-buffer plantuml-preview-buffer))
|
|
|
|
|
|
|
|
(defun read-test-file (path)
|
|
|
|
(f-read (f-join plantuml-test-resources-path path) 'utf-8))
|
|
|
|
|
2017-07-07 19:18:37 +00:00
|
|
|
(defun load-plantuml-mode ()
|
|
|
|
(require 'plantuml-mode (f-expand "plantuml-mode.el" package-code-path)))
|
|
|
|
|
2018-03-18 21:59:22 +00:00
|
|
|
(defun format-preview-output (s)
|
|
|
|
"Make the preview output as S more readable in test output."
|
|
|
|
(concat "\n" s))
|
|
|
|
|
2019-03-16 09:53:17 +00:00
|
|
|
(defun plantuml-test-indent-block (before after)
|
|
|
|
"The common code for the block indentation tests.
|
|
|
|
|
|
|
|
BEFORE is the text block to be inserted into a temporary buffer.
|
|
|
|
AFTER is the expected text block after indentation.
|
|
|
|
|
|
|
|
The temporary buffer will be put into `plantuml-mode'. The whole buffer
|
|
|
|
will be indented with two spaces for each level of indentation.
|
|
|
|
|
|
|
|
Finally, the indented text in the buffer will be compared with AFTER."
|
|
|
|
|
|
|
|
(with-temp-buffer
|
|
|
|
;; fix the JAR location prior to mode initialization
|
|
|
|
;; for some reason, plantuml-mode disregards the setq-local
|
2019-05-31 08:53:40 +00:00
|
|
|
(setq plantuml-jar-path plantuml-test-jar-path)
|
|
|
|
(plantuml-init-once 'jar)
|
2019-03-16 09:53:17 +00:00
|
|
|
|
|
|
|
(insert before)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(plantuml-mode)
|
|
|
|
;; use 2 spaces instead of one tab for indentation
|
2019-05-31 08:53:40 +00:00
|
|
|
(setq indent-tabs-mode nil)
|
|
|
|
(setq tab-width 2)
|
2019-03-16 09:53:17 +00:00
|
|
|
|
|
|
|
(indent-region (point-min) (point-max))
|
|
|
|
(should (equal (buffer-string) after))))
|
|
|
|
|
2018-03-18 18:17:38 +00:00
|
|
|
;; enable code coverage
|
|
|
|
(when (require 'undercover nil t)
|
|
|
|
(undercover "plantuml-mode.el"))
|
|
|
|
|
2017-08-19 19:46:16 +00:00
|
|
|
(load-plantuml-mode)
|
|
|
|
|
2016-11-11 10:51:49 +00:00
|
|
|
;;; test-helper.el ends here
|