mermaid-markdown-api 0.2.0

Generating markdown for mermaid diagrams
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
use crate::objects::connection::{Connection, ConnectionType};
use crate::objects::node::{ActionType, Node};
use crate::syntax::{CoreSyntaxFunctions, FlowDirection, SyntaxConfigFile};
use enum_as_inner::EnumAsInner;
use strum::EnumProperty;
use strum_macros::EnumProperty;

/// The various different shapes enabled by this syntax.
#[derive(EnumProperty, Debug)]
pub enum Shape {
    #[strum(props(Left = "((", Right = "))"))]
    Circle,
    #[strum(props(Left = "{{", Right = "}}"))]
    Hexagon,
    #[strum(props(Left = "[", Right = "]"))]
    Rectangle,
    #[strum(props(Left = ">", Right = "]"))]
    Flag,
}

/// The various different line types enabled by this syntax.
#[derive(EnumProperty, Debug)]
pub enum LineType {
    #[strum(props(Complete = "--", Addition = "-"))]
    Solid,
    #[strum(props(Left = "-.", Right = ".-", Addition = "."))]
    Dashed,
}

/// The various different arrow types enabled by this syntax.
#[derive(AsRefStr, EnumProperty, Debug, Clone, Copy)]
pub enum ArrowType {
    #[strum(props(Left = "<", Right = ">"))]
    Standard,
    #[strum(props(Left = "x", Right = "x"))]
    X,
    #[strum(props(Left = "o", Right = "o"))]
    O,
}

/// The various different arrow directions enabled by this syntax.
#[derive(AsRefStr, Debug)]
pub enum ArrowDirection {
    BiDirectional,
    Left,
    Right,
    None,
}

/// An enum representation of either a [NodeConfig] or a [ConnectionConfig].
#[derive(EnumProperty, EnumAsInner, Debug)]
pub enum ObjectConfig<'a> {
    NodeConfig(NodeConfig<'a>),
    ConnectionConfig(ConnectionConfig),
}

/// A struct representing the possible attributes for a [Node].
#[derive(Debug)]
pub struct NodeConfig<'a> {
    /// The ID that will be assigned to this node
    pub id: &'a str,
    /// An optional class name to assign to the node
    pub class: Option<String>,
    /// The shape of the node
    pub shape: Shape,
    /// The text to be displayed within the node
    pub inner_text: &'a str,
}

/// A struct representing the possible attributes for a [Connection].
#[derive(Debug)]
pub struct ConnectionConfig {
    /// The enum representation of the type of line you want
    pub line_type: LineType,
    /// The enum representation of the type of arrow you want
    pub arrow_type: ArrowType,
    /// The enum representation of the direction you want the arrows to point
    pub arrow_direction: ArrowDirection,
    /// An optional amount of additional flags to increase line length
    pub extra_length_num: Option<u8>,
}

/// This is the root struct for an individual flow chart.
pub struct FlowChart {
    /// This is the data location of the string data for the markdown
    data: String,
}

impl FlowChart {
    /// Creates a [Mermaid.js Dotted/Dashed Line](https://mermaid-js.github.io/mermaid/#/flowchart?id=dotted-link) with the supplied attributes & appends it to the current data of the flow chart struct (i.e. `self.data`).
    ///
    /// # Arguments
    ///
    /// * `extra_length_num` - An optional amount of additional flags to increase line length
    fn add_dashed_line(
        &mut self,
        extra_length_num: Option<u8>,
    ) {
        // Push the left half of the dashed line flag
        self.data
            .push_str(LineType::Dashed.get_str("Left").unwrap());

        // Check to see if an additional length was requested
        if let Some(extra_length_num) = extra_length_num {
            // Range over `extra_length_num` to add the appropriate number of length additions
            for _ in 0..extra_length_num {
                // Add in a `.`
                self.data
                    .push_str(LineType::Dashed.get_str("Addition").unwrap());
            }
        }

        // Push the right half of the dashed line flag
        self.data
            .push_str(LineType::Dashed.get_str("Right").unwrap());
    }

