From 96ec931f645d7ff547370243d07a115daa0d438d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Schmelzer?= Date: Sun, 10 Mar 2019 21:35:24 +0100 Subject: [PATCH] regex corrections and added indentation tests for class diagrams correct indentation regexs found by tests for class diagrams --- plantuml-mode.el | 6 +- test/plantuml-indentation-class-test.el | 301 ++++++++++++++++++++++++ 2 files changed, 304 insertions(+), 3 deletions(-) create mode 100644 test/plantuml-indentation-class-test.el diff --git a/plantuml-mode.el b/plantuml-mode.el index b17a769..d0d31c9 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -346,9 +346,9 @@ Uses prefix (as PREFIX) to choose where to display it: (defvar plantuml-preprocessors-regexp (concat "^\\s *" (regexp-opt plantuml-preprocessors 'words))) (defvar plantuml-indent-regexp-block-start "^.*{\s*$" - "Indentation regex for all plantuml elements that might define a {} or [] block. + "Indentation regex for all plantuml elements that might define a {} block. Plantuml elements like skinparam, rectangle, sprite, package, …. -The opening { or [ has to be the last visible character in the line (whitespace +The opening { has to be the last visible character in the line (whitespace might follow).") (defvar plantuml-indent-regexp-note-start "^\s*\\(note\s+over\\|note\sas\s.*\\|note\s+\\(\\(?:\\(?:button\\|left\\|right\\|top\\)\\)\\)\\(?:\s+of\\)?\\)" "Indentation regex for all plantuml note elements") @@ -373,7 +373,7 @@ or it is followed by line end.") plantuml-indent-regexp-footer-start plantuml-indent-regexp-legend-start plantuml-indent-regexp-if-start)) - (defvar plantuml-indent-regexp-end "^\s*\\(?:endif\\|else\s*.*\\|end\\|end\s+note\\|end\s+box\\|.*}\\|deactivate\s+.+\\|end\s+title\\|endheader\\|endfooter\\|endlegend\\)") + (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-class-test.el b/test/plantuml-indentation-class-test.el new file mode 100644 index 0000000..c148aff --- /dev/null +++ b/test/plantuml-indentation-class-test.el @@ -0,0 +1,301 @@ +;;; 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 <> { + String name + } + + class Foo { + int size() + } + + package \"Classic Collections\" #DDDDDD { + Object <|-- ArrayList + } + + package net.sourceforge.plantuml { + Object <|-- Demo1 + Demo1 *- Demo2 + } + + package foo1 <> { + class Class1 + } + + package foo2 <> { + class Class2 + } + + package foo3 <> { + class Class3 + } + + package foo4 <> { + class Class4 + } + + package foo5 <> { + class Class5 + } + + package foo6 <> { + 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 <> { + String name +} + +class Foo { + int size() +} + +package \"Classic Collections\" #DDDDDD { + Object <|-- ArrayList +} + +package net.sourceforge.plantuml { + Object <|-- Demo1 + Demo1 *- Demo2 +} + +package foo1 <> { + class Class1 +} + +package foo2 <> { + class Class2 +} + +package foo3 <> { + class Class3 +} + +package foo4 <> { + class Class4 +} + +package foo5 <> { + class Class5 +} + +package foo6 <> { + 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 +} +")) + +(provide 'plantuml-indentation-class-test) + +;;; plantuml-indentation-class-test.el ends here