Skip to content

Commit

Permalink
utils: fix mermaid output.
Browse files Browse the repository at this point in the history
  • Loading branch information
peteut committed Apr 20, 2020
1 parent e4df86f commit a17e196
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func visualizeForMermaid(fsm *FSM) string {
return sortedEKeys[i].src < sortedEKeys[j].src
})

buf.WriteString(fmt.Sprintf(`graph fsm`))
buf.WriteString("\n")
buf.WriteString("stateDiagram\n")
buf.WriteString(fmt.Sprintln(` [*] -->`, fsm.current))

for _, k := range sortedEKeys {
v := fsm.transitions[k]
buf.WriteString(fmt.Sprintf(` %s -->|%s| %s`, k.src, k.event, v))
buf.WriteString(fmt.Sprintf(` %s --> %s: %s`, k.src, v, k.event))
buf.WriteString("\n")
}

Expand Down
9 changes: 5 additions & 4 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ func TestMermaidOutput(t *testing.T) {
t.Errorf("got error for visualizing with type MERMAID: %s", err)
}
wanted := `
graph fsm
closed -->|open| open
intermediate -->|part-close| closed
open -->|close| closed
stateDiagram
[*] --> closed
closed --> open: open
intermediate --> closed: part-close
open --> closed: close
`
normalizedGot := strings.ReplaceAll(got, "\n", "")
normalizedWanted := strings.ReplaceAll(wanted, "\n", "")
Expand Down

0 comments on commit a17e196

Please sign in to comment.