Added a test for indentation using tabs.

This commit is contained in:
mtoboid 2021-06-17 10:19:45 +02:00
parent ea45a13707
commit 87b3c1ed0d
2 changed files with 142 additions and 0 deletions

View File

@ -0,0 +1,111 @@
;;; plantuml-indentation-with-tabs-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;; Author: René Schmelzer, Tobias Marczewski (mtoboid)
;; Maintainer: Carlo Sciolla (skuro)
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;; Test indentation for class diagrams, specifically using tabs.
;;; Code:
(ert-deftest plantuml-test-indentation/tabs/nested-modules ()
"Test correct indentation of plantuml class diagram elements.
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block-with-tabs
"
@startuml
'some comment
package org.example.module1 {
interface A {
doStuff(): String
getList(): List<Integer>
}
class B {
-name: String
+getName(): String
}
}
package org.example.module2 {
class C {
-count: int
+getCount(): int
}
}
A <|.. B
A <|.. C
@enduml
"
"
@startuml
'some comment
package org.example.module1 {
interface A {
doStuff(): String
getList(): List<Integer>
}
class B {
-name: String
+getName(): String
}
}
package org.example.module2 {
class C {
-count: int
+getCount(): int
}
}
A <|.. B
A <|.. C
@enduml
"))
(ert-deftest plantuml-test-block-indentation/tabs/package-empty ()
"Test correct indentation of an empty package block."
(plantuml-test-indent-block-with-tabs
"
package APackage ()
interface Inter
"
"
package APackage ()
interface Inter
"))
(ert-deftest platuml-test-block-indentation/tabs/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-with-tabs
"
package foo {
interface Bar {
baz
}
}
"
"
package foo {
interface Bar {
baz
}
}
"))
(provide 'plantuml-indentation-class-test)
;;; plantuml-indentation-with-tabs-test.el ends here

View File

@ -66,6 +66,37 @@ Finally, the indented text in the buffer will be compared with AFTER."
(indent-region (point-min) (point-max))
(should (equal (buffer-string) after))))
;; FIXME
;; This function is just a copy of the above plantuml-test-indent-block with
;; some minor changes to use indentation with tabs. Perhaps merge the two
;; functions?
(defun plantuml-test-indent-block-with-tabs (before after)
"Helper for the block indentation tests with tabs.
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 one tab 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)
;; ensure that plantuml-indent-level is the default value 8
(setq indent-tabs-mode t)
(setq plantuml-indent-level 8)
(indent-region (point-min) (point-max))
(should (equal (buffer-string) after))))
;; enable code coverage
(when (require 'undercover nil t)
(undercover "plantuml-mode.el"))