@@ -219,3 +219,133 @@ func TestContinueStmt(t *testing.T) {
219
219
assert .Equal (t , "" , continueStmt .GetLabel ())
220
220
})
221
221
}
222
+
223
+ func TestYieldStmt (t * testing.T ) {
224
+ t .Run ("ToString with non-empty value" , func (t * testing.T ) {
225
+ yieldStmt := & YieldStmt {
226
+ Value : & Expr {NodeString : "42" },
227
+ }
228
+ assert .Equal (t , "yield 42" , yieldStmt .ToString ())
229
+ })
230
+
231
+ t .Run ("ToString with empty value" , func (t * testing.T ) {
232
+ yieldStmt := & YieldStmt {
233
+ Value : & Expr {NodeString : "" },
234
+ }
235
+ assert .Equal (t , "yield " , yieldStmt .ToString ())
236
+ })
237
+
238
+ t .Run ("ToString with complex expression" , func (t * testing.T ) {
239
+ yieldStmt := & YieldStmt {
240
+ Value : & Expr {NodeString : "a + b * c" },
241
+ }
242
+ assert .Equal (t , "yield a + b * c" , yieldStmt .ToString ())
243
+ })
244
+
245
+ t .Run ("ToString with string literal" , func (t * testing.T ) {
246
+ yieldStmt := & YieldStmt {
247
+ Value : & Expr {NodeString : "\" hello world\" " },
248
+ }
249
+ assert .Equal (t , "yield \" hello world\" " , yieldStmt .ToString ())
250
+ })
251
+ }
252
+
253
+ func TestYieldStmt_GetValue (t * testing.T ) {
254
+ t .Run ("GetValue with non-nil value" , func (t * testing.T ) {
255
+ expr := & Expr {NodeString : "42" }
256
+ yieldStmt := & YieldStmt {
257
+ Value : expr ,
258
+ }
259
+ assert .Equal (t , expr , yieldStmt .GetValue ())
260
+ })
261
+
262
+ t .Run ("GetValue with nil value" , func (t * testing.T ) {
263
+ yieldStmt := & YieldStmt {
264
+ Value : nil ,
265
+ }
266
+ assert .Nil (t , yieldStmt .GetValue ())
267
+ })
268
+
269
+ t .Run ("GetValue with complex expression" , func (t * testing.T ) {
270
+ expr := & Expr {NodeString : "foo() + bar(x, y)" }
271
+ yieldStmt := & YieldStmt {
272
+ Value : expr ,
273
+ }
274
+ assert .Equal (t , expr , yieldStmt .GetValue ())
275
+ })
276
+
277
+ t .Run ("GetValue preserves expression reference" , func (t * testing.T ) {
278
+ expr := & Expr {NodeString : "someValue" }
279
+ yieldStmt := & YieldStmt {
280
+ Value : expr ,
281
+ }
282
+ retrievedExpr := yieldStmt .GetValue ()
283
+ expr .NodeString = "modifiedValue"
284
+ assert .Equal (t , "modifiedValue" , retrievedExpr .NodeString )
285
+ })
286
+ }
287
+
288
+ func TestYieldStmt_GetHalsteadID (t * testing.T ) {
289
+ t .Run ("Returns zero for empty yield statement" , func (t * testing.T ) {
290
+ yieldStmt := & YieldStmt {}
291
+ assert .Equal (t , 0 , yieldStmt .GetHalsteadID ())
292
+ })
293
+
294
+ t .Run ("Returns zero for yield with simple value" , func (t * testing.T ) {
295
+ yieldStmt := & YieldStmt {
296
+ Value : & Expr {NodeString : "42" },
297
+ }
298
+ assert .Equal (t , 0 , yieldStmt .GetHalsteadID ())
299
+ })
300
+
301
+ t .Run ("Returns zero for yield with complex expression" , func (t * testing.T ) {
302
+ yieldStmt := & YieldStmt {
303
+ Value : & Expr {NodeString : "a + b * c" },
304
+ }
305
+ assert .Equal (t , 0 , yieldStmt .GetHalsteadID ())
306
+ })
307
+
308
+ t .Run ("Returns zero for yield with method call" , func (t * testing.T ) {
309
+ yieldStmt := & YieldStmt {
310
+ Value : & Expr {NodeString : "calculateValue()" },
311
+ }
312
+ assert .Equal (t , 0 , yieldStmt .GetHalsteadID ())
313
+ })
314
+ }
315
+
316
+ func TestYieldStmt_GetPP (t * testing.T ) {
317
+ t .Run ("GetPP with numeric value" , func (t * testing.T ) {
318
+ yieldStmt := & YieldStmt {
319
+ Value : & Expr {NodeString : "42" },
320
+ }
321
+ assert .Equal (t , "yield 42" , yieldStmt .GetPP ())
322
+ })
323
+
324
+ t .Run ("GetPP with method call" , func (t * testing.T ) {
325
+ yieldStmt := & YieldStmt {
326
+ Value : & Expr {NodeString : "getValue()" },
327
+ }
328
+ assert .Equal (t , "yield getValue()" , yieldStmt .GetPP ())
329
+ })
330
+
331
+ t .Run ("GetPP with complex expression" , func (t * testing.T ) {
332
+ yieldStmt := & YieldStmt {
333
+ Value : & Expr {NodeString : "x + y * (z - 1)" },
334
+ }
335
+ assert .Equal (t , "yield x + y * (z - 1)" , yieldStmt .GetPP ())
336
+ })
337
+
338
+ t .Run ("GetPP with empty expression" , func (t * testing.T ) {
339
+ yieldStmt := & YieldStmt {
340
+ Value : & Expr {NodeString : "" },
341
+ }
342
+ assert .Equal (t , "yield " , yieldStmt .GetPP ())
343
+ })
344
+
345
+ t .Run ("GetPP with string literal" , func (t * testing.T ) {
346
+ yieldStmt := & YieldStmt {
347
+ Value : & Expr {NodeString : "\" test string\" " },
348
+ }
349
+ assert .Equal (t , "yield \" test string\" " , yieldStmt .GetPP ())
350
+ })
351
+ }
0 commit comments