Dependencies
moon add kokic/uml///|
test "quick start" {
let source =
#|@startuml
#|participant Alice
#|Alice -> Bob : hello
#|@enduml
let svg = @api.render_svg(source)
assert_true(svg.contains("<svg"))
}///|
test "sequence diagram" (it : @test.Test) {
let source =
#|@startuml
#|autonumber
#|actor User
#|participant "Web App" as App
#|participant "Auth Service" as Auth
#|User -> App : sign in
#|App -> Auth : POST /token
#|activate Auth
#|Auth --> App : access token
#|deactivate Auth
#|alt token granted
#|App --> User : welcome page
#|else invalid credentials
#|App --> User : error message
#|end
#|note right of Auth : stateless issuer
#|@enduml
it.write(@api.render_svg(source))
it.snapshot(filename="sequence.svg")
}///|
test "class diagram" (it : @test.Test) {
let source =
#|@startuml
#|interface Shape {
#| + area() : Double
#|}
#|abstract class Polygon {
#| # vertices : Array[Point]
#| + area() : Double
#|}
#|class Circle {
#| - radius : Double
#| + area() : Double
#|}
#|class Point {
#| + x : Double
#| + y : Double
#|}
#|Shape <|.. Polygon
#|Shape <|.. Circle
#|Polygon o-- Point
#|@enduml
it.write(@api.render_svg(source))
it.snapshot(filename="class.svg")
}///|
test "use case diagram" (it : @test.Test) {
let source =
#|@startuml
#|:Customer: --> (Browse catalog)
#|:Customer: --> (Place order)
#|:Sales clerk: --> (Approve order)
#|(Place order) ..> (Approve order) : include
#|@enduml
it.write(@api.render_svg(source))
it.snapshot(filename="usecase.svg")
}///|
test "mindmap diagram" (it : @test.Test) {
let source =
#|@startmindmap
#|* uml
#|** Diagrams
#|*** Sequence
#|*** Class
#|*** Use case
#|** Formats
#|*** JSON
#|*** YAML
#|*** TOML
#|-- Backend
#|--- SVG
#|-- Tooling
#|--- moon test
#|@endmindmap
it.write(@api.render_svg(source))
it.snapshot(filename="mindmap.svg")
}///|
test "json diagram" (it : @test.Test) {
let source =
#|@startjson
#|{
#| "name": "kokic/uml",
#| "version": "0.1.2",
#| "targets": ["wasm", "js", "native"],
#| "diagrams": {
#| "available": 7,
#| "planned": 3
#| }
#|}
#|@endjson
it.write(@api.render_svg(source))
it.snapshot(filename="json.svg")
}///|
test "yaml diagram" (it : @test.Test) {
let source =
#|@startyaml
#|name: uml
#|license: Apache-2.0
#|diagrams:
#| - sequence
#| - class
#| - mindmap
#|render:
#| backend: svg
#| compatible: PlantUML
#|@endyaml
it.write(@api.render_svg(source))
it.snapshot(filename="yaml.svg")
}///|
test "toml diagram" (it : @test.Test) {
let source =
#|@starttoml
#|[package]
#|name = "uml"
#|version = "0.1.2"
#|
#|[render]
#|backend = "svg"
#|targets = ["wasm", "js"]
#|@endtoml
it.write(@api.render_svg(source))
it.snapshot(filename="toml.svg")
}///|
test "dot diagram" (it : @test.Test) {
let source =
#|@startdot
#|digraph G {
#| rankdir=LR;
#| a -> b -> c;
#| a -> c [label="direct"];
#|}
#|@enduml
it.write(@api.render_svg(source))
it.snapshot(filename="dot.svg")
}///|
test "dark sequence diagram" (it : @test.Test) {
let dark = @style.ColorScheme::ColorScheme(
"#e6edf3", // text
"#8b949e", // line
canvas="#0d1117",
participant="#161b22",
activation="#21262d",
lifeline="#30363d",
note="#2d2a1f",
)
let source =
#|@startuml
#|participant "Web App" as App
#|participant "Auth Service" as Auth
#|App -> Auth : POST /token
#|activate Auth
#|Auth --> App : access token
#|deactivate Auth
#|note right of Auth : stateless issuer
#|@enduml
it.write(@api.render_svg(source, color_scheme=dark))
it.snapshot(filename="sequence_dark.svg")
}///|
test "documents expose their detected diagram kind" {
let source =
#|@startmindmap
#|* root
#|@endmindmap
let document = @api.parse(source)
assert_true(document.kind() is Mindmap)
assert_true(document.render_svg().contains("<svg"))
}///|
test "collapsible class members" {
let source =
#|@startuml
#|class User {
#|- secret
#|}
#|@enduml
let svg = @api.render_svg(source, class_member_collapsible=true)
assert_true(svg.contains("<details"))
}moon test # verifies the SVGs are unchanged
moon test --update # regenerates __snapshot__/*.svg after a rendering changeDependencies