///|
test "construct an immutable flowchart with ordinary groups" {
let nodes = [
@flowchart.Node::new("Read", label="Read request", groups=["Work"]),
@flowchart.Node::new("Save", label="Save", groups=["Work"]),
]
let view = @flowchart.Flowchart::new(
"request",
nodes[:],
[@flowchart.Connection::new("save", "Read", "Save")],
direction=LR,
groups=[@flowchart.Group::new("Work")],
notes=[
@flowchart.Note::new("Detail", "Source text", targets=["Read"], groups=[
"Work",
]),
],
)
nodes[0] = @flowchart.Node::new("Changed")
assert_eq(view.nodes[0].id, "Read")
assert_eq(view.lanes.length(), 0)
assert_eq(view.groups[0].id, "Work")
assert_eq(view.connections[0].source, "Read")
assert_eq(@flowchart.validate(view), [])
}///|
test "control role and source identity are explicit values" {
let origin = @flowchart.SourceBinding::new("caller", "actions/0")
let action = @flowchart.Node::new("Review", role=Action, origin~)
let view = @flowchart.Flowchart::new("review", [action], [])
assert_eq(view.nodes[0].role, Action)
assert_eq(view.nodes[0].origin.unwrap().path, "actions/0")
assert_eq(view.nodes[0].origin.unwrap().span, None)
assert_eq(@flowchart.validate(view), [])
assert_true(!@flowchart.validate(view, work_limit=1).is_empty())
}pub struct Branch {
id : String
label : String
members : ReadOnlyArray[String]
condition : String?
origin : SourceBinding?
} derive(Eq, Debug)fn Branch::new(id : String, label? : String, members? : ArrayView[String], condition? : String, origin? : SourceBinding) -> Branchpub struct Connection {
id : String
source : String
target : String
label : String
label_kind : LabelKind
style : LineStyle
source_marker : Marker
target_marker : Marker
min_length : Int
direction : FlowDirection
direction_hint : Direction?
role : ConnectionRole
origin : SourceBinding?
} derive(Eq, Debug)fn Connection::new(id : String, source : String, target : String, label? : String, label_kind? : LabelKind, style? : LineStyle, source_marker? : Marker, target_marker? : Marker, min_length? : Int, direction_hint? : Direction, role? : ConnectionRole, origin? : SourceBinding) -> Connectionpub struct Flowchart {
notes : ReadOnlyArray[Note]
regions : ReadOnlyArray[Region]
id : String
direction : Direction
lanes : ReadOnlyArray[Lane]
groups : ReadOnlyArray[Group]
nodes : ReadOnlyArray[Node]
connections : ReadOnlyArray[Connection]
title : String?
accessibility_title : String?
accessibility_description : String?
} derive(Eq, Debug)fn Flowchart::new(id : String, nodes : ArrayView[Node], connections : ArrayView[Connection], direction? : Direction, lanes? : ArrayView[Lane], groups? : ArrayView[Group], title? : String, accessibility_title? : String, accessibility_description? : String, notes? : ArrayView[Note], regions? : ArrayView[Region]) -> Flowchartpub struct Node {
id : String
label : String
label_kind : LabelKind
shape : String
metadata : ReadOnlyArray[(String, String)]
lane : String?
groups : ReadOnlyArray[String]
properties : RenderProperties?
role : Role
regions : ReadOnlyArray[String]
origin : SourceBinding?
} derive(Eq, Debug)fn Node::new(id : String, label? : String, label_kind? : LabelKind, shape? : String, metadata? : ArrayView[(String, String)], lane? : String, groups? : ArrayView[String], properties? : RenderProperties, role? : Role, regions? : ArrayView[String], origin? : SourceBinding) -> Nodepub struct Note {
id : String
text : String
targets : ReadOnlyArray[String]
connection_targets : ReadOnlyArray[String]
placement : String
groups : ReadOnlyArray[String]
lane : String?
origin : SourceBinding?
} derive(Eq, Debug)pub struct Region {
id : String
kind : RegionKind
parent : String?
entry : String?
exit : String?
members : ReadOnlyArray[String]
branches : ReadOnlyArray[Branch]
condition : String?
join_specification : String?
origin : SourceBinding?
} derive(Eq, Debug)fn Region::new(id : String, kind : RegionKind, parent? : String, entry? : String, exit? : String, members? : ArrayView[String], branches? : ArrayView[Branch], condition? : String, join_specification? : String, origin? : SourceBinding) -> Regionfn RenderProperties::new(link? : String, metadata? : ArrayView[(String, String)]) -> RenderPropertiesfn fresh_id(stem : String, used : ArrayView[String], work_limit? : Int) -> Result[String, Diagnostic]fn validate(model : Flowchart, nodes_limit? : Int, edges_limit? : Int, depth_limit? : Int, work_limit? : Int) -> ReadOnlyArray[Diagnostic]