Compare commits

...

65 Commits

Author SHA1 Message Date
Carlo Sciolla 5889166b6c
Prepping for v1.4.1 2019-09-03 23:24:56 +02:00
Carlo Sciolla 7a1d7ab1ca
Merge branch 'fix-105' into develop 2019-09-03 23:13:06 +02:00
Carlo Sciolla bea66129a9
Fix note syntax in tests 2019-09-03 23:12:48 +02:00
Carlo Sciolla 4f899a4495
Ensure base64 encoding happens after coding the string with UTF8 (#111)
* Fixes #110

Ensure base64 encoding happens after coding the string with UTF8

* Avoid line breaks in base64 encoding
2019-09-03 23:06:47 +02:00
Carlo Sciolla 252e2c3ce8
Disabling master again 2019-09-03 23:06:47 +02:00
Carlo Sciolla 11b78ff62e
Trying to re-enable builds against Emacs master 2019-09-03 23:06:47 +02:00
Carlo Sciolla 4349011ed7
Aesthitics, just aesthetics 2019-09-03 23:06:46 +02:00
Carlo Sciolla 2954c15322
Fix emacs 26 build 2019-09-03 23:06:46 +02:00
Carlo Sciolla a6545435cd
Bumping java version for CI 2019-09-03 23:06:46 +02:00
Carlo Sciolla 1a11576f4a
Bump version after release 2019-09-03 23:06:45 +02:00
Carlo Sciolla df0d718981
Prepping for the new release 2019-09-03 23:06:45 +02:00
Carlo Sciolla 271f468edd
Bump version 2019-09-03 23:06:45 +02:00
Carlo Sciolla b0be4182fb
Fix tests 2019-09-03 23:06:44 +02:00
Carlo Sciolla 76b14086e8
Ignore java warnings 2019-09-03 23:06:44 +02:00
Carlo Sciolla f04480dcba
Use UTC timezone when setting dates, to align with MELPA 2019-09-03 23:06:44 +02:00
Carlo Sciolla 2bd72f7ae6
Use `car` instead of `first` 2019-09-03 23:06:43 +02:00
Carlo Sciolla 914e0526d9
Avoid zero-padding of hours to mimic MELPA 2019-09-03 23:06:43 +02:00
Carlo Sciolla 60e4d3ec6e
Better version management 2019-09-03 23:06:43 +02:00
Felix Weilbach 7eb6167eb8
Added run mode EXECUTABLE (#102) 2019-09-03 23:06:42 +02:00
Carlo Sciolla 19e268c0cb
Ensure base64 encoding happens after coding the string with UTF8 (#111)
* Fixes #110

Ensure base64 encoding happens after coding the string with UTF8

* Avoid line breaks in base64 encoding
2019-08-30 22:54:26 +02:00
Carlo Sciolla 2f8170b30b
Disabling master again 2019-08-25 11:03:29 +02:00
Carlo Sciolla 14daefbb2f
Trying to re-enable builds against Emacs master 2019-08-25 10:37:51 +02:00
Carlo Sciolla 47156fac58
Aesthitics, just aesthetics 2019-08-22 16:03:53 +02:00
Carlo Sciolla 95428d2e2e
Fix emacs 26 build 2019-08-22 11:31:36 +02:00
Carlo Sciolla b43249e1aa
Bumping java version for CI 2019-08-21 17:20:22 +02:00
Carlo Sciolla 39a109ffe6
Bump version after release 2019-08-21 16:47:52 +02:00
Carlo Sciolla b39c310e9c
Prepping for the new release 2019-08-21 16:42:54 +02:00
Carlo Sciolla f7e3af35e8
Merge branch 'develop' 2019-08-21 16:41:38 +02:00
Carlo Sciolla ae8593d662
Bump version 2019-08-21 14:34:02 +02:00
Carlo Sciolla 36e0abac58
Merge branch 'issue106' into develop 2019-08-21 14:31:52 +02:00
Carlo Sciolla beb4dfc726
Fix tests 2019-08-21 14:27:26 +02:00
Carlo Sciolla 7c1d6d3891
Merge branch 'issue107' into develop 2019-08-21 14:19:54 +02:00
Carlo Sciolla 08b783aee6
Ignore java warnings 2019-08-21 14:18:20 +02:00
Carlo Sciolla 04110d0110
Use UTC timezone when setting dates, to align with MELPA 2019-08-21 12:11:36 +02:00
Carlo Sciolla 5a6ed6c5a2
Use `car` instead of `first` 2019-08-21 11:29:20 +02:00
Carlo Sciolla 4a908c2279
Avoid zero-padding of hours to mimic MELPA 2019-08-21 11:19:37 +02:00
Carlo Sciolla a822c551b8
Better version management 2019-08-21 10:55:50 +02:00
Felix Weilbach 9cba6835fd Added run mode EXECUTABLE (#102) 2019-08-19 14:10:35 +02:00
Michael Steiner cbd7fa4c6b - give user some control to override in comments level of indentation
Signed-off-by: Michael Steiner <michael.steiner@intel.com>
2019-08-12 12:01:26 -07:00
Michael Steiner 80b554e871 - allow for white-space and comments after all begin/end indent regexps
- make end indent regexp symmetrical to being regexp allowing for selective
  change (e.g., disactivation via non-matching regexp) what is leads to
  indentation

Signed-off-by: Michael Steiner <michael.steiner@intel.com>
2019-08-12 12:01:12 -07:00
Michael Steiner c32493229d more robust matching of notes
Signed-off-by: Michael Steiner <michael.steiner@intel.com>
2019-08-12 10:17:50 -07:00
Carlo Sciolla 1e5f8beedd
Fix switching between modes (#104)
Giving a default value to `plantuml-exec-mode` local var at startup time
is wrong. This change keeps the local var to `nil` and resorts to the
customizable `plantuml-default-exec-mode`. The local var can be set by users
at will on a buffer local level, but without such an explicit opt-in then the
default value is always used
2019-08-12 17:40:00 +02:00
Carlo Sciolla d11bd57f31
Removed broken link 2019-08-12 17:14:45 +02:00
Carlo Sciolla 0ae3aed095
Avoid breaking long lines on base64 encoding
Spotted by @alexvs11 as a solution to #101
2019-08-03 16:03:25 +02:00
Carlo Sciolla 648feb5b12
New release 2019-08-03 15:59:00 +02:00
Carlo Sciolla 56bb65342a
Updated changelog 2019-08-03 15:56:41 +02:00
Carlo Sciolla 15ced4ae26
Fix interactive `plantuml-set-exec-mode`
Fixes #97
2019-08-03 15:47:00 +02:00
Carlo Sciolla e9c8e76ff2
Re-enable coverage. Not sure when it actually broke. 2019-05-31 11:39:09 +02:00
Carlo Sciolla 27d48942a6
🆕Multiple run modes, now including JAR and SERVER (#96)
It is now possible to support many execution modes, currently available are:

- `jar`: the traditional way of running PlantUML from `plantuml-mode`
- `server`: ask a [`plantuml-server`](https://github.com/plantuml/plantuml-server) instance to run the preview (defaults to https://www.plantuml.com/plantuml)
2019-05-31 10:53:40 +02:00
Carlo Sciolla 698a248549
Merge branch 'master' into develop 2019-05-10 08:58:43 +02:00
Carlo Sciolla a2617017fd
We actually use dash 2019-05-10 08:57:46 +02:00
Carlo Sciolla b3cfafbf99
Merge branch 'develop' 2019-05-09 22:08:47 +02:00
Carlo Sciolla 8503f9d96a
Fixed relnotes 2019-05-09 22:07:35 +02:00
Carlo Sciolla 8f12855be9
Updated relnote 2019-05-09 22:06:21 +02:00
Carlo Sciolla c14684dc3a
Added capability to automatically download the PlantUML jar path (#95)
* Added capability to automatically download the PlantUML jar path

As an effort to ease the first user setup, a new function is added to download the latest
PlantUML JAR release into `plantuml-jar-path` from Maven central.
2019-05-09 22:04:51 +02:00
Carlo Sciolla 9bd2dc86aa
Added Stale for more prompt reactions and better housekeeping 2019-05-06 15:59:11 +02:00
Carlo Sciolla 689c6a6950
CI downloads plantuml (#94)
Fixes #73

Now the latest version of PlantUML is downloaded as part of the CI script. This has two consequences:

we always test against the latest and greatest PlantUML version.
PlantUML evolves at a much higher pace than plantuml-mode. This allows for some sanity check of our code with the upstream project.

builds are not reproducible
As a side effect of always downloading a (potentially) new PlantUML version, re-running the build for an old commit can lead to different outcomes. This is usually a big no-no but given the limited efforts currently spent on plantuml-mode I find it more convenient to immediately raise a flag if a new version of PlantUML causes issues.
2019-05-06 12:14:25 +02:00
Carlo Sciolla 92c490d3fc
New relnote addition 2019-05-03 17:52:26 +02:00
wailo 56f5cf7276 Improving preview functionality. No buffer switch. (#93)
* Improving preview functionality. No buffer switch.

- Using temp buffer instead of new buffer.
- Windows layout is retained. No need to switch buffer after every preview
2019-05-03 17:50:55 +02:00
Carlo Sciolla 2b84a2df52
Upped version 2019-03-16 12:58:06 +01:00
Carlo Sciolla 0e54f437f6
Added tests for Information Engineering (IE) notation 2019-03-16 12:55:56 +01:00
ReneSchmelzer ef4eecefae Rsch/indentation/multiple start regexs (#88)
* fix version

* split indentation rexgexs

Split the regexs as a preparation for improvement and enhancement.
No explicit enhancement was intended, although the
`plantuml-indent-regexp-block-start' covers more blocks now.

* enhance and test regexs for groups

Changed `plantuml-indent-regexp-group-start' to cover all cases
mentioned on sequence diagram page of the plantuml website. Added
tests for all elements-with and without label (text following the
keyword).

* add support and test for box/end box blocks

* indentation test for a nested interface block

* correction of () at end of file

* indentation test for deployment diagram

* file “Cask”: added dependency to dash

* indentation tests for diagram commons

* add indentation tests for component diagrams

* regex corrections and added indentation tests for class diagrams

correct indentation regexs found by tests for class diagrams

* add indentation tests for object diagrams

* add indentation tests for state diagrams

* enhance indentation class diagram test: abstract class and interface

* move indentation tests to diagram test files

* mv test/plantuml-indentation-test.el -> test/plantuml-indentation-basics-test.el

* add indentation sequence diagram tests and mv basics tests to diagram tests

* add indentation for ref-groups

* improved indentation for ref-groups

* support indentation for activity diagrams - current/old style

* indentation support for notes

* rm not used regexs

* indentation support for plantuml macros

* correction: … → etc.
2019-03-16 10:53:17 +01:00
Carlo Sciolla 366ecb605a
Support block indentation for abstract classes
Fixes #83
2019-01-08 23:06:58 +01:00
Carlo Sciolla de5d9b3dd7
Keep docu for new changes 2019-01-08 22:51:24 +01:00
Carlo Sciolla 56d668c54e
Added extra keywords to the indentation block start regex
Keywords added:
- `folder`
- `frame`
- `cloud`

Fixes #78
2019-01-08 22:47:51 +01:00
25 changed files with 2749 additions and 340 deletions

View File

@ -3,13 +3,18 @@ version: 2.0
# Default actions to perform on each Emacs version
default: &default-steps
steps:
- checkout
- run:
name: Update APT packages
command: apt-get update
- run:
name: Install prerequisites
command: apt-get install -y openjdk-8-jre make python git
command: apt-get install -y openjdk-11-jre make python git
- checkout
- run:
# Note: this makes it hard to reproduce builds but easier to spot incompatibilities with
# newer PlantUML releases. Current trade off seems acceptable.
name: Download the latest PlantUML release
command: sh ./bin/download-plantuml.sh
- run:
name: Install cask
command: curl -fsSL https://raw.githubusercontent.com/cask/cask/master/go | python
@ -30,7 +35,7 @@ jobs:
test-emacs-26:
docker:
- image: silex/emacs:26.0
- image: silex/emacs:26
entrypoint: bash
<<: *default-steps
@ -48,4 +53,4 @@ workflows:
- test-emacs-25
- test-emacs-26
# Testing against master currently hangs on CircleCI
#- test-emacs-master
# - test-emacs-master

17
.github/stale.yml vendored Normal file
View File

@ -0,0 +1,17 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 90
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 10
# Issues with these labels will never be considered stale
exemptLabels:
- help-wanted
- enhancement
# Label to use when marking an issue as stale
staleLabel: wontfix
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false

1
Cask
View File

@ -5,6 +5,7 @@
(development
(depends-on "f")
(depends-on "dash")
(depends-on "ecukes")
(depends-on "ert-runner")
(depends-on "el-mock")

View File

@ -1,14 +1,15 @@
#
# Programs used in the make goals
#
export CASK ?= cask
export CASK ?= cask
export EMACS ?= emacs
#
# General configuration
#
export CASK_DIR ?= `${CASK} package-directory`
export BATCH = --batch -q -l .emacs/init.el
export CASK_DIR ?= `${CASK} package-directory`
export BATCH = --batch -q -l .emacs/init.el
export COVERALLS_REPO_TOKEN = 61YFD7RG1RRJTs0kEuj1aZX7VBgUPiMNO
all: version test

View File

@ -1,6 +1,5 @@
[![MELPA](http://melpa.org/packages/plantuml-mode-badge.svg)](http://melpa.org/#/plantuml-mode) [![MELPA Stable](http://stable.melpa.org/packages/plantuml-mode-badge.svg)](http://stable.melpa.org/#/plantuml-mode) [![CircleCI](https://circleci.com/gh/skuro/plantuml-mode.svg?style=svg)](https://circleci.com/gh/skuro/plantuml-mode) [![Coverage Status](https://coveralls.io/repos/github/skuro/plantuml-mode/badge.svg?branch=HEAD)](https://coveralls.io/github/skuro/plantuml-mode?branch=HEAD)
# PlantUML mode for Emacs
<img src="https://raw.githubusercontent.com/skuro/plantuml-mode/master/banner.png"
@ -26,11 +25,16 @@ Also, to enable preview you need to tell `plantuml-mode` where to locate the Pla
M-x customize-variable<RET>
plantuml-jar-path<RET>
You can also download the latest version of PlantUML straight into `plantuml-jar-path`:
M-x plantuml-download-jar<RET>
# Features
- Syntax highlight
- Autocompletion
- Preview of buffer or region
- [EXPERIMENTAL] Use either local JAR or remote server for preview
# Enable the major mode
@ -84,6 +88,28 @@ Then you can edit a `plantuml` code block with `plantuml-mode` by hitting `C-'`
When in the `plantuml-mode` buffer you can then hit again `C-'` to return to the original `org-mode` document.
# Execution modes
**EXPERIMENTAL**
As of `v1.3.0` support is added for switching execution mode. The following two modes are available:
- `jar` (default) to run PlantUML as a local JAR file. This is the traditional system used by `plantuml-mode`
- `server` (experimental) to let an instance of [`plantuml-server`](https://github.com/plantuml/plantuml-server) render the preview
- `executable` to run PlantUML as a local executable file. This is useful if your package manager provides a executable for PlantUML.
You can customize `plantuml-default-exec-mode` or run `plantuml-set-exec-mode` from a `plantuml-mode` buffer to switch modes.
## Configure server rendering
When selecting `server` execution modes, you can customize the following variable to set the server to use for rendering:
```
plantuml-server-url
```
It defaults to `"https://www.plantuml.com/plantuml"`.
# Migration from `puml-mode`
If you were previously using `puml-mode`, you should change any reference to a `puml-..` variable or function to its `plantuml-..` counterpart. Most notably, `puml-plantuml-jar-path` is now just `plantuml-jar-path`.
@ -112,11 +138,20 @@ the textual mode and see if the output is valid SVG.
## Development
Development happens mostly on the `develop` branch, which is released on MELPA at every commit. The `master` branch is used to generate tags which are then released to [MELPA
stable](https://stable.melpa.org).
In order to contribute to `plantuml-mode` make sure to:
- agree with the [GPLv3+ licencing terms](#License) as they are mandated by Emacs
- install [`cask`](https://github.com/cask/cask)
- always test your code and run the full test suite with `cask exec ert-runner` (or just by `make`)
- ensure you always target `develop` in your pull requests
For collaborators who have merge access to the repo:
- make sure [`set-version.sh`](./blob/develop/bin/set-version.sh) is run as part of your [`pre-commit` git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)
- always merge PRs on the command line
- when releasing a new stable version, add the proper entry in the changelog within `plantuml-mode.el` to ensure the right version is set for `plantuml-mode-version`
# Credits

20
bin/download-plantuml.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/sh
# Where the script is executed
CURRENT_PATH="$(dirname "$(readlink -f "$0")")"
# Where to download the file
OUTPUT_PATH="${CURRENT_PATH}/plantuml.jar"
# Retrieve the list of versions, in XML format, only one result (the latest)
VERSIONS_URL='https://search.maven.org/solrsearch/select?q=g:net.sourceforge.plantuml+AND+a:plantuml&core=gav&start=0&rows=1&wt=xml'
# Only match the contents of the version (name="v") XML tag
LATEST_VERSION="$(curl -s "${VERSIONS_URL}" | grep -oP '(?<=<str name="v">).*(?=</str>)')"
# Compose the download link
DOWNLOAD_URL="https://search.maven.org/remotecontent?filepath=net/sourceforge/plantuml/plantuml/${LATEST_VERSION}/plantuml-${LATEST_VERSION}.jar"
# finally, download the JAR file
echo "Downloading PlantUML v${LATEST_VERSION} into ${OUTPUT_PATH}"
curl -so "${OUTPUT_PATH}" "${DOWNLOAD_URL}" 2>/dev/null

Binary file not shown.

33
bin/set-version.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
# Retrieves the version from the changelog in plantuml-mode.el
function grab_version(){
grep ';; version' plantuml-mode.el | \
head -n1 | \
cut -f3 -d' ' | \
tr -d ','
}
# Updates the version in-place
function update_version(){
NEW_VERSION="${1}"
sed -i -E "s/plantuml-mode-version \"[0-9\.]+\"/plantuml-mode-version \"${1}\"/" plantuml-mode.el
}
case "$(git rev-parse --abbrev-ref HEAD)" in
'master')
VERSION="$(grab_version)"
update_version "${VERSION}"
git add plantuml-mode.el
;;
'develop')
VERSION="$(TZ='UTC' date '+%Y%m%d.%-H%M')" # MELPA style
update_version "${VERSION}"
git add plantuml-mode.el
;;
*)
## do nothing
;;
esac

View File

@ -6,8 +6,9 @@
;; Author: Zhang Weize (zwz)
;; Maintainer: Carlo Sciolla (skuro)
;; Keywords: uml plantuml ascii
;; Version: 1.2.7
;; Package-Requires: ((emacs "25.0"))
;; Version: 1.2.9
;; Package-Version: 1.2.9
;; Package-Requires: ((dash "2.0.0") (emacs "25.0"))
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@ -36,6 +37,13 @@
;;; Change log:
;;
;; version 1.4.1, 2019-09-03 Better indentation; more bugfixing; actually adding `executable' mode
;; version 1.4.0, 2019-08-21 Added `executable' exec mode to use locally installed `plantuml' binaries, various bugfixes
;; version 1.3.1, 2019-08-02 Fixed interactive behavior of `plantuml-set-exec-mode'
;; version 1.3.0, 2019-05-31 Added experimental support for multiple rendering modes and, specifically, preview using a PlantUML server
;; version 1.2.11, 2019-04-09 Added `plantuml-download-jar'
;; version 1.2.10, 2019-04-03 Avoid messing with window layouts and buffers -- courtesy of https://github.com/wailo
;; version 1.2.9, Revamped indentation support, now working with a greater number of keywords
;; version 1.2.8, 2019-01-07 Support indentation for activate / deactivate blocks; allow customization of `plantuml-java-args'
;; version 1.2.7, 2018-08-15 Added support for indentation; Fixed the comiling error when installing with melpa
;; version 1.2.6, 2018-07-17 Introduced custom variable `plantuml-jar-args' to control which arguments are passed to PlantUML jar. Fix the warning of failing to specify types of 'defcustom' variables
@ -65,6 +73,8 @@
;;; Code:
(require 'thingatpt)
(require 'dash)
(require 'xml)
(defgroup plantuml-mode nil
"Major mode for editing plantuml file."
@ -76,9 +86,15 @@
:type 'string
:group 'plantuml)
(defcustom plantuml-executable-path
"plantuml"
"The location of the PlantUML executable."
:type 'string
:group 'plantuml)
(defvar plantuml-mode-hook nil "Standard hook for plantuml-mode.")
(defconst plantuml-mode-version "1.2.7" "The plantuml-mode version string.")
(defconst plantuml-mode-version "1.4.1" "The plantuml-mode version string.")
(defvar plantuml-mode-debug-enabled nil)
@ -95,7 +111,7 @@
:type 'string
:group 'plantuml)
(defcustom plantuml-java-args (list "-Djava.awt.headless=true" "-jar")
(defcustom plantuml-java-args (list "-Djava.awt.headless=true" "-jar" "--illegal-access=deny")
"The parameters passed to `plantuml-java-command' when executing PlantUML."
:type '(repeat string)
:group 'plantuml)
@ -105,12 +121,29 @@
:type '(repeat string)
:group 'plantuml)
(defcustom plantuml-server-url "https://www.plantuml.com/plantuml"
"The base URL of the PlantUML server."
:type 'string
:group 'plantuml)
(defcustom plantuml-executable-args (list "-headless")
"The parameters passed to plantuml executable when executing PlantUML."
:type '(repeat string)
:group 'plantuml)
(defcustom plantuml-default-exec-mode 'server
"Default execution mode for PlantUML. Valid values are:
- `jar': run PlantUML as a JAR file (requires a local install of the PlantUML JAR file, see `plantuml-jar-path'"
:type 'symbol
:group 'plantuml
:options '(jar server executable))
(defcustom plantuml-suppress-deprecation-warning t
"To silence the deprecation warning when `puml-mode' is found upon loading."
:type 'boolean
:group 'plantuml)
(defun plantuml-render-command (&rest arguments)
(defun plantuml-jar-render-command (&rest arguments)
"Create a command line to execute PlantUML with arguments (as ARGUMENTS)."
(let* ((cmd-list (append plantuml-java-args (list (expand-file-name plantuml-jar-path)) plantuml-jar-args arguments))
(cmd (mapconcat 'identity cmd-list "|")))
@ -138,6 +171,30 @@
;; keyword completion
(defvar plantuml-kwdList nil "The plantuml keywords.")
;; PlantUML execution mode
(defvar-local plantuml-exec-mode nil
"The Plantuml execution mode override. See `plantuml-default-exec-mode' for acceptable values.")
(defun plantuml-set-exec-mode (mode)
"Set the execution mode MODE for PlantUML."
(interactive (let* ((completion-ignore-case t)
(supported-modes '("jar" "server" "executable")))
(list (completing-read (format "Exec mode [%s]: " plantuml-exec-mode)
supported-modes
nil
t
nil
nil
plantuml-exec-mode))))
(if (member mode '("jar" "server" "executable"))
(setq plantuml-exec-mode (intern mode))
(error (concat "Unsupported mode:" mode))))
(defun plantuml-get-exec-mode ()
"Retrieves the currently active PlantUML exec mode."
(or plantuml-exec-mode
plantuml-default-exec-mode))
(defun plantuml-enable-debug ()
"Enables debug messages into the *PLANTUML Messages* buffer."
(interactive)
@ -159,15 +216,68 @@
(insert msg)
(insert "\n"))))))
(defun plantuml-init ()
"Initialize the keywords or builtins from the cmdline language output."
(defun plantuml-download-jar ()
"Download the latest PlantUML JAR file and install it into `plantuml-jar-path'."
(interactive)
(if (y-or-n-p (format "Download the latest PlantUML JAR file into %s? " plantuml-jar-path))
(if (or (not (file-exists-p plantuml-jar-path))
(y-or-n-p (format "The PlantUML jar file already exists at %s, overwrite? " plantuml-jar-path)))
(with-current-buffer (url-retrieve-synchronously "https://search.maven.org/solrsearch/select?q=g:net.sourceforge.plantuml+AND+a:plantuml&core=gav&start=0&rows=1&wt=xml")
(mkdir (file-name-directory plantuml-jar-path) t)
(let* ((parse-tree (xml-parse-region))
(doc (->> parse-tree
(assq 'response)
(assq 'result)
(assq 'doc)))
(strs (xml-get-children doc 'str))
(version (->> strs
(--filter (string-equal "v" (xml-get-attribute it 'name)))
(car)
(xml-node-children)
(car))))
(message (concat "Downloading PlantUML v" version " into " plantuml-jar-path))
(url-copy-file (format "https://search.maven.org/remotecontent?filepath=net/sourceforge/plantuml/plantuml/%s/plantuml-%s.jar" version version) plantuml-jar-path t)
(kill-buffer)))
(message "Aborted."))
(message "Aborted.")))
(defun plantuml-jar-get-language (buf)
"Retrieve the language specification from the PlantUML JAR file and paste it into BUF."
(unless (or (eq system-type 'cygwin) (file-exists-p plantuml-jar-path))
(error "Could not find plantuml.jar at %s" plantuml-jar-path))
(with-temp-buffer
(with-current-buffer buf
(let ((cmd-args (append (list plantuml-java-command nil t nil)
(plantuml-render-command "-language"))))
(plantuml-jar-render-command "-language"))))
(apply 'call-process cmd-args)
(goto-char (point-min)))
(goto-char (point-min)))))
(defun plantuml-server-get-language (buf)
"Retrieve the language specification from the PlantUML server and paste it into BUF."
(let ((lang-url (concat plantuml-server-url "/language")))
(with-current-buffer buf
(url-insert-file-contents lang-url))))
(defun plantuml-executable-get-language (buf)
"Retrieve the language specification from the PlantUML executable and paste it into BUF."
(with-current-buffer buf
(let ((cmd-args (append (list plantuml-executable-path nil t nil) (list "-language"))))
(apply 'call-process cmd-args)
(goto-char (point-min)))))
(defun plantuml-get-language (mode buf)
"Retrieve the language spec using the preferred PlantUML execution mode MODE. Paste the result into BUF."
(let ((get-fn (pcase mode
('jar #'plantuml-jar-get-language)
('server #'plantuml-server-get-language)
('executable #'plantuml-executable-get-language))))
(if get-fn
(funcall get-fn buf)
(error "Unsupported execution mode %s" mode))))
(defun plantuml-init (mode)
"Initialize the keywords or builtins from the cmdline language output. Use exec mode MODE to load the language details."
(with-temp-buffer
(plantuml-get-language mode (current-buffer))
(let ((found (search-forward ";" nil t))
(word "")
(count 0)
@ -205,10 +315,10 @@
(defvar plantuml-output-type
(if (not (display-images-p))
"utxt"
"txt"
(cond ((image-type-available-p 'svg) "svg")
((image-type-available-p 'png) "png")
(t "utxt")))
(t "txt")))
"Specify the desired output type to use for generated diagrams.")
(defun plantuml-read-output-type ()
@ -218,7 +328,7 @@
(append
(and (image-type-available-p 'svg) '("svg"))
(and (image-type-available-p 'png) '("png"))
'("utxt"))))
'("txt"))))
(completing-read (format "Output type [%s]: " plantuml-output-type)
available-types
nil
@ -236,56 +346,137 @@ default output type for new buffers."
(setq plantuml-output-type type))
(defun plantuml-is-image-output-p ()
"Return true if the diagram output format is an image, false if it's text based."
(not (equal "utxt" plantuml-output-type)))
"Return non-nil if the diagram output format is an image, false if it's text based."
(not (equal "txt" plantuml-output-type)))
(defun plantuml-output-type-opt ()
"Create the flag to pass to PlantUML to produce the selected output format."
(concat "-t" plantuml-output-type))
(defun plantuml-jar-output-type-opt (output-type)
"Create the flag to pass to PlantUML according to OUTPUT-TYPE.
Note that output type `txt' is promoted to `utxt' for better rendering."
(concat "-t" (pcase output-type
("txt" "utxt")
(_ output-type))))
(defun plantuml-start-process (buf)
(defun plantuml-jar-start-process (buf)
"Run PlantUML as an Emacs process and puts the output into the given buffer (as BUF)."
(apply #'start-process
"PLANTUML" buf plantuml-java-command
`(,@plantuml-java-args
,(expand-file-name plantuml-jar-path)
,(plantuml-output-type-opt)
,(plantuml-jar-output-type-opt plantuml-output-type)
,@plantuml-jar-args
"-p")))
(defun plantuml-preview-string (prefix string)
"Preview diagram from PlantUML sources (as STRING), using prefix (as PREFIX)
to choose where to display it:
(defun plantuml-executable-start-process (buf)
"Run PlantUML as an Emacs process and puts the output into the given buffer (as BUF)."
(apply #'start-process
"PLANTUML" buf plantuml-executable-path
`(,@plantuml-executable-args
,(plantuml-jar-output-type-opt plantuml-output-type)
"-p")))
(defun plantuml-update-preview-buffer (prefix buf)
"Show the preview in the preview buffer BUF.
Window is selected according to PREFIX:
- 4 (when prefixing the command with C-u) -> new window
- 16 (when prefixing the command with C-u C-u) -> new frame.
- else -> new buffer"
(let ((imagep (and (display-images-p)
(plantuml-is-image-output-p))))
(cond
((= prefix 16) (switch-to-buffer-other-frame buf))
((= prefix 4) (switch-to-buffer-other-window buf))
(t (display-buffer buf)))
(when imagep
(with-current-buffer buf
(image-mode)
(set-buffer-multibyte t)))))
(defun plantuml-jar-preview-string (prefix string buf)
"Preview the diagram from STRING by running the PlantUML JAR.
Put the result into buffer BUF. Window is selected according to PREFIX:
- 4 (when prefixing the command with C-u) -> new window
- 16 (when prefixing the command with C-u C-u) -> new frame.
- else -> new buffer"
(let* ((process-connection-type nil)
(ps (plantuml-jar-start-process buf)))
(process-send-string ps string)
(process-send-eof ps)
(set-process-sentinel ps
(lambda (_ps event)
(unless (equal event "finished\n")
(error "PLANTUML Preview failed: %s" event))
(plantuml-update-preview-buffer prefix buf)))))
(defun plantuml-server-encode-url (string)
"Encode the string STRING into a URL suitable for PlantUML server interactions."
(let* ((coding-system (or buffer-file-coding-system
"utf8"))
(encoded-string (base64-encode-string (encode-coding-string string coding-system) t)))
(concat plantuml-server-url "/" plantuml-output-type "/-base64-" encoded-string)))
(defun plantuml-server-preview-string (prefix string buf)
"Preview the diagram from STRING as rendered by the PlantUML server.
Put the result into buffer BUF and place it according to PREFIX:
- 4 (when prefixing the command with C-u) -> new window
- 16 (when prefixing the command with C-u C-u) -> new frame.
- else -> new buffer"
(let* ((url-request-location (plantuml-server-encode-url string)))
(save-current-buffer
(save-match-data
(url-retrieve url-request-location
(lambda (status)
;; TODO: error check
(goto-char (point-min))
;; skip the HTTP headers
(while (not (looking-at "\n"))
(forward-line))
(kill-region (point-min) (+ 1 (point)))
(copy-to-buffer buf (point-min) (point-max))
(plantuml-update-preview-buffer prefix buf)))))))
(defun plantuml-executable-preview-string (prefix string buf)
"Preview the diagram from STRING by running the PlantUML JAR.
Put the result into buffer BUF. Window is selected according to PREFIX:
- 4 (when prefixing the command with C-u) -> new window
- 16 (when prefixing the command with C-u C-u) -> new frame.
- else -> new buffer"
(let* ((process-connection-type nil)
(ps (plantuml-executable-start-process buf)))
(process-send-string ps string)
(process-send-eof ps)
(set-process-sentinel ps
(lambda (_ps event)
(unless (equal event "finished\n")
(error "PLANTUML Preview failed: %s" event))
(plantuml-update-preview-buffer prefix buf)))))
(defun plantuml-exec-mode-preview-string (prefix mode string buf)
"Preview the diagram from STRING using the execution mode MODE.
Put the result into buffer BUF, selecting the window according to PREFIX:
- 4 (when prefixing the command with C-u) -> new window
- 16 (when prefixing the command with C-u C-u) -> new frame.
- else -> new buffer"
(let ((preview-fn (pcase mode
('jar #'plantuml-jar-preview-string)
('server #'plantuml-server-preview-string)
('executable #'plantuml-executable-preview-string))))
(if preview-fn
(funcall preview-fn prefix string buf)
(error "Unsupported execution mode %s" mode))))
(defun plantuml-preview-string (prefix string)
"Preview diagram from PlantUML sources (as STRING), using prefix (as PREFIX)
to choose where to display it."
(let ((b (get-buffer plantuml-preview-buffer)))
(when b
(kill-buffer b)))
(let* ((imagep (and (display-images-p)
(plantuml-is-image-output-p)))
(process-connection-type nil)
(buf (get-buffer-create plantuml-preview-buffer))
(coding-system-for-read (and imagep 'binary))
(coding-system-for-write (and imagep 'binary)))
(let ((ps (plantuml-start-process buf)))
(process-send-string ps string)
(process-send-eof ps)
(set-process-sentinel ps
(lambda (_ps event)
(unless (equal event "finished\n")
(error "PLANTUML Preview failed: %s" event))
(cond
((= prefix 16)
(switch-to-buffer-other-frame plantuml-preview-buffer))
((= prefix 4)
(switch-to-buffer-other-window plantuml-preview-buffer))
(t (switch-to-buffer plantuml-preview-buffer)))
(when imagep
(image-mode)
(set-buffer-multibyte t)))))))
(plantuml-exec-mode-preview-string prefix (plantuml-get-exec-mode) string buf)))
(defun plantuml-preview-buffer (prefix)
"Preview diagram from the PlantUML sources in the current buffer.
@ -333,42 +524,121 @@ Uses prefix (as PREFIX) to choose where to display it:
(plantuml-preview-region prefix (region-beginning) (region-end))
(plantuml-preview-buffer prefix)))
(defun plantuml-init-once ()
"Ensure initialization only happens once."
(unless plantuml-kwdList
(plantuml-init)
(defvar plantuml-types-regexp (concat "^\\s *\\(" (regexp-opt plantuml-types 'words) "\\|\\<\\(note\\s +over\\|note\\s +\\(left\\|right\\|bottom\\|top\\)\\s +\\(of\\)?\\)\\>\\|\\<\\(\\(left\\|center\\|right\\)\\s +\\(header\\|footer\\)\\)\\>\\)"))
(defvar plantuml-keywords-regexp (concat "^\\s *" (regexp-opt plantuml-keywords 'words) "\\|\\(<\\|<|\\|\\*\\|o\\)\\(\\.+\\|-+\\)\\|\\(\\.+\\|-+\\)\\(>\\||>\\|\\*\\|o\\)\\|\\.\\{2,\\}\\|-\\{2,\\}"))
(defvar plantuml-builtins-regexp (regexp-opt plantuml-builtins 'words))
(defvar plantuml-preprocessors-regexp (concat "^\\s *" (regexp-opt plantuml-preprocessors 'words)))
(defvar plantuml-indent-regexp-start "^[ \t]*\\(\\(?:.*\\)?\s*\\(?:[<>.*a-z-|]+\\)?\s*\\(?:\\[[a-zA-Z]+\\]\\)?\s+if\s+.*\\|loop\s+.*\\|group\s+.*\\|par\s*$\\|opt\s+.*\\|alt\s+.*\\|else\\|note\s+over\\|note\sas\s.*\\|note\s+\\(\\(?:\\(?:buttom\\|left\\|right\\|top\\)\\)\\)\\(?:\s+of\\)?\\|\\(?:class\\|enum\\|package\\|database\\)\s+.*{\\|activate\s+.+\\)")
(defvar plantuml-indent-regexp-end "^[ \t]*\\(endif\\|else\\|end\\|end\s+note\\|.*}\\|deactivate\s+.+\\)")
(defun plantuml-init-once (&optional mode)
"Ensure initialization only happens once. Use exec mode MODE to load the language details or by first querying `plantuml-get-exec-mode'."
(let ((mode (or mode (plantuml-get-exec-mode))))
(unless plantuml-kwdList
(plantuml-init mode)
(defvar plantuml-types-regexp (concat "^\\s *\\(" (regexp-opt plantuml-types 'words) "\\|\\<\\(note\\s +over\\|note\\s +\\(left\\|right\\|bottom\\|top\\)\\s +\\(of\\)?\\)\\>\\|\\<\\(\\(left\\|center\\|right\\)\\s +\\(header\\|footer\\)\\)\\>\\)"))
(defvar plantuml-keywords-regexp (concat "^\\s *" (regexp-opt plantuml-keywords 'words) "\\|\\(<\\|<|\\|\\*\\|o\\)\\(\\.+\\|-+\\)\\|\\(\\.+\\|-+\\)\\(>\\||>\\|\\*\\|o\\)\\|\\.\\{2,\\}\\|-\\{2,\\}"))
(defvar plantuml-builtins-regexp (regexp-opt plantuml-builtins 'words))
(defvar plantuml-preprocessors-regexp (concat "^\\s *" (regexp-opt plantuml-preprocessors 'words)))
(setq plantuml-font-lock-keywords
`(
(,plantuml-types-regexp . font-lock-type-face)
(,plantuml-keywords-regexp . font-lock-keyword-face)
(,plantuml-builtins-regexp . font-lock-builtin-face)
(,plantuml-preprocessors-regexp . font-lock-preprocessor-face)
;; note: order matters
))
;; Below are the regexp's for indentation.
;; Notes:
;; - there is some control on what it is indented by overriding some of below
;; X-start and X-end regexp before plantuml-mode is loaded. E.g., to disable
;; indentation on activate, you might define in your .emacs something like
;; (setq plantuml-indent-regexp-activate-start
;; "NEVER MATCH THIS EXPRESSION"); define _before_ load plantuml-mode!
;; (setq plantuml-indent-regexp-activate-end
;; "NEVER MATCH THIS EXPRESSION"); define _before_ load plantuml-mode!
;; - due to the nature of using (context-insensitive) regexp, indentation have
;; following limitations
;; - commands commented out by /' ... '/ will _not_ be ignored
;; and potentially lead to miss-indentation
;; - you can though somewhat correct mis-indentation by adding in '-comment lines
;; PLANTUML_MODE_INDENT_INCREASE and/or PLANTUML_MODE_INDENT_DECREASE
;; to increase and/or decrease the level of indentation
;; (Note: the line with the comment should not contain any text matching other indent
;; regexp or this user-control instruction will be ignored; also at most will count
;; per line ...)
(defvar plantuml-indent-regexp-block-start "^.*{\s*$"
"Indentation regex for all plantuml elements that might define a {} block.
Plantuml elements like skinparam, rectangle, sprite, package, etc.
The opening { has to be the last visible character in the line (whitespace
might follow).")
(defvar plantuml-indent-regexp-note-start "^\s*\\(floating\s+\\)?[hr]?note\s+\\(right\\|left\\|top\\|bottom\\|over\\)[^:]*?$" "simplyfied regex; note syntax is especially inconsistent across diagrams")
(defvar plantuml-indent-regexp-group-start "^\s*\\(alt\\|else\\|opt\\|loop\\|par\\|break\\|critical\\|group\\)\\(?:\s+.+\\|$\\)"
"Indentation regex for plantuml group elements that are defined for sequence diagrams.
Two variants for groups: keyword is either followed by whitespace and some text
or it is followed by line end.")
(defvar plantuml-indent-regexp-activate-start "^\s*activate\s+.+$")
(defvar plantuml-indent-regexp-box-start "^\s*box\s+.+$")
(defvar plantuml-indent-regexp-ref-start "^\s*ref\s+over\s+[^:]+?$")
(defvar plantuml-indent-regexp-title-start "^\s*title\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-header-start "^\s*\\(?:\\(?:center\\|left\\|right\\)\s+header\\|header\\)\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-footer-start "^\s*\\(?:\\(?:center\\|left\\|right\\)\s+footer\\|footer\\)\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-legend-start "^\s*\\(?:legend\\|legend\s+\\(?:bottom\\|top\\)\\|legend\s+\\(?:center\\|left\\|right\\)\\|legend\s+\\(?:bottom\\|top\\)\s+\\(?:center\\|left\\|right\\)\\)\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-oldif-start "^.*if\s+\".*\"\s+then\s*\\('.*\\)?$" "used in current activity diagram, sometimes already mentioned as deprecated")
(defvar plantuml-indent-regexp-macro-start "^\s*!definelong.*$")
(defvar plantuml-indent-regexp-user-control-start "^.*'.*\s*PLANTUML_MODE_INDENT_INCREASE\s*.*$")
(defvar plantuml-indent-regexp-start (list plantuml-indent-regexp-block-start
plantuml-indent-regexp-group-start
plantuml-indent-regexp-activate-start
plantuml-indent-regexp-box-start
plantuml-indent-regexp-ref-start
plantuml-indent-regexp-legend-start
plantuml-indent-regexp-note-start
plantuml-indent-regexp-oldif-start
plantuml-indent-regexp-title-start
plantuml-indent-regexp-header-start
plantuml-indent-regexp-footer-start
plantuml-indent-regexp-macro-start
plantuml-indent-regexp-oldif-start
plantuml-indent-regexp-user-control-start))
(defvar plantuml-indent-regexp-block-end "^\s*\\(?:}\\|endif\\|else\s*.*\\|end\\)\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-note-end "^\s*\\(end\s+note\\|end[rh]note\\)\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-group-end "^\s*end\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-activate-end "^\s*deactivate\s+.+$")
(defvar plantuml-indent-regexp-box-end "^\s*end\s+box\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-ref-end "^\s*end\s+ref\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-title-end "^\s*end\s+title\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-header-end "^\s*endheader\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-footer-end "^\s*endfooter\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-legend-end "^\s*endlegend\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-oldif-end "^\s*\\(endif\\|else\\)\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-macro-end "^\s*!enddefinelong\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-user-control-end "^.*'.*\s*PLANTUML_MODE_INDENT_DECREASE\s*.*$")
(defvar plantuml-indent-regexp-end (list plantuml-indent-regexp-block-end
plantuml-indent-regexp-group-end
plantuml-indent-regexp-activate-end
plantuml-indent-regexp-box-end
plantuml-indent-regexp-ref-end
plantuml-indent-regexp-legend-end
plantuml-indent-regexp-note-end
plantuml-indent-regexp-oldif-end
plantuml-indent-regexp-title-end
plantuml-indent-regexp-header-end
plantuml-indent-regexp-footer-end
plantuml-indent-regexp-macro-end
plantuml-indent-regexp-oldif-end
plantuml-indent-regexp-user-control-end))
(setq plantuml-font-lock-keywords
`(
(,plantuml-types-regexp . font-lock-type-face)
(,plantuml-keywords-regexp . font-lock-keyword-face)
(,plantuml-builtins-regexp . font-lock-builtin-face)
(,plantuml-preprocessors-regexp . font-lock-preprocessor-face)
;; note: order matters
))
(setq plantuml-kwdList (make-hash-table :test 'equal))
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-types)
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-keywords)
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-builtins)
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-preprocessors)
(put 'plantuml-kwdList 'risky-local-variable t)
(setq plantuml-kwdList (make-hash-table :test 'equal))
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-types)
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-keywords)
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-builtins)
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-preprocessors)
(put 'plantuml-kwdList 'risky-local-variable t)
;; clear memory
(setq plantuml-types nil)
(setq plantuml-keywords nil)
(setq plantuml-builtins nil)
(setq plantuml-preprocessors nil)
(setq plantuml-types-regexp nil)
(setq plantuml-keywords-regexp nil)
(setq plantuml-builtins-regexp nil)
(setq plantuml-preprocessors-regexp nil)))
;; clear memory
(setq plantuml-types nil)
(setq plantuml-keywords nil)
(setq plantuml-builtins nil)
(setq plantuml-preprocessors nil)
(setq plantuml-types-regexp nil)
(setq plantuml-keywords-regexp nil)
(setq plantuml-builtins-regexp nil)
(setq plantuml-preprocessors-regexp nil))))
(defun plantuml-complete-symbol ()
"Perform keyword completion on word before cursor."
@ -399,22 +669,19 @@ Uses prefix (as PREFIX) to choose where to display it:
(defun plantuml-current-block-depth ()
"Trace the current block indentation level by recursively looking back line by line."
;; forward declare the lazy initialized constants
(defvar plantuml-indent-regexp-start)
(defvar plantuml-indent-regexp-end)
(save-excursion
(let ((relative-depth 0))
;; current line
(beginning-of-line)
(if (looking-at plantuml-indent-regexp-end)
(if (-any? 'looking-at plantuml-indent-regexp-end)
(setq relative-depth (1- relative-depth)))
;; from current line backwards to beginning of buffer
(while (not (bobp))
(forward-line -1)
(if (looking-at plantuml-indent-regexp-end)
(if (-any? 'looking-at plantuml-indent-regexp-end)
(setq relative-depth (1- relative-depth)))
(if (looking-at plantuml-indent-regexp-start)
(if (-any? 'looking-at plantuml-indent-regexp-start)
(setq relative-depth (1+ relative-depth))))
(if (<= relative-depth 0)
@ -425,9 +692,6 @@ Uses prefix (as PREFIX) to choose where to display it:
"Indent the current line to its desired indentation level.
Restore point to same position in text of the line as before indentation."
(interactive)
;; forward declare the lazy initialized constants
(defvar plantuml-indent-regexp-start)
(defvar plantuml-indent-regexp-end)
;; store position of point in line measured from end of line
(let ((original-position-eol (- (line-end-position) (point))))
(save-excursion
@ -462,8 +726,8 @@ Shortcuts Command Name
(if (and plantuml-suppress-deprecation-warning
(featurep 'puml-mode))
(display-warning :warning
"`puml-mode' is now deprecated and no longer updated, but it's still present in your system.\
You should move your configuration to use `plantuml-mode'. See https://github.com/sytac/plantuml-mode. \
"`puml-mode' is now deprecated and no longer updated, but it's still present in your system. \
You should move your configuration to use `plantuml-mode'. \
See more at https://github.com/skuro/puml-mode/issues/26")))
(add-hook 'plantuml-mode-hook 'plantuml-deprecation-warning)

View File

@ -0,0 +1,34 @@
;;; plantuml-config-test.el --- tests for plantuml-mode configuration knobs -*- lexical-binding: t; -*-
;; Author: Carlo Sciolla
;; Maintainer: Carlo Sciolla
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;; Test user-accessible configuration knobs
;;; Code:
(require 'plantuml-mode)
(ert-deftest plantuml-config-test/set-exec-mode-happy-path ()
"Test switching execution modes"
(let ((orig-mode plantuml-exec-mode))
;; happy flows:
(plantuml-set-exec-mode "server")
(should (equal 'server plantuml-exec-mode))
(plantuml-set-exec-mode "jar")
(should (equal 'jar plantuml-exec-mode))
(plantuml-set-exec-mode "executable")
(should (equal 'executable plantuml-exec-mode))
(setq plantuml-exec-mode orig-mode)))
(ert-deftest plantuml-config-test/set-exec-mode-wrong-mode ()
"Test setting the exec mode with the wrong text"
(should-error (plantuml-set-exec-mode "turing-machine")))
(provide 'plantuml-mode-config-test)
;;; plantuml-config-test.el ends here

View File

@ -0,0 +1,281 @@
;;; plantuml-indentation-activity-old-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;; Author: René Schmelzer
;; Maintainer: Carlo Sciolla (skuro)
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;; Test indentation for activity (old version) diagrams.
;;; Code:
(ert-deftest plantuml-test-indentation/activity-old-diagram/branches ()
"Test correct indentation of plantuml activity-old diagram elements: branches.
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"
if \"Some Test\" then
-->[true] \"Some Activity\"
--> \"Another activity\"
-right-> (*)
else
->[false] \"Something else\"
-->[Ending process] (*)
endif
(*) --> \"check input\"
If \"input is verbose\" then
--> [Yes] \"turn on verbosity\"
--> \"run command\"
else
--> \"run command\"
Endif
-->(*)
"
"
if \"Some Test\" then
-->[true] \"Some Activity\"
--> \"Another activity\"
-right-> (*)
else
->[false] \"Something else\"
-->[Ending process] (*)
endif
(*) --> \"check input\"
If \"input is verbose\" then
--> [Yes] \"turn on verbosity\"
--> \"run command\"
else
--> \"run command\"
Endif
-->(*)
"
))
(ert-deftest plantuml-test-indentation/activity-old-diagram/more-on-branches ()
"Test correct indentation of plantuml activity-old diagram elements: more on branches.
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"
(*) --> if \"Some Test\" then
-->[true] \"activity 1\"
if \"\" then
-> \"activity 3\" as a3
else
if \"Other test\" then
-left-> \"activity 5\"
else
--> \"activity 6\"
endif
endif
else
->[false] \"activity 2\"
endif
a3 --> if \"last test\" then
--> \"activity 7\"
else
-> \"activity 8\"
endif
"
"
(*) --> if \"Some Test\" then
-->[true] \"activity 1\"
if \"\" then
-> \"activity 3\" as a3
else
if \"Other test\" then
-left-> \"activity 5\"
else
--> \"activity 6\"
endif
endif
else
->[false] \"activity 2\"
endif
a3 --> if \"last test\" then
--> \"activity 7\"
else
-> \"activity 8\"
endif
"
))
(ert-deftest plantuml-test-indentation/activity-old-diagram/partitions ()
"Test correct indentation of plantuml activity-old diagram elements: partitions.
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"
partition Conductor {
(*) --> \"Climbs on Platform\"
--> === S1 ===
--> Bows
}
partition Audience #LightSkyBlue {
=== S1 === --> Applauds
}
partition Conductor {
Bows --> === S2 ===
--> WavesArmes
Applauds --> === S2 ===
}
partition Orchestra #CCCCEE {
WavesArmes --> Introduction
--> \"Play music\"
}
"
"
partition Conductor {
(*) --> \"Climbs on Platform\"
--> === S1 ===
--> Bows
}
partition Audience #LightSkyBlue {
=== S1 === --> Applauds
}
partition Conductor {
Bows --> === S2 ===
--> WavesArmes
Applauds --> === S2 ===
}
partition Orchestra #CCCCEE {
WavesArmes --> Introduction
--> \"Play music\"
}
"))
(ert-deftest plantuml-test-indentation/activity-old-diagram/complete-example ()
"Test correct indentation of plantuml activity-old diagram elements: complete example.
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"
title Servlet Container
(*) --> \"ClickServlet.handleRequest()\"
--> \"new Page\"
if \"Page.onSecurityCheck\" then
->[true] \"Page.onInit()\"
if \"isForward?\" then
->[no] \"Process controls\"
if \"continue processing?\" then
-->[yes] ===RENDERING===
else
-->[no] ===REDIRECT_CHECK===
endif
else
-->[yes] ===RENDERING===
endif
if \"is Post?\" then
-->[yes] \"Page.onPost()\"
--> \"Page.onRender()\" as render
--> ===REDIRECT_CHECK===
else
-->[no] \"Page.onGet()\"
--> render
endif
else
-->[false] ===REDIRECT_CHECK===
endif
if \"Do redirect?\" then
->[yes] \"redirect request\"
--> ==BEFORE_DESTROY===
else
if \"Do Forward?\" then
-left->[yes] \"Forward request\"
--> ==BEFORE_DESTROY===
else
-right->[no] \"Render page template\"
--> ==BEFORE_DESTROY===
endif
endif
--> \"Page.onDestroy()\"
-->(*)
"
"
title Servlet Container
(*) --> \"ClickServlet.handleRequest()\"
--> \"new Page\"
if \"Page.onSecurityCheck\" then
->[true] \"Page.onInit()\"
if \"isForward?\" then
->[no] \"Process controls\"
if \"continue processing?\" then
-->[yes] ===RENDERING===
else
-->[no] ===REDIRECT_CHECK===
endif
else
-->[yes] ===RENDERING===
endif
if \"is Post?\" then
-->[yes] \"Page.onPost()\"
--> \"Page.onRender()\" as render
--> ===REDIRECT_CHECK===
else
-->[no] \"Page.onGet()\"
--> render
endif
else
-->[false] ===REDIRECT_CHECK===
endif
if \"Do redirect?\" then
->[yes] \"redirect request\"
--> ==BEFORE_DESTROY===
else
if \"Do Forward?\" then
-left->[yes] \"Forward request\"
--> ==BEFORE_DESTROY===
else
-right->[no] \"Render page template\"
--> ==BEFORE_DESTROY===
endif
endif
--> \"Page.onDestroy()\"
-->(*)
"
))
(provide 'plantuml-indentation-activity-old-test)
;;; plantuml-indentation-activity-old-test.el ends here

View File

@ -1,4 +1,4 @@
;;; plantuml-indentation-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;;; plantuml-indentation-basics-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;; Author: Raymond Huang (rymndhng)
;; Maintainer: Carlo Sciolla (skuro)
@ -6,6 +6,8 @@
;;; Commentary:
;; Test basics like single correct indentation depth etc. Focus is not on diagram contents
;; and context; such things are tested in the diagram specific indentation tests.
;; Test setup is inspired/taken from clojure-mode-indentation-tests
;;; Code:
@ -255,243 +257,7 @@ foofoo|"
foofoo|"))
(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.
(provide 'plantuml-indentation-basics-test)
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
(setq-local plantuml-jar-path plantuml-test-jar-path)
(plantuml-init-once)
(insert before)
(goto-char (point-min))
(plantuml-mode)
;; use 2 spaces instead of one tab for indentation
(setq-local indent-tabs-mode nil)
(setq-local tab-width 2)
(indent-region (point-min) (point-max))
(should (equal (buffer-string) after))))
(ert-deftest plantuml-test-block-indentation/package-empty ()
"Test correct indentation of an empty package block."
(plantuml-test-indent-block
"
package APackage ()
"
"
package APackage ()
"))
(ert-deftest plantuml-test-block-indentation/package ()
"Test correct indentation of a package block."
(plantuml-test-indent-block
"
package APackage {
A -> B
}
"
"
package APackage {
A -> B
}
"))
(ert-deftest plantuml-test-block-indentation/package-database-nested ()
"Test correct indentation of two nested blocks, a package and a database.
Note: currently the inner database is not indented."
(plantuml-test-indent-block
"
package APackage {
database ADatabase {
A -> B
}
}
"
"
package APackage {
database ADatabase {
A -> B
}
}
"))
(ert-deftest plantuml-test-block-indentation/alt-end ()
"Test correct indentation of an alt-end block."
(plantuml-test-indent-block
"
alt choice 1
A -> B
end
"
"
alt choice 1
A -> B
end
" ))
(ert-deftest plantuml-test-block-indentation/alt-else-end ()
"Test correct indentation of an alt-else-end block."
(plantuml-test-indent-block
"
alt choice 1
A -> B
else
B -> C
end
"
"
alt choice 1
A -> B
else
B -> C
end
" ))
(ert-deftest plantuml-test-block-indentation/opt ()
"Test correct indentation of an opt block."
(plantuml-test-indent-block
"
opt event triggered
A -> B
end
"
"
opt event triggered
A -> B
end
" ))
(ert-deftest plantuml-test-block-indentation/par ()
"Test correct indentation of a par block."
(plantuml-test-indent-block
"
par
A -> B
else
C -> B
end
"
"
par
A -> B
else
C -> B
end
" ))
(ert-deftest plantuml-test-block-indentation/alt-else-loop-group ()
"Test correct indentation of combination of alt-else, loop and group.
This is taken from the plantuml homepage."
(plantuml-test-indent-block
"
Alice -> Bob: Authentication Request
alt successful case
Bob -> Alice: Authentication Accepted
else some kind of failure
Bob -> Alice: Authentication Failure
group My own label
Alice -> Log : Log attack start
loop 1000 times
Alice -> Bob: DNS Attack
end
Alice -> Log : Log attack end
end
else Another type of failure
Bob -> Alice: Please repeat
end
"
"
Alice -> Bob: Authentication Request
alt successful case
Bob -> Alice: Authentication Accepted
else some kind of failure
Bob -> Alice: Authentication Failure
group My own label
Alice -> Log : Log attack start
loop 1000 times
Alice -> Bob: DNS Attack
end
Alice -> Log : Log attack end
end
else Another type of failure
Bob -> Alice: Please repeat
end
"))
(ert-deftest plantuml-test-block-indentation/note-as ()
"Test correct indentation of a note-as block."
(plantuml-test-indent-block
"
note as N1
This is a note
end note
"
"
note as N1
This is a note
end note
"
))
(ert-deftest plantuml-test-block-indentation/activate-deactivate ()
"Test correct indentation of an activate-deactivate block."
(plantuml-test-indent-block
"
activate participant_1
participant_1 -> participant_2 : f()
deactivate participant_1
"
"
activate participant_1
participant_1 -> participant_2 : f()
deactivate participant_1
"))
(ert-deftest plantuml-test-block-indentation/activate-deactivate-nested ()
"Test correct indentation of two nested activate-deactivate blocks."
(plantuml-test-indent-block
"
activate participant_1
activate participant_2
participant_1 -> participant_2 : f()
deactivate participant_2
deactivate participant_1
"
"
activate participant_1
activate participant_2
participant_1 -> participant_2 : f()
deactivate participant_2
deactivate participant_1
"))
(provide 'plantuml-indentation-test)
;;; plantuml-indentation-test.el ends here
;;; plantuml-indentation-basics-test.el ends here

View File

@ -0,0 +1,351 @@
;;; plantuml-indentation-class-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;; Author: René Schmelzer
;; Maintainer: Carlo Sciolla (skuro)
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;; Test indentation for class diagrams.
;;; Code:
(ert-deftest plantuml-test-indentation/class-diagram ()
"Test correct indentation of plantuml class diagram elements.
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"
class Dummy {
String data
void methods()
}
class Flight {
flightNumber : Integer
departureTime : Date
}
class Dummy1 {
{field} A field (despite parentheses)
{method} Some method
}
class Dummy2 {
-field1
#field2
~method1()
+method2()
}
class Dummy3 {
{static} String id
{abstract} void methods()
}
class Foo1 {
You can use
several lines
..
as you want
and group
==
things together.
__
You can have as many groups
as you want
--
End of class
}
class User {
.. Simple Getter ..
+ getName()
+ getAddress()
.. Some setter ..
+ setName()
__ private data __
int age
-- encrypted --
String password
}
class ArrayList {
Object[] elementData
size()
}
enum TimeUnit {
DAYS
HOURS
MINUTES
}
class Dummy4 <<Serializable>> {
String name
}
class Foo<? extends Element> {
int size()
}
abtract class AbstractC {
int size()
}
interface InterfaceC {
int size()
}
package \"Classic Collections\" #DDDDDD {
Object <|-- ArrayList
}
package net.sourceforge.plantuml {
Object <|-- Demo1
Demo1 *- Demo2
}
package foo1 <<Node>> {
class Class1
}
package foo2 <<Rectangle>> {
class Class2
}
package foo3 <<Folder>> {
class Class3
}
package foo4 <<Frame>> {
class Class4
}
package foo5 <<Cloud>> {
class Class5
}
package foo6 <<Database>> {
class Class6
}
package foo1.foo2 {
class ObjectFoo1Foo2
}
package foo1.foo2.foo3 {
class Objectfoo1.foo2.foo3
}
namespace net.dummy #DDDDDD {
.BaseClass <|-- Person
Meeting o-- Person
.BaseClass <|- Meeting
}
namespace net.foo {
net.dummy.Person <|- Person
.BaseClass <|-- Person
net.dummy.Meeting o-- Person
}
set namespaceSeparator ::
class X1::X2::foo {
some info
}
together {
class Together1
class Together2
class Together3
}
"
"
class Dummy {
String data
void methods()
}
class Flight {
flightNumber : Integer
departureTime : Date
}
class Dummy1 {
{field} A field (despite parentheses)
{method} Some method
}
class Dummy2 {
-field1
#field2
~method1()
+method2()
}
class Dummy3 {
{static} String id
{abstract} void methods()
}
class Foo1 {
You can use
several lines
..
as you want
and group
==
things together.
__
You can have as many groups
as you want
--
End of class
}
class User {
.. Simple Getter ..
+ getName()
+ getAddress()
.. Some setter ..
+ setName()
__ private data __
int age
-- encrypted --
String password
}
class ArrayList {
Object[] elementData
size()
}
enum TimeUnit {
DAYS
HOURS
MINUTES
}
class Dummy4 <<Serializable>> {
String name
}
class Foo<? extends Element> {
int size()
}
abtract class AbstractC {
int size()
}
interface InterfaceC {
int size()
}
package \"Classic Collections\" #DDDDDD {
Object <|-- ArrayList
}
package net.sourceforge.plantuml {
Object <|-- Demo1
Demo1 *- Demo2
}
package foo1 <<Node>> {
class Class1
}
package foo2 <<Rectangle>> {
class Class2
}
package foo3 <<Folder>> {
class Class3
}
package foo4 <<Frame>> {
class Class4
}
package foo5 <<Cloud>> {
class Class5
}
package foo6 <<Database>> {
class Class6
}
package foo1.foo2 {
class ObjectFoo1Foo2
}
package foo1.foo2.foo3 {
class Objectfoo1.foo2.foo3
}
namespace net.dummy #DDDDDD {
.BaseClass <|-- Person
Meeting o-- Person
.BaseClass <|- Meeting
}
namespace net.foo {
net.dummy.Person <|- Person
.BaseClass <|-- Person
net.dummy.Meeting o-- Person
}
set namespaceSeparator ::
class X1::X2::foo {
some info
}
together {
class Together1
class Together2
class Together3
}
"))
(ert-deftest plantuml-test-block-indentation/class/package-empty ()
"Test correct indentation of an empty package block."
(plantuml-test-indent-block
"
package APackage ()
interface Inter
"
"
package APackage ()
interface Inter
"))
(ert-deftest platuml-test-block-indentation/class/package-interface-nested ()
"Test correct indentation of two nested blocks, a package and an interface
Note: package is used in deployment and object diagrams as well, see there for more tests."
(plantuml-test-indent-block
"
package foo {
interface Bar {
baz
}
}
"
"
package foo {
interface Bar {
baz
}
}
"))
(provide 'plantuml-indentation-class-test)
;;; plantuml-indentation-class-test.el ends here

View File

@ -0,0 +1,340 @@
;;; plantuml-indentation-commons-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;; Author: René Schmelzer
;; Maintainer: Carlo Sciolla (skuro)
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;; Test indentation of structures and elements that are common
;; to many/all diagrams.
;;; Code:
(ert-deftest plantuml-test-indentation/commons/skinparam ()
"Test correct indentation of skinparam elements, which are common to many plantuml diagrams:"
(plantuml-test-indent-block
"
skinparam roundcorner 20
skinparam rectangle {
roundCorner<<Concept>> 25
}
"
"
skinparam roundcorner 20
skinparam rectangle {
roundCorner<<Concept>> 25
}
"))
(ert-deftest plantuml-test-indentation/commons/rectangle ()
"Test correct indentation of rectangle elements, which are common to many plantuml diagrams:"
(plantuml-test-indent-block
"
rectangle \"Concept Model\" <<Concept>> {
rectangle \"Example 1\" <<Concept>> as ex1
rectangle \"Another rectangle\"
}
"
"
rectangle \"Concept Model\" <<Concept>> {
rectangle \"Example 1\" <<Concept>> as ex1
rectangle \"Another rectangle\"
}
"))
(ert-deftest plantuml-test-indentation/commons/title ()
"Test correct indentation of title elements, which are common to many plantuml diagrams:"
(plantuml-test-indent-block
"
title
<font color=red>Warning:</font>
Do not use in production.
end title
"
"
title
<font color=red>Warning:</font>
Do not use in production.
end title
" ))
(ert-deftest plantuml-test-indentation/commons/header ()
"Test correct indentation of header elements, which are common to many plantuml diagrams:"
(plantuml-test-indent-block
"
header
this is a header
endheader
center header
this is a centered header
endheader
right header
this is a header on right
endheader
left header
this is a header on left
endheader
center left header
this is no correct header
endheader
header left
this is no correct a header
endheader
"
"
header
this is a header
endheader
center header
this is a centered header
endheader
right header
this is a header on right
endheader
left header
this is a header on left
endheader
center left header
this is no correct header
endheader
header left
this is no correct a header
endheader
" ))
(ert-deftest plantuml-test-indentation/commons/footer ()
"Test correct indentation of footer elements, which are common to many plantuml diagrams:"
(plantuml-test-indent-block
"
footer
this is a footer
endfooter
center footer
this is a centered footer
endfooter
right footer
this is a footer on right
endfooter
left footer
this is a footer on left
endfooter
center left footer
this is no correct footer
endfooter
footer left
this is no correct a footer
endfooter
"
"
footer
this is a footer
endfooter
center footer
this is a centered footer
endfooter
right footer
this is a footer on right
endfooter
left footer
this is a footer on left
endfooter
center left footer
this is no correct footer
endfooter
footer left
this is no correct a footer
endfooter
" ))
(ert-deftest plantuml-test-indentation/commons/legend ()
"Test correct indentation of legend elements, which are common to many plantuml diagrams:"
(plantuml-test-indent-block
"
legend
Short legend
endlegend
legend bottom
bottom legend
endlegend
legend top
top legend
endlegend
legend center
centered legend
endlegend
legend right
legend on right
endlegend
legend left
legend on left
endlegend
legend bottom left
legend on bottom left
endlegend
legend top left
legend on top left
endlegend
legend bottom right
legend on bottom right
endlegend
legend top right
legend on top right
endlegend
"
"
legend
Short legend
endlegend
legend bottom
bottom legend
endlegend
legend top
top legend
endlegend
legend center
centered legend
endlegend
legend right
legend on right
endlegend
legend left
legend on left
endlegend
legend bottom left
legend on bottom left
endlegend
legend top left
legend on top left
endlegend
legend bottom right
legend on bottom right
endlegend
legend top right
legend on top right
endlegend
" ))
(ert-deftest plantuml-test-indentation/commons/legend-noindent ()
"Test the not-indentation of false legend elements."
(plantuml-test-indent-block
"
legend bottom top
this is no correct legend
endlegend
legend right bottom
this is no correct legend
endlegend
legend left top
this is no correct legend
endlegend
legend center right
this is no correct legend
endlegend
legend center left
this is no correct legend
endlegend
legend right left
this is no correct legend
endlegend
"
"
legend bottom top
this is no correct legend
endlegend
legend right bottom
this is no correct legend
endlegend
legend left top
this is no correct legend
endlegend
legend center right
this is no correct legend
endlegend
legend center left
this is no correct legend
endlegend
legend right left
this is no correct legend
endlegend
"
))
(ert-deftest plantuml-test-indentation/commons/multiline-macro ()
"Test the indentation of multiline macro elements."
(plantuml-test-indent-block
"
!define DOUBLE(x) x x
!definelong AUTHEN(x,y)
x -> y : DOUBLE(hello)
y -> x : ok
!enddefinelong
AUTHEN(Bob,Alice)
"
"
!define DOUBLE(x) x x
!definelong AUTHEN(x,y)
x -> y : DOUBLE(hello)
y -> x : ok
!enddefinelong
AUTHEN(Bob,Alice)
"
))
;;; plantuml-indentation-commons-test.el ends here

View File

@ -0,0 +1,69 @@
;;; plantuml-indentation-component-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;; Author: René Schmelzer
;; Maintainer: Carlo Sciolla (skuro)
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;; Test indentation for component diagrams.
;;; Code:
(ert-deftest plantuml-test-indentation/component-diagram ()
"Test correct indentation of plantuml component diagram elements.
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"
package \"Some Group\" {
HTTP - [First Component]
[Another Component]
}
node \"Other Groups\" {
FTP - [Second Component]
[First Component] --> FTP
}
cloud {
[Example 1]
}
database \"MySql\" {
folder \"This is my folder\" {
[Folder 3]
}
frame \"Foo\" {
[Frame 4]
}
}
"
"
package \"Some Group\" {
HTTP - [First Component]
[Another Component]
}
node \"Other Groups\" {
FTP - [Second Component]
[First Component] --> FTP
}
cloud {
[Example 1]
}
database \"MySql\" {
folder \"This is my folder\" {
[Folder 3]
}
frame \"Foo\" {
[Frame 4]
}
}
"))
(provide 'plantuml-indentation-component-test)
;;; plantuml-indentation-component-test.el ends here

View File

@ -0,0 +1,111 @@
;;; plantuml-indentation-deployment-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;; Author: René Schmelzer
;; Maintainer: Carlo Sciolla (skuro)
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;; Test indentation for deployment diagrams.
;; Most plantuml code examples are taken from www.plantuml.com
;;; Code:
(ert-deftest plantuml-test-indentation/deployment-diagram ()
"Test correct indentation of plantuml deployment diagram elements."
(plantuml-test-indent-block
"
artifact Foo1 {
folder Foo2
}
folder Foo3 {
artifact Foo4
}
frame Foo5 {
database Foo6
}
cloud vpc {
node ec2 {
stack stack
}
}
node Foo1 {
cloud Foo2
}
cloud Foo3 {
frame Foo4
}
database Foo5 {
storage Foo6
}
storage Foo7 {
storage Foo8
}
"
"
artifact Foo1 {
folder Foo2
}
folder Foo3 {
artifact Foo4
}
frame Foo5 {
database Foo6
}
cloud vpc {
node ec2 {
stack stack
}
}
node Foo1 {
cloud Foo2
}
cloud Foo3 {
frame Foo4
}
database Foo5 {
storage Foo6
}
storage Foo7 {
storage Foo8
}
"))
(ert-deftest plantuml-test-block-indentation/package-database-nested ()
"Test correct indentation of two nested blocks, a package and a database.
Note: package is used in class and object diagrams as well, see there for more tests."
(plantuml-test-indent-block
"
package APackage {
database ADatabase {
A -> B
}
}
"
"
package APackage {
database ADatabase {
A -> B
}
}
"))
(provide 'plantuml-indentation-deployment-test)
;;; plantuml-indentation-deployment-test.el ends here

View File

@ -0,0 +1,58 @@
;;; plantuml-indentation-ie-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;; Author: Carlo Sciolla (skuro)
;; Maintainer: Carlo Sciolla (skuro)
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;; Test indentation of Information Engineering (IE) notation.
;; See https://github.com/plantuml/plantuml/pull/31
;;; Code:
(ert-deftest plantuml-test-block-indentation/ie-entity ()
"Test correct indentation of an entity block."
(plantuml-test-indent-block
"
entity Entity {
* identifying_attribute
--
* mandatory_attribute
optional_attribute
}
"
"
entity Entity {
* identifying_attribute
--
* mandatory_attribute
optional_attribute
}
"
))
(ert-deftest plantuml-test-indendation/ie-arrows ()
"Test correct indentation of IE-style arrows."
(plantuml-test-indent-block
"
foo1 --{ bar1
foo1 --{ bar2
foo1 --{ bar3
aa --o{ bb
aa --o{ cc
aa --o{ dd
"
"
foo1 --{ bar1
foo1 --{ bar2
foo1 --{ bar3
aa --o{ bb
aa --o{ cc
aa --o{ dd
"))
;;; plantuml-indentation-ie-test.el ends here

View File

@ -0,0 +1,403 @@
;;; plantuml-indentation-notes-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;; Author: René Schmelzer
;; Maintainer: Carlo Sciolla (skuro)
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;; Test indentation of note elements.
;; Notes are used in almost all diagrams, but not all types of notes
;; are supported in every diagram type.
;;; Code:
(ert-deftest plantuml-test-block-indentation/note-simple ()
"Test correct indentation of a simple note block."
(plantuml-test-indent-block
"
note right: single line note
note right
multi line note
end note
"
"
note right: single line note
note right
multi line note
end note
"
))
(ert-deftest plantuml-test-block-indentation/note-left-right ()
"Test correct indentation of a note left/right block."
(plantuml-test-indent-block
"
(*) --> \"Some Activity\"
note right: This activity has to be defined
\"Some Activity\" --> (*)
note right
This note is on
several lines
end note
(*) --> \"Some Activity\"
note left: This activity has to be defined
\"Some Activity\" --> (*)
note left
This note is on
several lines
end note
"
"
(*) --> \"Some Activity\"
note right: This activity has to be defined
\"Some Activity\" --> (*)
note right
This note is on
several lines
end note
(*) --> \"Some Activity\"
note left: This activity has to be defined
\"Some Activity\" --> (*)
note left
This note is on
several lines
end note
" ))
(ert-deftest plantuml-test-block-indentation/note-xxx-of ()
"Test correct indentation of a note xxx of block.
plantuml.com:
You can use the note left of, note right of, note top of,
note bottom of keywords to define notes related to a single
object."
(plantuml-test-indent-block
"
note right of Alice: This is displayed right of Alice.
note left of Alice #aqua
This is displayed
left of Alice.
end note
note left of Alice: This is displayed left of Alice.
note right of Alice #aqua
This is displayed
right of Alice.
end note
note right of (Use)
A note can also
be on several lines
end note
note left of HTTP : Web Service only
note right of [First Component]
A note can also
be on several lines
end note
"
"
note right of Alice: This is displayed right of Alice.
note left of Alice #aqua
This is displayed
left of Alice.
end note
note left of Alice: This is displayed left of Alice.
note right of Alice #aqua
This is displayed
right of Alice.
end note
note right of (Use)
A note can also
be on several lines
end note
note left of HTTP : Web Service only
note right of [First Component]
A note can also
be on several lines
end note
"
))
(ert-deftest plantuml-test-block-indentation/note-on-link ()
"Test correct indentation of a note xxx of block.
plantuml.com:
You can also use note left on link, note right on link,
note top on link, note bottom on link if you want to change
the relative position of the note with the label."
(plantuml-test-indent-block
"
class Dummy
Dummy --> Foo : A link
note on link #red: note that is red
Dummy --> Foo2 : Another link
note right on link #blue
this is my note on right link
and in blue
end note
note left on link #00FFFF
this is my note on left link
and in color as number
end note
"
"
class Dummy
Dummy --> Foo : A link
note on link #red: note that is red
Dummy --> Foo2 : Another link
note right on link #blue
this is my note on right link
and in blue
end note
note left on link #00FFFF
this is my note on left link
and in color as number
end note
"
))
(ert-deftest plantuml-test-block-indentation/note-over ()
"Test correct indentation of a note-over block."
(plantuml-test-indent-block
"
note over Alice: This is displayed over Alice.
note over Alice, Bob #FFAAAA: This is displayed over Bob and Alice.
note over Bob, Alice
This is yet another
example of
a long note.
end note
"
"
note over Alice: This is displayed over Alice.
note over Alice, Bob #FFAAAA: This is displayed over Bob and Alice.
note over Bob, Alice
This is yet another
example of
a long note.
end note
"
))
;; Here we have an inconsistency (again) in plantuml syntax
;; single line note as …’ does not contain a ?:
;;
;; (ert-deftest plantuml-test-block-indentation/note-as ()
;; "Test correct indentation of a note-as block."
;; (plantuml-test-indent-block
;; "
;; :Main Admin: as Admin
;; (Use the application) as (Use)
;; User -> (Start)
;; User --> (Use)
;; Admin ---> (Use)
;; note right of Admin : This is an example.
;; note right of (Use)
;; A note can also
;; be on several lines
;; end note
;; note \"This note is connected to several objects.\" as N2 #RED
;; (Start) .. N2
;; N2 .. (Use)
;; note as N3 #blue
;; This note is connected
;; to several objects as well.
;; end note
;; (Start) .. N3
;; N3 .. Admin
;; "
;; "
;; :Main Admin: as Admin
;; (Use the application) as (Use)
;; User -> (Start)
;; User --> (Use)
;; Admin ---> (Use)
;; note right of Admin : This is an example.
;; note right of (Use)
;; A note can also
;; be on several lines
;; end note
;; note \"This note is connected to several objects.\" as N2 #RED
;; (Start) .. N2
;; N2 .. (Use)
;; note as N3 #blue
;; This note is connected
;; to several objects as well.
;; end note
;; (Start) .. N3
;; N3 .. Admin
;; "
;; ))
(ert-deftest plantuml-test-block-indentation/note-floating ()
"Test correct indentation of a floating note block."
(plantuml-test-indent-block
"
floating note left: This is a note
:foo2;
floating note right
This note is on several
//lines// and can
contain <b>HTML</b>
====
* Calling the method \"\"foo()\"\" is prohibited
end note
"
"
floating note left: This is a note
:foo2;
floating note right
This note is on several
//lines// and can
contain <b>HTML</b>
====
* Calling the method \"\"foo()\"\" is prohibited
end note
"
))
(ert-deftest plantuml-test-block-indentation/note-h-r-note ()
"Test correct indentation of a [hr]note block."
(plantuml-test-indent-block
"
caller -> server : conReq
rnote over caller : idle
hnote over caller : idle
caller <- server : conConf
rnote over server
r as rectangle
h as hexagon
endrnote
hnote over server
r as rectangle
h as hexagon
endrnote
"
"
caller -> server : conReq
rnote over caller : idle
hnote over caller : idle
caller <- server : conConf
rnote over server
r as rectangle
h as hexagon
endrnote
hnote over server
r as rectangle
h as hexagon
endrnote
"
))
(ert-deftest plantuml-test-block-indentation/note-creole-html ()
"Test correct indentation of a note block with creole/html."
(plantuml-test-indent-block
"
participant Alice
participant \"The **Famous** Bob\" as Bob
Alice -> Bob : hello --there--
... Some ~~long delay~~ ...
Bob -> Alice : ok
note left
This is **bold**
This is //italics//
This is \"\"monospaced\"\"
This is --stroked--
This is __underlined__
This is ~~waved~~
end note
Alice -> Bob : A //well formatted// message
note right of Alice
This is <back:cadetblue><size:18>displayed</size></back>
__left of__ Alice.
end note
note left of Bob
<u:red>This</u> is <color #118888>displayed</color>
**<color purple>left of</color> <s:red>Alice</strike> Bob**.
end note
note over Alice, Bob
<w:#FF33FF>This is hosted</w> by <img sourceforge.jpg>
end note
"
"
participant Alice
participant \"The **Famous** Bob\" as Bob
Alice -> Bob : hello --there--
... Some ~~long delay~~ ...
Bob -> Alice : ok
note left
This is **bold**
This is //italics//
This is \"\"monospaced\"\"
This is --stroked--
This is __underlined__
This is ~~waved~~
end note
Alice -> Bob : A //well formatted// message
note right of Alice
This is <back:cadetblue><size:18>displayed</size></back>
__left of__ Alice.
end note
note left of Bob
<u:red>This</u> is <color #118888>displayed</color>
**<color purple>left of</color> <s:red>Alice</strike> Bob**.
end note
note over Alice, Bob
<w:#FF33FF>This is hosted</w> by <img sourceforge.jpg>
end note
"
))
;;; plantuml-indentation-notes-test.el ends here

View File

@ -0,0 +1,34 @@
;;; plantuml-indentation-object-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;; Author: René Schmelzer
;; Maintainer: Carlo Sciolla (skuro)
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;; Test indentation for object diagrams.
;;; Code:
(ert-deftest plantuml-test-indentation/object-diagram ()
"Test correct indentation of plantuml object diagram elements.
These code examples are taken from www.plantuml.com
Note: object diagrams use many elements defined for class diagrams."
(plantuml-test-indent-block
"
object user {
name = \"Dummy\"
id = 123
}
"
"
object user {
name = \"Dummy\"
id = 123
}
"))
(provide 'plantuml-indentation-object-test)
;;; plantuml-indentation-object-test.el ends here

View File

@ -0,0 +1,362 @@
;;; plantuml-indentation-sequence-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;; Author: René Schmelzer
;; Maintainer: Carlo Sciolla (skuro)
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;; Test indentation for sequence diagrams.
;;; Code:
(ert-deftest platuml-test-block-indentation/sequence/box ()
"Test correct indentation of a box block"
(plantuml-test-indent-block
"
box \"Device with USB connector\"
actor Human
participant UsbDetector
end box
"
"
box \"Device with USB connector\"
actor Human
participant UsbDetector
end box
" ))
(ert-deftest platuml-test-block-indentation/sequence/ref ()
"Test correct indentation of a ref block"
(plantuml-test-indent-block
"
participant Alice
actor Bob
participant \"Great Cesar\"
ref over Alice, Bob : init
Alice -> Bob : hello
ref over Bob, \"Great Cesar\"
This can be on
several lines
end ref
ref over Bob
This is a ref over Bob
end ref
ref over \"Great Cesar\"
This is a ref over \"Great Cesar\"
end ref
"
"
participant Alice
actor Bob
participant \"Great Cesar\"
ref over Alice, Bob : init
Alice -> Bob : hello
ref over Bob, \"Great Cesar\"
This can be on
several lines
end ref
ref over Bob
This is a ref over Bob
end ref
ref over \"Great Cesar\"
This is a ref over \"Great Cesar\"
end ref
" ))
(ert-deftest plantuml-test-block-indentation/sequence/alt-end ()
"Test correct indentation of an alt-end block.
The alt-keyword is NOT followed by some text."
(plantuml-test-indent-block
"
alt
A -> B
end
"
"
alt
A -> B
end
" ))
(ert-deftest plantuml-test-block-indentation/sequence/alt-end-with-label ()
"Test correct indentation of an alt-end block.
The alt-keyword is followed by some text."
(plantuml-test-indent-block
"
alt choice 1
A -> B
end
"
"
alt choice 1
A -> B
end
" ))
(ert-deftest plantuml-test-block-indentation/sequence/alt-else-end ()
"Test correct indentation of an alt-else-end block."
(plantuml-test-indent-block
"
alt choice 1
A -> B
else
B -> C
end
"
"
alt choice 1
A -> B
else
B -> C
end
" ))
(ert-deftest plantuml-test-block-indentation/sequence/opt ()
"Test correct indentation of an opt block.
The opt-keyword is NOT followed by some text."
(plantuml-test-indent-block
"
opt
A -> B
end
"
"
opt
A -> B
end
" ))
(ert-deftest plantuml-test-block-indentation/sequence/opt-with-label ()
"Test correct indentation of an opt block.
The opt-keyword is followed by some text."
(plantuml-test-indent-block
"
opt event triggered
A -> B
end
"
"
opt event triggered
A -> B
end
" ))
(ert-deftest plantuml-test-block-indentation/sequence/par ()
"Test correct indentation of a par block.
The par-keyword is NOT followed by some text."
(plantuml-test-indent-block
"
par
A -> B
else
C -> B
end
"
"
par
A -> B
else
C -> B
end
" ))
(ert-deftest plantuml-test-block-indentation/sequence/par-with-label ()
"Test correct indentation of a par block.
The par-keyword is followed by some text."
(plantuml-test-indent-block
"
par a text label
A -> B
else
C -> B
end
"
"
par a text label
A -> B
else
C -> B
end
" ))
(ert-deftest plantuml-test-block-indentation/sequence/group ()
"Test correct indentation of a group block.
The group-keyword is NOT followed by some text."
(plantuml-test-indent-block
"
group
A -> B
else
C -> B
end
"
"
group
A -> B
else
C -> B
end
" ))
(ert-deftest plantuml-test-block-indentation/sequence/group-with-label ()
"Test correct indentation of a group block.
The group-keyword is followed by some text."
(plantuml-test-indent-block
"
group my own label
A -> B
else
C -> B
end
"
"
group my own label
A -> B
else
C -> B
end
" ))
(ert-deftest plantuml-test-block-indentation/sequence/critical ()
"Test correct indentation of a critical block.
The critical-keyword is NOT followed by some text."
(plantuml-test-indent-block
"
critical
A -> B
else
C -> B
end
"
"
critical
A -> B
else
C -> B
end
" ))
(ert-deftest plantuml-test-block-indentation/sequence/critical-with-label ()
"Test correct indentation of a critical block.
The critical-keyword is followed by some text."
(plantuml-test-indent-block
"
critical my own label
A -> B
else
C -> B
end
"
"
critical my own label
A -> B
else
C -> B
end
" ))
(ert-deftest plantuml-test-block-indentation/sequence/activate-deactivate ()
"Test correct indentation of an activate-deactivate block."
(plantuml-test-indent-block
"
activate participant_1
participant_1 -> participant_2 : f()
deactivate participant_1
"
"
activate participant_1
participant_1 -> participant_2 : f()
deactivate participant_1
"))
(ert-deftest plantuml-test-block-indentation/sequence/activate-deactivate-nested ()
"Test correct indentation of two nested activate-deactivate blocks."
(plantuml-test-indent-block
"
activate participant_1
activate participant_2
participant_1 -> participant_2 : f()
deactivate participant_2
deactivate participant_1
"
"
activate participant_1
activate participant_2
participant_1 -> participant_2 : f()
deactivate participant_2
deactivate participant_1
"))
(ert-deftest plantuml-test-indentation/sequence-diagram ()
"Test correct indentation of plantuml sequence diagram elements.
These code examples are taken from www.plantuml.com."
(plantuml-test-indent-block
"
Alice -> Bob: Authentication Request
alt successful case
Bob -> Alice: Authentication Accepted
else some kind of failure
Bob -> Alice: Authentication Failure
group My own label
Alice -> Log : Log attack start
loop 1000 times
Alice -> Bob: DNS Attack
end
Alice -> Log : Log attack end
end
else Another type of failure
Bob -> Alice: Please repeat
end
"
"
Alice -> Bob: Authentication Request
alt successful case
Bob -> Alice: Authentication Accepted
else some kind of failure
Bob -> Alice: Authentication Failure
group My own label
Alice -> Log : Log attack start
loop 1000 times
Alice -> Bob: DNS Attack
end
Alice -> Log : Log attack end
end
else Another type of failure
Bob -> Alice: Please repeat
end
"))
(provide 'plantuml-indentation-sequence-test)
;;; plantuml-indentation-sequence-test.el ends here

View File

@ -0,0 +1,119 @@
;;; plantuml-indentation-state-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;; Author: René Schmelzer
;; Maintainer: Carlo Sciolla (skuro)
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;; Test indentation for state diagrams.
;;; Code:
(ert-deftest plantuml-test-indentation/state-diagram ()
"Test correct indentation of plantuml state diagram elements.
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"
state NotShooting {
[*] --> Idle
Idle --> Configuring : EvConfig
Configuring --> Idle : EvConfig
}
state Configuring {
[*] --> NewValueSelection
NewValueSelection --> NewValuePreview : EvNewValue
NewValuePreview --> NewValueSelection : EvNewValueRejected
NewValuePreview --> NewValueSelection : EvNewValueSaved
state NewValuePreview {
State1 -> State2
}
}
state State3 {
state \"Accumulate Enough Data\\nLong State Name\" as long1
long1 : Just a test
[*] --> long1
long1 --> long1 : New Data
long1 --> ProcessData : Enough Data
}
state Active {
[*] -> NumLockOff
NumLockOff --> NumLockOn : EvNumLockPressed
NumLockOn --> NumLockOff : EvNumLockPressed
--
[*] -> CapsLockOff
CapsLockOff --> CapsLockOn : EvCapsLockPressed
CapsLockOn --> CapsLockOff : EvCapsLockPressed
--
[*] -> ScrollLockOff
ScrollLockOff --> ScrollLockOn : EvCapsLockPressed
ScrollLockOn --> ScrollLockOff : EvCapsLockPressed
}
state \"Not Shooting State\" as NotShooting {
state \"Idle mode\" as Idle
state \"Configuring mode\" as Configuring
[*] --> Idle
Idle --> Configuring : EvConfig
Configuring --> Idle : EvConfig
}
"
"
state NotShooting {
[*] --> Idle
Idle --> Configuring : EvConfig
Configuring --> Idle : EvConfig
}
state Configuring {
[*] --> NewValueSelection
NewValueSelection --> NewValuePreview : EvNewValue
NewValuePreview --> NewValueSelection : EvNewValueRejected
NewValuePreview --> NewValueSelection : EvNewValueSaved
state NewValuePreview {
State1 -> State2
}
}
state State3 {
state \"Accumulate Enough Data\\nLong State Name\" as long1
long1 : Just a test
[*] --> long1
long1 --> long1 : New Data
long1 --> ProcessData : Enough Data
}
state Active {
[*] -> NumLockOff
NumLockOff --> NumLockOn : EvNumLockPressed
NumLockOn --> NumLockOff : EvNumLockPressed
--
[*] -> CapsLockOff
CapsLockOff --> CapsLockOn : EvCapsLockPressed
CapsLockOn --> CapsLockOff : EvCapsLockPressed
--
[*] -> ScrollLockOff
ScrollLockOff --> ScrollLockOn : EvCapsLockPressed
ScrollLockOn --> ScrollLockOff : EvCapsLockPressed
}
state \"Not Shooting State\" as NotShooting {
state \"Idle mode\" as Idle
state \"Configuring mode\" as Configuring
[*] --> Idle
Idle --> Configuring : EvConfig
Configuring --> Idle : EvConfig
}
"))
(provide 'plantuml-indentation-state-test)
;;; plantuml-indentation-state-test.el ends here

View File

@ -10,14 +10,14 @@
(ert-deftest custom-jar-location ()
(setq-local plantuml-jar-path "~/.plantuml/plantuml.jar")
(should (equal `("-Djava.awt.headless=true" "-jar"
(should (equal `("-Djava.awt.headless=true" "-jar" "--illegal-access=deny"
,(expand-file-name "~/.plantuml/plantuml.jar")
"-charset" "UTF-8")
(plantuml-render-command)))
(plantuml-jar-render-command)))
(setq-local plantuml-jar-path "/path/with spaces/plantuml.jar")
(should (equal `("-Djava.awt.headless=true" "-jar" "/path/with spaces/plantuml.jar" "-charset" "UTF-8")
(plantuml-render-command))))
(should (equal `("-Djava.awt.headless=true" "-jar" "--illegal-access=deny" "/path/with spaces/plantuml.jar" "-charset" "UTF-8")
(plantuml-jar-render-command))))
(provide 'plantuml-mode-custom-jar-location-test)

View File

@ -8,16 +8,19 @@
;;; Code:
(defun assert-preview (puml output &optional format)
(defun assert-preview (puml output &optional format mode)
(if format
(setq plantuml-output-type format)
(setq plantuml-output-type "utxt"))
(setq plantuml-output-type format)
(setq plantuml-output-type "txt"))
(if mode
(setq plantuml-exec-mode mode)
(setq plantuml-exec-mode 'jar))
(plantuml-preview-string 42 (read-test-file puml))
(sleep-for 3)
(should (equal (format-preview-output (replace-regexp-in-string " " "~" (read-test-file output)))
(format-preview-output (replace-regexp-in-string " " "~" (read-preview-buffer))))))
(ert-deftest preview-utxt-test ()
(ert-deftest preview-txt-test ()
(setq-local plantuml-jar-path plantuml-test-jar-path)
(assert-preview "a-b.puml" "a-b.txt"))

View File

@ -1,4 +1,79 @@
/' This is a manual test for you to test different use-cases '/
participant API
participant Instance
alt deploy success
Instance -> API: Deploy successful
else deploy failure
Instance -> API: Deploy failed
else deploy timeout
Instance -> API: Deploy failed
end
package "kuaishow-common-proto" {
component Kwai
component KwaiGo
component AcFun
}
package "kwaigo-log-proto" {
[KwaiGo] ..> [KwaiGo Client->Data] : split
}
package "kwaigo-api-proto" {
[KwaiGo] ..> [KwaiGo Client->Server] : split
}
cloud "log server\n" {
[KwaiGo Client->Data] -->[KwaiGo Log Server] : upload
}
cloud "api server\n" {
[KwaiGo Api Server]
}
[KwaiGo Client->Server] --> [KwaiGo Api Server] : request
[KwaiGo Api Server] --> [KwaiGo Client->Server] : response
database "LogSql" {
folder "Log" {
[ReportEvent]
}
frame "event" {
[EventPackage]
}
frame "stat" {
[StatPackage]
}
}
[KwaiGo Log Server] --> [ReportEvent] : save
[ReportEvent] --> [EventPackage]
[ReportEvent] --> [StatPackage]
database "ApiSql" {
folder "kwaigo" {
[KwaiGoData]
}
frame "user" {
[UserData]
}
frame "photo" {
[PhotoData]
}
}
[KwaiGo Api Server] --> [KwaiGoData] : request
[KwaiGoData] --> [KwaiGo Api Server] : compute
[KwaiGoData] --> [UserData]
[KwaiGoData] --> [PhotoData]
Nobody -> [APIGateway]
package APackage {

View File

@ -39,6 +39,33 @@
"Make the preview output as S more readable in test output."
(concat "\n" s))
(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
(setq plantuml-jar-path plantuml-test-jar-path)
(plantuml-init-once 'jar)
(insert before)
(goto-char (point-min))
(plantuml-mode)
;; use 2 spaces instead of one tab for indentation
(setq indent-tabs-mode nil)
(setq tab-width 2)
(indent-region (point-min) (point-max))
(should (equal (buffer-string) after))))
;; enable code coverage
(when (require 'undercover nil t)
(undercover "plantuml-mode.el"))