Skip to content

Commit ad60c70

Browse files
committed
test: cover enum split empty case ordering
Symptom: targeted roundtrip auditing found enum splits where an explicit `(empty)` case or an empty-body grouped case could drift relative to named cases after describe/exec/describe. Root cause: the enum split PR already encoded authored branch order, but it did not have direct regression coverage for `(empty)` before named cases or grouped empty-body cases before terminal cases. Fix: add synthetic describer/builder roundtrip tests for those two ordering shapes without using project-specific microflow names. Tests: make lint-go; make test.
1 parent f3c1004 commit ad60c70

1 file changed

Lines changed: 110 additions & 0 deletions

File tree

mdl/executor/cmd_microflows_describe_enum_split_test.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77
"testing"
88

9+
"github.com/mendixlabs/mxcli/mdl/ast"
910
"github.com/mendixlabs/mxcli/model"
1011
"github.com/mendixlabs/mxcli/sdk/microflows"
1112
)
@@ -108,6 +109,115 @@ func TestTraverseFlow_EnumSplitPreservesExplicitCaseOrder(t *testing.T) {
108109
}
109110
}
110111

112+
func TestEnumSplitRoundtripPreservesEmptyCaseBeforeNamedCases(t *testing.T) {
113+
out := describeBuiltEnumSplitBody(t, []ast.MicroflowStatement{
114+
&ast.EnumSplitStmt{
115+
Variable: "ImageKind",
116+
Cases: []ast.EnumSplitCase{
117+
{
118+
Value: "(empty)",
119+
Body: []ast.MicroflowStatement{
120+
&ast.LogStmt{
121+
Level: ast.LogError,
122+
Message: &ast.LiteralExpr{Kind: ast.LiteralString, Value: "missing kind"},
123+
Annotations: &ast.ActivityAnnotations{Position: &ast.Position{X: -300, Y: -200}},
124+
},
125+
},
126+
},
127+
{
128+
Value: "Cover",
129+
Body: []ast.MicroflowStatement{
130+
&ast.LogStmt{
131+
Level: ast.LogInfo,
132+
Message: &ast.LiteralExpr{Kind: ast.LiteralString, Value: "cover"},
133+
Annotations: &ast.ActivityAnnotations{Position: &ast.Position{X: -300, Y: 100}},
134+
},
135+
},
136+
},
137+
{
138+
Value: "Logo",
139+
Body: []ast.MicroflowStatement{
140+
&ast.LogStmt{
141+
Level: ast.LogInfo,
142+
Message: &ast.LiteralExpr{Kind: ast.LiteralString, Value: "logo"},
143+
Annotations: &ast.ActivityAnnotations{Position: &ast.Position{X: -300, Y: -40}},
144+
},
145+
},
146+
},
147+
},
148+
},
149+
})
150+
151+
assertOrder(t, out, "case (empty)", "case Cover", "case Logo")
152+
}
153+
154+
func TestEnumSplitRoundtripPreservesEmptyGroupedCaseBeforeTerminalCase(t *testing.T) {
155+
out := describeBuiltEnumSplitBody(t, []ast.MicroflowStatement{
156+
&ast.EnumSplitStmt{
157+
Variable: "Event/Type",
158+
Cases: []ast.EnumSplitCase{
159+
{
160+
Values: []string{"CREATE", "DELETE"},
161+
},
162+
{
163+
Value: "UPDATE",
164+
Body: []ast.MicroflowStatement{
165+
&ast.LogStmt{Level: ast.LogInfo, Message: &ast.LiteralExpr{Kind: ast.LiteralString, Value: "update"}},
166+
&ast.ReturnStmt{},
167+
},
168+
},
169+
{
170+
Value: "(empty)",
171+
Body: []ast.MicroflowStatement{
172+
&ast.LogStmt{
173+
Level: ast.LogInfo,
174+
Message: &ast.LiteralExpr{Kind: ast.LiteralString, Value: "empty"},
175+
Annotations: &ast.ActivityAnnotations{
176+
Anchor: &ast.FlowAnchors{From: ast.AnchorSideBottom, To: ast.AnchorSideTop},
177+
},
178+
},
179+
&ast.ReturnStmt{
180+
Annotations: &ast.ActivityAnnotations{
181+
Anchor: &ast.FlowAnchors{To: ast.AnchorSideTop},
182+
},
183+
},
184+
},
185+
},
186+
},
187+
},
188+
&ast.LogStmt{Level: ast.LogInfo, Message: &ast.LiteralExpr{Kind: ast.LiteralString, Value: "shared tail"}},
189+
})
190+
191+
assertOrder(t, out, "case CREATE, DELETE", "case UPDATE", "case (empty)")
192+
}
193+
194+
func describeBuiltEnumSplitBody(t *testing.T, body []ast.MicroflowStatement) string {
195+
t.Helper()
196+
197+
fb := &flowBuilder{posX: 100, posY: 100, spacing: HorizontalSpacing, measurer: &layoutMeasurer{}}
198+
oc := fb.buildFlowGraph(body, nil)
199+
mf := &microflows.Microflow{ObjectCollection: oc}
200+
e := newTestExecutor()
201+
202+
return strings.Join(formatMicroflowActivities(e.newExecContext(t.Context()), mf, nil, nil), "\n")
203+
}
204+
205+
func assertOrder(t *testing.T, out string, items ...string) {
206+
t.Helper()
207+
208+
lastIdx := -1
209+
for _, item := range items {
210+
idx := strings.Index(out, item)
211+
if idx == -1 {
212+
t.Fatalf("missing %q in output:\n%s", item, out)
213+
}
214+
if idx < lastIdx {
215+
t.Fatalf("expected %q after previous item in output:\n%s", item, out)
216+
}
217+
lastIdx = idx
218+
}
219+
}
220+
111221
func assertContainsAny(t *testing.T, lines []string, want string) {
112222
t.Helper()
113223
for _, line := range lines {

0 commit comments

Comments
 (0)