diff --git a/plantuml-mode.el b/plantuml-mode.el index 67740b0..ff6832b 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -352,12 +352,16 @@ The opening { or [ 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") - (defvar plantuml-indent-regexp-group-start "^\s*\\(loop\s+.*\\|group\s+.*\\|par\s*$\\|opt\s+.*\\|alt\s+.*\\|else\\|activate\s+.+\\)" - "Indentation regex for plantuml group elements that are defined for sequence 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-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-if-start)) (defvar plantuml-indent-regexp-end "^\s*\\(endif\\|else\\|end\\|end\s+note\\|.*}\\|deactivate\s+.+\\)") diff --git a/test/plantuml-indentation-test.el b/test/plantuml-indentation-test.el index 53a1cbb..daad927 100644 --- a/test/plantuml-indentation-test.el +++ b/test/plantuml-indentation-test.el @@ -387,7 +387,23 @@ package APackage { ")) (ert-deftest plantuml-test-block-indentation/alt-end () - "Test correct indentation of an alt-end block." + "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/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 @@ -419,7 +435,23 @@ end " )) (ert-deftest plantuml-test-block-indentation/opt () - "Test correct indentation of an opt block." + "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/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 @@ -433,7 +465,8 @@ end " )) (ert-deftest plantuml-test-block-indentation/par () - "Test correct indentation of a par block." + "Test correct indentation of a par block. +The par-keyword is NOT followed by some text." (plantuml-test-indent-block " par @@ -450,6 +483,101 @@ else end " )) +(ert-deftest plantuml-test-block-indentation/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/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/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/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/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/alt-else-loop-group () "Test correct indentation of combination of alt-else, loop and group. diff --git a/test/resources/unindented.plantuml b/test/resources/unindented.plantuml index 2d1a94d..f449f65 100644 --- a/test/resources/unindented.plantuml +++ b/test/resources/unindented.plantuml @@ -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 {