|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +package executor |
| 4 | + |
| 5 | +import ( |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/mendixlabs/mxcli/mdl/ast" |
| 9 | + "github.com/mendixlabs/mxcli/sdk/microflows" |
| 10 | +) |
| 11 | + |
| 12 | +// TestIfEmptyElseBodyWithContinuingThenEmitsFalseFlowToMerge is a regression |
| 13 | +// guard for CE0079 ("The 'false' condition value should be configured in |
| 14 | +// properties for an outgoing flow"). |
| 15 | +// |
| 16 | +// Pattern: an IF with THEN that continues and an explicitly empty ELSE body. |
| 17 | +// Both branches must feed a merge, but an empty ELSE has no lastElseID to wire. |
| 18 | +func TestIfEmptyElseBodyWithContinuingThenEmitsFalseFlowToMerge(t *testing.T) { |
| 19 | + fb := &flowBuilder{ |
| 20 | + spacing: HorizontalSpacing, |
| 21 | + measurer: &layoutMeasurer{}, |
| 22 | + } |
| 23 | + |
| 24 | + fb.addIfStatement(&ast.IfStmt{ |
| 25 | + Condition: &ast.VariableExpr{Name: "Flag"}, |
| 26 | + ThenBody: []ast.MicroflowStatement{ |
| 27 | + &ast.LogStmt{Level: ast.LogInfo, Message: &ast.LiteralExpr{Kind: ast.LiteralString, Value: "in-then"}}, |
| 28 | + }, |
| 29 | + // The source had an explicit ELSE token, but no statements in that |
| 30 | + // branch. That must still build a false split->merge flow. |
| 31 | + HasElse: true, |
| 32 | + }) |
| 33 | + |
| 34 | + var split *microflows.ExclusiveSplit |
| 35 | + var merge *microflows.ExclusiveMerge |
| 36 | + for _, obj := range fb.objects { |
| 37 | + switch o := obj.(type) { |
| 38 | + case *microflows.ExclusiveSplit: |
| 39 | + split = o |
| 40 | + case *microflows.ExclusiveMerge: |
| 41 | + merge = o |
| 42 | + } |
| 43 | + } |
| 44 | + if split == nil { |
| 45 | + t.Fatal("expected ExclusiveSplit to be created") |
| 46 | + } |
| 47 | + if merge == nil { |
| 48 | + t.Fatal("expected ExclusiveMerge to be created") |
| 49 | + } |
| 50 | + |
| 51 | + var hasFalseFlow bool |
| 52 | + for _, flow := range fb.flows { |
| 53 | + if flow.OriginID != split.ID || flow.DestinationID != merge.ID { |
| 54 | + continue |
| 55 | + } |
| 56 | + if ec, ok := flow.CaseValue.(microflows.EnumerationCase); ok && ec.Value == "false" { |
| 57 | + hasFalseFlow = true |
| 58 | + } |
| 59 | + } |
| 60 | + if !hasFalseFlow { |
| 61 | + t.Fatal("missing split->merge flow with case \"false\"") |
| 62 | + } |
| 63 | +} |
0 commit comments