From bfa587d039a396ad7195ff1c3930d8a10330244a Mon Sep 17 00:00:00 2001 From: Stig Brautaset Date: Sun, 28 Mar 2021 00:13:49 +0000 Subject: [PATCH] Add indentation of "return" in sequence diagrams's activated blocks The return keyword takes an optional label. Use it as shorthand for "deactivate X[: LABEL]" when the block you want to deactivate is the most recent activated one. --- plantuml-mode.el | 2 +- test/plantuml-indentation-sequence-test.el | 86 ++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/plantuml-mode.el b/plantuml-mode.el index e40ba0d..345fbf5 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -610,7 +610,7 @@ or it is followed by line end.") (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-activate-end "^\s*\\(?:deactivate\s+.+\\|return.*\\)$") (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*\\('.*\\)?$") diff --git a/test/plantuml-indentation-sequence-test.el b/test/plantuml-indentation-sequence-test.el index d317942..cd721ca 100644 --- a/test/plantuml-indentation-sequence-test.el +++ b/test/plantuml-indentation-sequence-test.el @@ -302,6 +302,38 @@ activate participant_1 deactivate participant_1 ")) +(ert-deftest plantuml-test-block-indentation/sequence/activate-return () + "Test correct indentation of an activate-return block." + (plantuml-test-indent-block + " +activate participant_1 +participant_1 -> participant_2 : f() +return +" + " +activate participant_1 + participant_1 -> participant_2 : f() +return +")) + +(ert-deftest plantuml-test-block-indentation/sequence/activate-return-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() +return with a label +return +" + " +activate participant_1 + activate participant_2 + participant_1 -> participant_2 : f() + return with a label +return +")) + (ert-deftest plantuml-test-indentation/sequence-diagram () "Test correct indentation of plantuml sequence diagram elements. @@ -356,6 +388,60 @@ else Another type of failure end ")) +(ert-deftest plantuml-test-indentation/nested-sequence-diagram () + "Test correct indentation of plantuml nested sequence diagram elements." + (plantuml-test-indent-block + " +A -> foo +activate foo + foo --> bar + activate bar + bar->baz + activate baz + alt success case + baz --> baz: success +else + baz --> baz: fail +end +return +bar->quux +activate quux + note over quux + Cum sociis natoque + penatibus et magnis + dis parturient montes, + nascetur ridiculus mus. +end note +return +return +return +" + " +A -> foo +activate foo + foo --> bar + activate bar + bar->baz + activate baz + alt success case + baz --> baz: success + else + baz --> baz: fail + end + return + bar->quux + activate quux + note over quux + Cum sociis natoque + penatibus et magnis + dis parturient montes, + nascetur ridiculus mus. + end note + return + return +return +")) + (provide 'plantuml-indentation-sequence-test)