-
Notifications
You must be signed in to change notification settings - Fork 314
/
mermaid_visualizer_test.go
78 lines (71 loc) · 2.08 KB
/
mermaid_visualizer_test.go
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
package fsm
import (
"fmt"
"strings"
"testing"
)
func TestMermaidOutput(t *testing.T) {
fsmUnderTest := NewFSM(
"closed",
Events{
{Name: "open", Src: []string{"closed"}, Dst: "open"},
{Name: "close", Src: []string{"open"}, Dst: "closed"},
{Name: "part-close", Src: []string{"intermediate"}, Dst: "closed"},
},
Callbacks{},
)
got, err := VisualizeForMermaidWithGraphType(fsmUnderTest, StateDiagram)
if err != nil {
t.Errorf("got error for visualizing with type MERMAID: %s", err)
}
wanted := `
stateDiagram-v2
[*] --> closed
closed --> open: open
intermediate --> closed: part-close
open --> closed: close
`
normalizedGot := strings.ReplaceAll(got, "\n", "")
normalizedWanted := strings.ReplaceAll(wanted, "\n", "")
if normalizedGot != normalizedWanted {
t.Errorf("build mermaid graph failed. \nwanted \n%s\nand got \n%s\n", wanted, got)
fmt.Println([]byte(normalizedGot))
fmt.Println([]byte(normalizedWanted))
}
}
func TestMermaidFlowChartOutput(t *testing.T) {
fsmUnderTest := NewFSM(
"closed",
Events{
{Name: "open", Src: []string{"closed"}, Dst: "open"},
{Name: "part-open", Src: []string{"closed"}, Dst: "intermediate"},
{Name: "part-open", Src: []string{"intermediate"}, Dst: "open"},
{Name: "close", Src: []string{"open"}, Dst: "closed"},
{Name: "part-close", Src: []string{"intermediate"}, Dst: "closed"},
},
Callbacks{},
)
got, err := VisualizeForMermaidWithGraphType(fsmUnderTest, FlowChart)
if err != nil {
t.Errorf("got error for visualizing with type MERMAID: %s", err)
}
wanted := `
graph LR
id0[closed]
id1[intermediate]
id2[open]
id0 --> |open| id2
id0 --> |part-open| id1
id1 --> |part-close| id0
id1 --> |part-open| id2
id2 --> |close| id0
style id0 fill:#00AA00
`
normalizedGot := strings.ReplaceAll(got, "\n", "")
normalizedWanted := strings.ReplaceAll(wanted, "\n", "")
if normalizedGot != normalizedWanted {
t.Errorf("build mermaid graph failed. \nwanted \n%s\nand got \n%s\n", wanted, got)
fmt.Println([]byte(normalizedGot))
fmt.Println([]byte(normalizedWanted))
}
}