    /// Creates a [Mermaid.js Solid Line](https://mermaid-js.github.io/mermaid/#/flowchart?id=a-link-with-arrow-head) with the supplied attributes & appends it to the current data of the flow chart struct (i.e. `self.data`).
    ///
    /// # Arguments
    ///
    /// * `extra_length_num` - An optional amount of additional flags to increase line length
    fn add_solid_line(
        &mut self,
        extra_length_num: Option<u8>,
    ) {
        // Push the main portion of the solid line flag
        self.data
            .push_str(LineType::Solid.get_str("Complete").unwrap());

        // Check to see if an additional length was requested
        if let Some(extra_length_num) = extra_length_num {
            // Range over `extra_length_num` to add the appropriate number of length additions
            for _ in 0..extra_length_num {
                // Add in a `-`
                self.data
                    .push_str(LineType::Solid.get_str("Addition").unwrap());
            }
        }
    }

    /// Creates a [Mermaid.js Connection Line with no arrow](https://mermaid-js.github.io/mermaid/#/flowchart?id=links-between-nodes) with the supplied attributes & appends it to the current data of the flow chart struct (i.e. `self.data`).
    ///
    /// # Arguments
    ///
    /// * `line_type` - The enum representation of the line type you want
    /// * `extra_length_num` - An optional amount of additional flags to increase line length
    fn add_line(
        &mut self,
        line_type: LineType,
        extra_length_num: Option<u8>,
    ) {
        match line_type {
            LineType::Solid => self.add_solid_line(extra_length_num),
            LineType::Dashed => self.add_dashed_line(extra_length_num),
        }
    }

    /// Creates a [Mermaid.js Arrow](https://mermaid-js.github.io/mermaid/#/flowchart?id=new-arrow-types) with the supplied attributes & appends it to the current data of the flow chart struct (i.e. `self.data`).
    ///
    /// # Arguments
    ///
    /// * `arrow_type` - The enum representation of the arrow type you want
    /// * `arrow_direction` - The enum representation of the direction you want the arrow to
    fn add_arrow(
        &mut self,
        arrow_type: ArrowType,
        arrow_direction: ArrowDirection,
    ) {
        // Get the `arrow_direction` as a str to use as the key for the `ArrowType` enum property to then add the correct arrow flag
        self.data
            .push_str(arrow_type.get_str(arrow_direction.as_ref()).unwrap())
    }

    /// Determines which [Shape] to put in a [NodeConfig].
    ///
    /// # Arguments
    ///
    /// * `node` - The [Node] that is being represented
    fn get_shape_from_node(
        &self,
        node: &Node,
    ) -> Shape {
        match node.action {
            ActionType::Mutation => Shape::Hexagon,
            ActionType::View => Shape::Circle,
            ActionType::Process => Shape::Rectangle,
            ActionType::Event => Shape::Flag,
            ActionType::None => Shape::Rectangle,
        }
    }

    /// Determines which [LineType] & [ArrowType] to put in a [ConnectionConfig].
    ///
    /// # Arguments
    ///
    /// * `connection` - The [Connection] that is being represented
    fn get_line_and_arrow_type_from_connection(
        &self,
        connection: &Connection,
    ) -> (LineType, ArrowType, ArrowDirection) {
        match connection.connection_type {
            ConnectionType::DirectConnection => {
                (LineType::Solid, ArrowType::Standard, ArrowDirection::Right)
            }
            ConnectionType::CrossContractConnection => {
                (LineType::Dashed, ArrowType::Standard, ArrowDirection::Right)
            }
            ConnectionType::Emission => {
                (LineType::Dashed, ArrowType::O, ArrowDirection::None)
            }
        }
    }
}

