forked from mendixlabs/mxcli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_microflows_builder_terminal_test.go
More file actions
99 lines (87 loc) · 2.82 KB
/
cmd_microflows_builder_terminal_test.go
File metadata and controls
99 lines (87 loc) · 2.82 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// SPDX-License-Identifier: Apache-2.0
package executor
import (
"testing"
"github.com/mendixlabs/mxcli/mdl/ast"
)
func TestLastStmtIsReturn_EmptyBody(t *testing.T) {
if lastStmtIsReturn(nil) {
t.Error("empty body must not be terminal")
}
}
func TestLastStmtIsReturn_PlainReturn(t *testing.T) {
body := []ast.MicroflowStatement{&ast.ReturnStmt{}}
if !lastStmtIsReturn(body) {
t.Error("body ending in ReturnStmt must be terminal")
}
}
func TestLastStmtIsReturn_RaiseError(t *testing.T) {
body := []ast.MicroflowStatement{&ast.RaiseErrorStmt{}}
if !lastStmtIsReturn(body) {
t.Error("body ending in RaiseErrorStmt must be terminal")
}
}
func TestLastStmtIsReturn_IfWithoutElse_NotTerminal(t *testing.T) {
body := []ast.MicroflowStatement{
&ast.IfStmt{ThenBody: []ast.MicroflowStatement{&ast.ReturnStmt{}}},
}
if lastStmtIsReturn(body) {
t.Error("IF without ELSE must not be terminal (false path falls through)")
}
}
func TestLastStmtIsReturn_IfBothBranchesReturn_Terminal(t *testing.T) {
body := []ast.MicroflowStatement{
&ast.IfStmt{
ThenBody: []ast.MicroflowStatement{&ast.ReturnStmt{}},
ElseBody: []ast.MicroflowStatement{&ast.ReturnStmt{}},
},
}
if !lastStmtIsReturn(body) {
t.Error("IF/ELSE where both branches return must be terminal")
}
}
func TestLastStmtIsReturn_IfOnlyThenReturns_NotTerminal(t *testing.T) {
body := []ast.MicroflowStatement{
&ast.IfStmt{
ThenBody: []ast.MicroflowStatement{&ast.ReturnStmt{}},
ElseBody: []ast.MicroflowStatement{&ast.LogStmt{}}, // non-terminal
},
}
if lastStmtIsReturn(body) {
t.Error("IF/ELSE where only THEN terminates must not be terminal")
}
}
func TestLastStmtIsReturn_NestedIfChain_Terminal(t *testing.T) {
// if { return } else if { return } else { return }
inner := &ast.IfStmt{
ThenBody: []ast.MicroflowStatement{&ast.ReturnStmt{}},
ElseBody: []ast.MicroflowStatement{&ast.ReturnStmt{}},
}
outer := &ast.IfStmt{
ThenBody: []ast.MicroflowStatement{&ast.ReturnStmt{}},
ElseBody: []ast.MicroflowStatement{inner},
}
if !lastStmtIsReturn([]ast.MicroflowStatement{outer}) {
t.Error("else-if chain where every terminal branch returns must be terminal")
}
}
func TestLastStmtIsReturn_RaiseErrorMixed_Terminal(t *testing.T) {
body := []ast.MicroflowStatement{
&ast.IfStmt{
ThenBody: []ast.MicroflowStatement{&ast.ReturnStmt{}},
ElseBody: []ast.MicroflowStatement{&ast.RaiseErrorStmt{}},
},
}
if !lastStmtIsReturn(body) {
t.Error("IF/ELSE with return on one side and raise error on the other must be terminal")
}
}
func TestLastStmtIsReturn_LoopNotTerminal(t *testing.T) {
// A LOOP whose body only returns is still non-terminal — BREAK can exit.
body := []ast.MicroflowStatement{
&ast.LoopStmt{Body: []ast.MicroflowStatement{&ast.ReturnStmt{}}},
}
if lastStmtIsReturn(body) {
t.Error("LOOP must never be terminal (BREAK path)")
}
}