@@ -65,6 +65,157 @@ func TestFormatActivity_WhileLoop(t *testing.T) {
6565 }
6666}
6767
68+ func TestAddLoopStatement_PreservesAnnotatedPosition (t * testing.T ) {
69+ fb := & flowBuilder {
70+ posX : 350 ,
71+ posY : 200 ,
72+ spacing : HorizontalSpacing ,
73+ varTypes : map [string ]string {"Items" : "List of Test.Item" },
74+ declaredVars : map [string ]string {},
75+ measurer : & layoutMeasurer {varTypes : map [string ]string {"Items" : "List of Test.Item" }},
76+ }
77+
78+ stmt := & ast.LoopStmt {
79+ LoopVariable : "Item" ,
80+ ListVariable : "Items" ,
81+ Annotations : & ast.ActivityAnnotations {
82+ Position : & ast.Position {X : 350 , Y : 200 },
83+ },
84+ }
85+
86+ id := fb .addLoopStatement (stmt )
87+ if id == "" {
88+ t .Fatal ("expected loop activity ID" )
89+ }
90+
91+ loop , ok := fb .objects [len (fb .objects )- 1 ].(* microflows.LoopedActivity )
92+ if ! ok {
93+ t .Fatalf ("expected LoopedActivity, got %T" , fb .objects [len (fb .objects )- 1 ])
94+ }
95+ if loop .Position .X != 350 || loop .Position .Y != 200 {
96+ t .Fatalf ("got loop position (%d, %d), want (350, 200)" , loop .Position .X , loop .Position .Y )
97+ }
98+ wantNextX := 350 + loop .Size .Width / 2 + HorizontalSpacing
99+ if fb .posX != wantNextX {
100+ t .Fatalf ("got next posX %d, want %d" , fb .posX , wantNextX )
101+ }
102+ }
103+
104+ func TestAddWhileStatement_PreservesAnnotatedPosition (t * testing.T ) {
105+ fb := & flowBuilder {
106+ posX : 420 ,
107+ posY : 180 ,
108+ spacing : HorizontalSpacing ,
109+ varTypes : map [string ]string {},
110+ declaredVars : map [string ]string {},
111+ measurer : & layoutMeasurer {varTypes : map [string ]string {}},
112+ }
113+
114+ stmt := & ast.WhileStmt {
115+ Condition : & ast.BinaryExpr {
116+ Left : & ast.VariableExpr {Name : "Count" },
117+ Operator : "<" ,
118+ Right : & ast.LiteralExpr {Kind : ast .LiteralInteger , Value : int64 (10 )},
119+ },
120+ Annotations : & ast.ActivityAnnotations {
121+ Position : & ast.Position {X : 420 , Y : 180 },
122+ },
123+ }
124+
125+ id := fb .addWhileStatement (stmt )
126+ if id == "" {
127+ t .Fatal ("expected while activity ID" )
128+ }
129+
130+ loop , ok := fb .objects [len (fb .objects )- 1 ].(* microflows.LoopedActivity )
131+ if ! ok {
132+ t .Fatalf ("expected LoopedActivity, got %T" , fb .objects [len (fb .objects )- 1 ])
133+ }
134+ if loop .Position .X != 420 || loop .Position .Y != 180 {
135+ t .Fatalf ("got while position (%d, %d), want (420, 180)" , loop .Position .X , loop .Position .Y )
136+ }
137+ wantNextX := 420 + loop .Size .Width / 2 + HorizontalSpacing
138+ if fb .posX != wantNextX {
139+ t .Fatalf ("got next posX %d, want %d" , fb .posX , wantNextX )
140+ }
141+ }
142+
143+ func TestAddLogMessageAction_PreservesNodeExpression (t * testing.T ) {
144+ fb := & flowBuilder {
145+ posX : 100 ,
146+ posY : 200 ,
147+ spacing : HorizontalSpacing ,
148+ measurer : & layoutMeasurer {},
149+ }
150+
151+ stmt := & ast.LogStmt {
152+ Level : ast .LogInfo ,
153+ Node : & ast.ConstantRefExpr {
154+ QualifiedName : ast.QualifiedName {Module : "TestModule" , Name : "SecurityLogNode" },
155+ },
156+ Message : & ast.LiteralExpr {Kind : ast .LiteralString , Value : "User added" },
157+ }
158+
159+ id := fb .addLogMessageAction (stmt )
160+ if id == "" {
161+ t .Fatal ("expected log activity ID" )
162+ }
163+
164+ activity , ok := fb .objects [len (fb .objects )- 1 ].(* microflows.ActionActivity )
165+ if ! ok {
166+ t .Fatalf ("expected ActionActivity, got %T" , fb .objects [len (fb .objects )- 1 ])
167+ }
168+
169+ action , ok := activity .Action .(* microflows.LogMessageAction )
170+ if ! ok {
171+ t .Fatalf ("expected LogMessageAction, got %T" , activity .Action )
172+ }
173+
174+ if action .LogNodeName != "@TestModule.SecurityLogNode" {
175+ t .Fatalf ("got log node %q, want %q" , action .LogNodeName , "@TestModule.SecurityLogNode" )
176+ }
177+ }
178+
179+ func TestAddLogMessageAction_TemplateLiteralDoesNotKeepQuotes (t * testing.T ) {
180+ fb := & flowBuilder {
181+ posX : 100 ,
182+ posY : 200 ,
183+ spacing : HorizontalSpacing ,
184+ measurer : & layoutMeasurer {},
185+ }
186+
187+ stmt := & ast.LogStmt {
188+ Level : ast .LogInfo ,
189+ Node : & ast.LiteralExpr {Kind : ast .LiteralString , Value : "App" },
190+ Message : & ast.LiteralExpr {
191+ Kind : ast .LiteralString ,
192+ Value : "Order {1}" ,
193+ },
194+ Template : []ast.TemplateParam {
195+ {Index : 1 , Value : & ast.VariableExpr {Name : "OrderNumber" }},
196+ },
197+ }
198+
199+ id := fb .addLogMessageAction (stmt )
200+ if id == "" {
201+ t .Fatal ("expected log activity ID" )
202+ }
203+
204+ activity , ok := fb .objects [len (fb .objects )- 1 ].(* microflows.ActionActivity )
205+ if ! ok {
206+ t .Fatalf ("expected ActionActivity, got %T" , fb .objects [len (fb .objects )- 1 ])
207+ }
208+
209+ action , ok := activity .Action .(* microflows.LogMessageAction )
210+ if ! ok {
211+ t .Fatalf ("expected LogMessageAction, got %T" , activity .Action )
212+ }
213+
214+ if got := action .MessageTemplate .Translations ["en_US" ]; got != "Order {1}" {
215+ t .Fatalf ("got message template %q, want %q" , got , "Order {1}" )
216+ }
217+ }
218+
68219// =============================================================================
69220// Issue #19: Long type must not be downgraded to Integer
70221// =============================================================================
0 commit comments