mermaid_markdown_api/
md_api.rs1use crate::objects::node::Node;
2use crate::syntax::{CoreSyntaxFunctions, FlowDirection};
3
4pub struct MdAPI<T: CoreSyntaxFunctions> {
5 schema: T,
6 hierarchy_root: Node,
7}
8
9impl<T: CoreSyntaxFunctions> MdAPI<T> {
10 pub fn new(
11 flow_direction: FlowDirection,
12 hierarchy_root: Node,
13 ) -> Self {
14 MdAPI {
15 schema: T::new(flow_direction),
16 hierarchy_root,
17 }
18 }
19
20 pub fn parse_hierarchy(&mut self) -> String {
21 self.hierarchy_root.traverse(&mut self.schema);
22
23 self.schema.return_schema()
24 }
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30 use crate::objects::connection::{Connection, ConnectionType};
31 use crate::objects::node::{ActionType, ScopeType};
32 use crate::syntax::flow_chart::FlowChart;
33
34 #[test]
35 fn it_works() {
36 let hierarchy_tree_root = Node {
37 name: "function_a".to_string(),
38 scope: ScopeType::Public,
39 action: ActionType::Mutation,
40 connections: vec![
41 Connection {
42 connection_type: ConnectionType::Emission,
43 node: Node {
44 name: "function_a_event".to_string(),
45 scope: ScopeType::Public,
46 action: ActionType::Event,
47 connections: vec![],
48 },
49 },
50 Connection {
51 connection_type: ConnectionType::DirectConnection,
52 node: Node {
53 name: "function_b_private".to_string(),
54 scope: ScopeType::Private,
55 action: ActionType::Mutation,
56 connections: vec![],
57 },
58 },
59 ],
60 };
61
62 let mut api = MdAPI::<FlowChart>::new(FlowDirection::TD, hierarchy_tree_root);
63
64 let result = api.parse_hierarchy();
65
66 let expected_string = r#"flowchart TD
67 function_a{{function_a}}:::Public --> function_a_event>function_a_event]:::Public
68 function_a{{function_a}}:::Public --> function_b_private{{function_b_private}}:::Private"#;
69
70 assert_eq!(result, expected_string);
71 }
72}