impl CoreSyntaxFunctions for FlowChart {
    fn new(direction: FlowDirection) -> Self {
        // Instantiate the starting point for the diagram schema
        let mut schema_root = "flowchart ".to_string();

        // Add in `direction`
        schema_root.push_str(direction.as_ref());

        // Instantiate `FlowChart`
        let mut result = FlowChart { data: schema_root };

        // Add a new line
        result.add_linebreak(None);

        result
    }

    fn add_node(
        &mut self,
        node_config: SyntaxConfigFile,
    ) {
        let node_config: NodeConfig = node_config
            .into_flow_chart()
            .unwrap()
            .into_node_config()
            .unwrap();

        // Push the ID
        self.data.push_str(node_config.id);

        // Push the left shape flag
        self.data
            .push_str(node_config.shape.get_str("Left").unwrap());

        // Push the inner text
        self.data.push_str(node_config.inner_text);

        // Push the left shape flag
        self.data
            .push_str(node_config.shape.get_str("Right").unwrap());

        // If a class name was passed push it to `self.data`
        if let Some(class) = node_config.class {
            self.data.push_str(":::");
            self.data.push_str(class.as_str());
        }
    }

    fn add_connection(
        &mut self,
        connection_config: SyntaxConfigFile,
    ) {
        // Unwrap the `SyntaxConfigFile` into the needed `ConnectionConfig`
        let connection_config: ConnectionConfig = connection_config
            .into_flow_chart()
            .unwrap()
            .into_connection_config()
            .unwrap();

        // Push a preceding space
        self.data.push(' ');

        // Depending on the arrow direction wanted make calls to `self.add_arrow` & `self.add_line`
        match connection_config.arrow_direction {
            ArrowDirection::BiDirectional => {
                self.add_arrow(connection_config.arrow_type, ArrowDirection::Left);
                self.add_line(
                    connection_config.line_type,
                    connection_config.extra_length_num,
                );
                self.add_arrow(connection_config.arrow_type, ArrowDirection::Right)
            }
            ArrowDirection::Left => {
                self.add_arrow(
                    connection_config.arrow_type,
                    connection_config.arrow_direction,
                );
                self.add_line(
                    connection_config.line_type,
                    connection_config.extra_length_num,
                )
            }
            ArrowDirection::Right => {
                self.add_line(
                    connection_config.line_type,
                    connection_config.extra_length_num,
                );
                self.add_arrow(
                    connection_config.arrow_type,
                    connection_config.arrow_direction,
                )
            }
            ArrowDirection::None => {
                self.add_line(
                    connection_config.line_type,
                    connection_config.extra_length_num,
                );
            }
        }

        // Push a trailing space
        self.data.push(' ');
    }

    fn add_linebreak(
        &mut self,
        num_of_indents: Option<u8>,
    ) {
        // Get the number of indents to use
        let number_of_indents = num_of_indents.unwrap_or(1);

        // Add the new line
        self.data += "\n";

        // Range over `number_of_indents` to add the appropriate number of tabs
        for _ in 0..number_of_indents {
            // Add in a tab
            self.data += "\t";
        }
    }

