Add tests (taken from clojure-indent-test)

This commit is contained in:
Raymond Huang 2018-08-11 00:02:11 -07:00
parent 1162d9de46
commit a7584cab36
2 changed files with 237 additions and 0 deletions

View File

@ -0,0 +1,167 @@
;;; plantuml-mode-indentation-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;; Author: Raymond Huang (rymndhng)
;; Maintainer: Carlo Sciolla (skuro)
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;; Test setup is inspired/taken from clojure-mode-indentation-tests
;;; Code:
;; This is taken from https://github.com/clojure-emacs/clojure-mode/blob/master/test/clojure-mode-indentation-test.el
(defmacro check-indentation (description before after &optional var-bindings)
"Declare an ert test for indentation behaviour.
The test will check that the swift indentation command changes the buffer
from one state to another. It will also test that point is moved to an
expected position.
DESCRIPTION is a symbol describing the test.
BEFORE is the buffer string before indenting, where a pipe (|) represents
point.
AFTER is the expected buffer string after indenting, where a pipe (|)
represents the expected position of point.
VAR-BINDINGS is an optional let-bindings list. It can be used to set the
values of customisable variables."
(declare (indent 1))
(let ((fname (intern (format "indentation/%s" description))))
`(ert-deftest ,fname ()
(let* ((after ,after)
(clojure-indent-style :always-align)
(expected-cursor-pos (1+ (s-index-of "|" after)))
(expected-state (delete ?| after))
,@var-bindings)
(with-temp-buffer
(insert ,before)
(goto-char (point-min))
(search-forward "|")
(delete-char -1)
(plantuml-mode)
(indent-according-to-mode)
(should (equal expected-state (buffer-string)))
(should (equal expected-cursor-pos (point))))))))
(check-indentation toplevel-relationship
"|Nobody -> [APIGateway]"
"|Nobody -> [APIGateway]")
(check-indentation package-block
"package APackage {
|A -> B
}" "package APackage {
|A -> B
}")
(check-indentation nested-package
"package APackage {
|package AnotherPackage {
}
}"
"package APackage {
|package AnotherPackage {
}
}")
(check-indentation empty-package
"|package Foo {}"
"|package Foo {}")
(check-indentation relative-indent
"package APackage {
database Foo
|A --> B
}
}"
"package APackage {
database Foo
|A --> B
}
}"
)
(check-indentation note-as
"note as N1
|This is a note
end note"
"note as N1
|This is a note
end note"
)
(check-indentation note-of
"note right of Foo
|This is a note
end note"
"note right of Foo
|This is a note
end note"
)
(check-indentation alt
"alt choice 1
|A -> B
end
"
"alt choice 1
|A -> B
end
")
(check-indentation alt-end
"alt choice 1
A -> B
|end
"
"alt choice 1
A -> B
|end
")
(check-indentation alt-else
"alt choice 1
|else
end
"
"alt choice 1
|else
end
")
(check-indentation alt-else-body
"alt choice 1
else
|A -> B
end
"
"alt choice 1
else
|A -> B
end
")
(check-indentation alt-else-end
"alt choice 1
else
|end
"
"alt choice 1
else
|end
")
(check-indentation alt-else-body
"alt choice 1
else
|A -> B
end
"
"alt choice 1
else
|A -> B
end
")
(provide 'plantuml-indentation-test)
;;; plantuml-mode-preview-test.el ends here

View File

@ -0,0 +1,70 @@
/' This is a manual test for you to test different use-cases '/
Nobody -> [APIGateway]
package APackage {
A -> B
B -> A
}
package "APP Stack" {
[APIGateway] --> [Lambda]
}
package haha {}
package "Streams Stack" {
database Kinesis
[Lambda] --> Kinesis
}
package foo {
package bar {
foo --> bar
}
package bar {
foo --> bar
}
}
package "Roles And Policies" {
[Lambda] --> [IAM Roles]
[APIGateway] --> [IAM Roles]
}
package "SharedResources" {
[Lambda] ----> [LambdaCodeBucket]
note as N1
This belongs to a separate set
of resources we should clean up
separately.
end note
}
note right of Lambda
This thing is end of life
end note
note left of Nobody
There is no traffic coming
into the service.
end note
@startuml
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
@enduml