From 1b6562a1a2f5b396548ac8af4a72aaf5e9beb53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Schmelzer?= Date: Sat, 9 Mar 2019 08:27:26 +0100 Subject: [PATCH] indentation tests for diagram commons --- plantuml-mode.el | 11 +- test/plantuml-indentation-commons-test.el | 319 +++++++++++++++++++ test/plantuml-indentation-deployment-test.el | 20 +- 3 files changed, 329 insertions(+), 21 deletions(-) create mode 100644 test/plantuml-indentation-commons-test.el diff --git a/plantuml-mode.el b/plantuml-mode.el index 4943fbc..b17a769 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -358,15 +358,22 @@ 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-title-start "^\s*title$") + (defvar plantuml-indent-regexp-header-start "^\s*\\(?:\\(?:center\\|left\\|right\\)\s+header\\|header\\)$") + (defvar plantuml-indent-regexp-footer-start "^\s*\\(?:\\(?:center\\|left\\|right\\)\s+footer\\|footer\\)$") + (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\\)\\)$") (defvar plantuml-indent-regexp-if-start "^\s*\\(\\(?:.*\\)?\s*\\(?:[<>.*a-z-|]+\\)?\s*\\(?:\\[[a-zA-Z]+\\]\\)?\s+if\s+.*\\)") (defvar plantuml-indent-regexp-start (list plantuml-indent-regexp-block-start plantuml-indent-regexp-note-start plantuml-indent-regexp-group-start plantuml-indent-regexp-activate-start plantuml-indent-regexp-box-start + plantuml-indent-regexp-title-start + plantuml-indent-regexp-header-start + plantuml-indent-regexp-footer-start + plantuml-indent-regexp-legend-start plantuml-indent-regexp-if-start)) - (defvar plantuml-indent-regexp-end "^\s*\\(endif\\|else\\|end\\|end\s+note\\|end\s+box\\|.*}\\|deactivate\s+.+\\)") - + (defvar plantuml-indent-regexp-end "^\s*\\(?:endif\\|else\s*.*\\|end\\|end\s+note\\|end\s+box\\|.*}\\|deactivate\s+.+\\|end\s+title\\|endheader\\|endfooter\\|endlegend\\)") (setq plantuml-font-lock-keywords `( (,plantuml-types-regexp . font-lock-type-face) diff --git a/test/plantuml-indentation-commons-test.el b/test/plantuml-indentation-commons-test.el new file mode 100644 index 0000000..bde4683 --- /dev/null +++ b/test/plantuml-indentation-commons-test.el @@ -0,0 +1,319 @@ +;;; 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<> 25 +} +" + " +skinparam roundcorner 20 + +skinparam rectangle { + roundCorner<> 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\" <> { +rectangle \"Example 1\" <> as ex1 +rectangle \"Another rectangle\" +} +" + " +rectangle \"Concept Model\" <> { + rectangle \"Example 1\" <> 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 +Warning: +Do not use in production. +end title +" + " +title + Warning: + 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 +")) + + +(provide 'plantuml-indentation-commons-test) + +;;; plantuml-indentation-commons-test.el ends here diff --git a/test/plantuml-indentation-deployment-test.el b/test/plantuml-indentation-deployment-test.el index 11b4637..c8d0529 100644 --- a/test/plantuml-indentation-deployment-test.el +++ b/test/plantuml-indentation-deployment-test.el @@ -6,7 +6,7 @@ ;;; Commentary: -;; Test indentation for class diagrams. +;; Test indentation for deployment diagrams. ;; Most plantuml code examples are taken from www.plantuml.com ;;; Code: @@ -49,15 +49,6 @@ storage Foo7 { storage Foo8 } - -skinparam rectangle { -roundCorner<> 25 -} - -rectangle \"Concept Model\" <> { -rectangle \"Example 1\" <> as ex1 -rectangle \"Another rectangle\" -} " " artifact Foo1 { @@ -93,15 +84,6 @@ database Foo5 { storage Foo7 { storage Foo8 } - -skinparam rectangle { - roundCorner<> 25 -} - -rectangle \"Concept Model\" <> { - rectangle \"Example 1\" <> as ex1 - rectangle \"Another rectangle\" -} ")) (provide 'plantuml-indentation-deployment-test)