    fn build_node_config<'a>(
        &self,
        node: &'a Node,
        id: Option<&'a str>,
    ) -> SyntaxConfigFile<'a> {
        if let Some(id) = id {
           
            // If an ID was passed use it
            SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
                id,
                class: Some(format!("{}-{}",node.scope.as_ref(),node.action.as_ref())),
                shape: self.get_shape_from_node(node),
                inner_text: &node.name,
            }))
        } else {
            // Else use the Node's name
            SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
                id: &node.name,
                class: Some(format!("{}-{}",node.scope.as_ref(),node.action.as_ref())),
                shape: self.get_shape_from_node(node),
                inner_text: &node.name,
            }))
        }
    }

    fn build_connection_config<'a>(
        &self,
        connection: &'a Connection,
        extra_length_num: Option<u8>,
    ) -> SyntaxConfigFile<'a> {
        let (line_type, arrow_type, arrow_direction) =
            self.get_line_and_arrow_type_from_connection(connection);

        SyntaxConfigFile::FlowChart(ObjectConfig::ConnectionConfig(ConnectionConfig {
            line_type,
            arrow_type,
            arrow_direction,
            extra_length_num,
        }))
    }

    fn return_schema(&self) -> String {
        self.data.clone()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_creates_a_circle() {
        // Instantiate the flow chart
        let mut flow_chart = FlowChart::new(FlowDirection::TD);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "A",
            class: None,
            shape: Shape::Circle,
            inner_text: "inner text",
        }));

        // Add the node to check afterwards
        flow_chart.add_node(node_config);

        // The string we are expecting
        let expected = r"flowchart TD
	A((inner text))";

        println!("{}", flow_chart.data);

        assert_eq!(flow_chart.data, expected);
    }

    #[test]
    fn it_creates_a_rectangle() {
        // Instantiate the flow chart
        let mut flow_chart = FlowChart::new(FlowDirection::TD);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "A",
            class: None,
            shape: Shape::Rectangle,
            inner_text: "inner text",
        }));

        // Add the node to check afterwards
        flow_chart.add_node(node_config);

        // The string we are expecting
        let expected = r"flowchart TD
	A[inner text]";

        assert_eq!(flow_chart.data, expected);
    }

    #[test]
    fn it_creates_a_hexagon() {
        // Instantiate the flow chart
        let mut flow_chart = FlowChart::new(FlowDirection::TD);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "A",
            class: None,
            shape: Shape::Hexagon,
            inner_text: "inner text",
        }));

        // Add the node to check afterwards
        flow_chart.add_node(node_config);

        // The string we are expecting
        let expected = r"flowchart TD
	A{{inner text}}";

        assert_eq!(flow_chart.data, expected);
    }

    #[test]
    fn it_creates_a_flag() {
        // Instantiate the flow chart
        let mut flow_chart = FlowChart::new(FlowDirection::TD);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "A",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the node to check afterwards
        flow_chart.add_node(node_config);

        // The string we are expecting
        let expected = r"flowchart TD
	A>inner text]";

        assert_eq!(flow_chart.data, expected);
    }

    #[test]
    fn it_adds_a_dashed_line_with_right_arrow() {
        // Instantiate the flow chart
        let mut flow_chart = FlowChart::new(FlowDirection::TD);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "A",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the beginning node
        flow_chart.add_node(node_config);

        let connection_config =
            SyntaxConfigFile::FlowChart(ObjectConfig::ConnectionConfig(ConnectionConfig {
                line_type: LineType::Dashed,
                arrow_type: ArrowType::Standard,
                arrow_direction: ArrowDirection::Right,
                extra_length_num: None,
            }));

        // Add the line to check afterwards
        flow_chart.add_connection(connection_config);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "B",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the trailing node
        flow_chart.add_node(node_config);

        // The string we are expecting
        let expected = r"flowchart TD
	A>inner text] -..-> B>inner text]";

        assert_eq!(flow_chart.data, expected);
    }

    #[test]
    fn it_adds_a_dashed_line_with_no_arrow() {
        // Instantiate the flow chart
        let mut flow_chart = FlowChart::new(FlowDirection::TD);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "A",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the beginning node
        flow_chart.add_node(node_config);

        let connection_config =
            SyntaxConfigFile::FlowChart(ObjectConfig::ConnectionConfig(ConnectionConfig {
                line_type: LineType::Dashed,
                arrow_type: ArrowType::Standard,
                arrow_direction: ArrowDirection::None,
                extra_length_num: None,
            }));

        // Add the line to check afterwards
        flow_chart.add_connection(connection_config);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "B",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the trailing node
        flow_chart.add_node(node_config);

        // The string we are expecting
        let expected = r"flowchart TD
	A>inner text] -..- B>inner text]";

        assert_eq!(flow_chart.data, expected);
    }

    #[test]
    fn it_adds_a_dashed_line_with_left_arrow() {
        // Instantiate the flow chart
        let mut flow_chart = FlowChart::new(FlowDirection::TD);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "A",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the beginning node
        flow_chart.add_node(node_config);

        let connection_config =
            SyntaxConfigFile::FlowChart(ObjectConfig::ConnectionConfig(ConnectionConfig {
                line_type: LineType::Dashed,
                arrow_type: ArrowType::Standard,
                arrow_direction: ArrowDirection::Left,
                extra_length_num: None,
            }));

        // Add the line to check afterwards
        flow_chart.add_connection(connection_config);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "B",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the trailing node
        flow_chart.add_node(node_config);

        // The string we are expecting
        let expected = r"flowchart TD
	A>inner text] <-..- B>inner text]";

        assert_eq!(flow_chart.data, expected);
    }

    #[test]
    fn it_adds_a_dashed_line_with_bidirectional_arrow() {
        // Instantiate the flow chart
        let mut flow_chart = FlowChart::new(FlowDirection::TD);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "A",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the beginning node
        flow_chart.add_node(node_config);

        let connection_config =
            SyntaxConfigFile::FlowChart(ObjectConfig::ConnectionConfig(ConnectionConfig {
                line_type: LineType::Dashed,
                arrow_type: ArrowType::Standard,
                arrow_direction: ArrowDirection::BiDirectional,
                extra_length_num: None,
            }));

        // Add the line to check afterwards
        flow_chart.add_connection(connection_config);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "B",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the trailing node
        flow_chart.add_node(node_config);

        // The string we are expecting
        let expected = r"flowchart TD
	A>inner text] <-..-> B>inner text]";

        assert_eq!(flow_chart.data, expected);
    }

    #[test]
    fn it_adds_a_dashed_line_with_right_o_arrow() {
        // Instantiate the flow chart
        let mut flow_chart = FlowChart::new(FlowDirection::TD);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "A",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the beginning node
        flow_chart.add_node(node_config);

        let connection_config =
            SyntaxConfigFile::FlowChart(ObjectConfig::ConnectionConfig(ConnectionConfig {
                line_type: LineType::Dashed,
                arrow_type: ArrowType::O,
                arrow_direction: ArrowDirection::Right,
                extra_length_num: None,
            }));

        // Add the line to check afterwards
        flow_chart.add_connection(connection_config);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "B",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the trailing node
        flow_chart.add_node(node_config);

        // The string we are expecting
        let expected = r"flowchart TD
	A>inner text] -..-o B>inner text]";

        assert_eq!(flow_chart.data, expected);
    }

    #[test]
    fn it_adds_a_dashed_line_with_left_o_arrow() {
        // Instantiate the flow chart
        let mut flow_chart = FlowChart::new(FlowDirection::TD);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "A",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the beginning node
        flow_chart.add_node(node_config);

        let connection_config =
            SyntaxConfigFile::FlowChart(ObjectConfig::ConnectionConfig(ConnectionConfig {
                line_type: LineType::Dashed,
                arrow_type: ArrowType::O,
                arrow_direction: ArrowDirection::Left,
                extra_length_num: None,
            }));

        // Add the line to check afterwards
        flow_chart.add_connection(connection_config);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "B",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the trailing node
        flow_chart.add_node(node_config);

        // The string we are expecting
        let expected = r"flowchart TD
	A>inner text] o-..- B>inner text]";

        assert_eq!(flow_chart.data, expected);
    }

    #[test]
    fn it_adds_a_dashed_line_with_bidirectional_o_arrow() {
        // Instantiate the flow chart
        let mut flow_chart = FlowChart::new(FlowDirection::TD);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "A",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the beginning node
        flow_chart.add_node(node_config);

        let connection_config =
            SyntaxConfigFile::FlowChart(ObjectConfig::ConnectionConfig(ConnectionConfig {
                line_type: LineType::Dashed,
                arrow_type: ArrowType::O,
                arrow_direction: ArrowDirection::BiDirectional,
                extra_length_num: None,
            }));

        // Add the line to check afterwards
        flow_chart.add_connection(connection_config);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "B",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the trailing node
        flow_chart.add_node(node_config);

        // The string we are expecting
        let expected = r"flowchart TD
	A>inner text] o-..-o B>inner text]";

        assert_eq!(flow_chart.data, expected);
    }

    #[test]
    fn it_adds_a_dashed_line_with_right_x_arrow() {
        // Instantiate the flow chart
        let mut flow_chart = FlowChart::new(FlowDirection::TD);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "A",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the beginning node
        flow_chart.add_node(node_config);

        let connection_config =
            SyntaxConfigFile::FlowChart(ObjectConfig::ConnectionConfig(ConnectionConfig {
                line_type: LineType::Dashed,
                arrow_type: ArrowType::X,
                arrow_direction: ArrowDirection::Right,
                extra_length_num: None,
            }));

        // Add the line to check afterwards
        flow_chart.add_connection(connection_config);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "B",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the trailing node
        flow_chart.add_node(node_config);

        // The string we are expecting
        let expected = r"flowchart TD
	A>inner text] -..-x B>inner text]";

        assert_eq!(flow_chart.data, expected);
    }

    #[test]
    fn it_adds_a_dashed_line_with_left_x_arrow() {
        // Instantiate the flow chart
        let mut flow_chart = FlowChart::new(FlowDirection::TD);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "A",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the beginning node
        flow_chart.add_node(node_config);

        let connection_config =
            SyntaxConfigFile::FlowChart(ObjectConfig::ConnectionConfig(ConnectionConfig {
                line_type: LineType::Dashed,
                arrow_type: ArrowType::X,
                arrow_direction: ArrowDirection::Left,
                extra_length_num: None,
            }));

        // Add the line to check afterwards
        flow_chart.add_connection(connection_config);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "B",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the trailing node
        flow_chart.add_node(node_config);

        // The string we are expecting
        let expected = r"flowchart TD
	A>inner text] x-..- B>inner text]";

        assert_eq!(flow_chart.data, expected);
    }

    #[test]
    fn it_adds_a_dashed_line_with_bidirectional_x_arrow() {
        // Instantiate the flow chart
        let mut flow_chart = FlowChart::new(FlowDirection::TD);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "A",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the beginning node
        flow_chart.add_node(node_config);

        let connection_config =
            SyntaxConfigFile::FlowChart(ObjectConfig::ConnectionConfig(ConnectionConfig {
                line_type: LineType::Dashed,
                arrow_type: ArrowType::X,
                arrow_direction: ArrowDirection::BiDirectional,
                extra_length_num: None,
            }));

        // Add the line to check afterwards
        flow_chart.add_connection(connection_config);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "B",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the trailing node
        flow_chart.add_node(node_config);

        // The string we are expecting
        let expected = r"flowchart TD
	A>inner text] x-..-x B>inner text]";

        assert_eq!(flow_chart.data, expected);
    }

    #[test]
    fn it_adds_a_dashed_line_with_bidirectional_x_arrow_and_extra_length() {
        // Instantiate the flow chart
        let mut flow_chart = FlowChart::new(FlowDirection::TD);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "A",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the beginning node
        flow_chart.add_node(node_config);

        let connection_config =
            SyntaxConfigFile::FlowChart(ObjectConfig::ConnectionConfig(ConnectionConfig {
                line_type: LineType::Dashed,
                arrow_type: ArrowType::X,
                arrow_direction: ArrowDirection::BiDirectional,
                extra_length_num: Some(1),
            }));

        // Add the line to check afterwards
        flow_chart.add_connection(connection_config);

        let node_config = SyntaxConfigFile::FlowChart(ObjectConfig::NodeConfig(NodeConfig {
            id: "B",
            class: None,
            shape: Shape::Flag,
            inner_text: "inner text",
        }));

        // Add the trailing node
        flow_chart.add_node(node_config);

        // The string we are expecting
        let expected = r"flowchart TD
	A>inner text] x-...-x B>inner text]";

        assert_eq!(flow_chart.data, expected);
    }
}