Skip to content

Commit 96840ca

Browse files
cgreenoclaude
andcommitted
test(sequence): mermaid-spec-parity forms for new arrows
Pins the exact inputs mermaid's sequenceDiagram.spec.js and cypress rendering spec use: no-space forms (Alice-xBob:Hello Bob, how are you?), asymmetric spacing, punctuation labels, reversed-direction bidirectional (golden case), and loud rejection of the released central-connection syntax (A ()->>() B) as a documented follow-up. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent a568765 commit 96840ca

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

cmd/testdata/sequence-ascii/bidirectional_arrows.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sequenceDiagram
33
participant B
44
A<<->>B: solid bidirectional
55
A<<-->>B: dotted bidirectional
6+
B<<->>A: reverse solid
67
---
78
+---+ +---+
89
| A | | B |
@@ -14,3 +15,6 @@ sequenceDiagram
1415
| dotted bidirectional
1516
+<.......>|
1617
| |
18+
| reverse solid
19+
|<------->+
20+
| |

cmd/testdata/sequence/bidirectional_arrows.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sequenceDiagram
33
participant B
44
A<<->>B: solid bidirectional
55
A<<-->>B: dotted bidirectional
6+
B<<->>A: reverse solid
67
---
78
┌───┐ ┌───┐
89
│ A │ │ B │
@@ -14,3 +15,6 @@ sequenceDiagram
1415
│ dotted bidirectional
1516
├◄┈┈┈┈┈┈┈►│
1617
│ │
18+
│ reverse solid
19+
│◄───────►┤
20+
│ │

pkg/sequence/arrows_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,55 @@ func TestArrowTypes(t *testing.T) {
4040
}
4141
}
4242

43+
// TestArrowSpecParityForms pins the exact input forms mermaid's own test
44+
// suites use for these arrows (sequenceDiagram.spec.js and the cypress
45+
// rendering spec): no spaces around the arrow or after the colon, punctuation
46+
// in labels, asymmetric spacing, and both message directions.
47+
func TestArrowSpecParityForms(t *testing.T) {
48+
tests := []struct {
49+
in string
50+
want ArrowType
51+
}{
52+
{"sequenceDiagram\nAlice-xBob:Hello Bob, how are you?", SolidCross},
53+
{"sequenceDiagram\nAlice--xBob:Hello Bob, how are you?", DottedCross},
54+
{"sequenceDiagram\nAlice-)Bob:Hello Bob, how are you?", SolidPoint},
55+
{"sequenceDiagram\nAlice--)Bob:Hello Bob, how are you?", DottedPoint},
56+
{"sequenceDiagram\nAlice<<->>Bob:Hello Bob, how are you?", BidirectionalSolid},
57+
{"sequenceDiagram\nAlice<<-->>Bob:Hello Bob, how are you?", BidirectionalDotted},
58+
{"sequenceDiagram\n Bob--x Alice: I am good thanks!", DottedCross},
59+
{"sequenceDiagram\n Alice --x Ola1: Bye!", DottedCross},
60+
{"sequenceDiagram\n John<<->>Alice: This also works the other way", BidirectionalSolid},
61+
}
62+
for _, tt := range tests {
63+
sd, err := Parse(tt.in)
64+
if err != nil {
65+
t.Errorf("Parse(%q): %v", tt.in, err)
66+
continue
67+
}
68+
if len(sd.Messages) != 1 || sd.Messages[0].ArrowType != tt.want {
69+
t.Errorf("Parse(%q): expected 1 message with ArrowType %v, got %+v", tt.in, tt.want, sd.Messages)
70+
}
71+
}
72+
}
73+
74+
// TestCentralConnectionsRejected documents that mermaid's central-connection
75+
// syntax (circle markers at the lifeline: "A ()->>() B", released in mermaid
76+
// 11.16) is rejected loudly rather than silently mis-parsed. It composes with
77+
// every arrow type, so supporting it is its own follow-up.
78+
func TestCentralConnectionsRejected(t *testing.T) {
79+
for _, in := range []string{
80+
"sequenceDiagram\n Alice ()->>() Bob: dual",
81+
"sequenceDiagram\n Alice ()-x() Bob: cross dual",
82+
"sequenceDiagram\n Alice ()<<->>() Bob: bidirectional dual",
83+
"sequenceDiagram\n Alice ->>() Bob: forward",
84+
"sequenceDiagram\n Alice ()->> Bob: reverse",
85+
} {
86+
if _, err := Parse(in); err == nil {
87+
t.Errorf("expected error for central-connection syntax %q, got none", in)
88+
}
89+
}
90+
}
91+
4392
// TestCrossPointBidirectionalArrows checks that mermaid's remaining message
4493
// arrows — cross (-x/--x), async point (-)/--)) and bidirectional
4594
// (<<->>/<<-->>) — parse to the right ArrowType.

0 commit comments

Comments
 (0)