TestMatchCodeGen_GuardCondition tests guard condition generation.
(t *testing.T)
| 235 | |
| 236 | // TestMatchCodeGen_GuardCondition tests guard condition generation. |
| 237 | func TestMatchCodeGen_GuardCondition(t *testing.T) { |
| 238 | match := &ast.MatchExpr{ |
| 239 | Match: 1, |
| 240 | Scrutinee: &ast.RawExpr{ |
| 241 | Text: "result", |
| 242 | }, |
| 243 | Arms: []*ast.MatchArm{ |
| 244 | { |
| 245 | Pattern: &ast.ConstructorPattern{ |
| 246 | Name: "Ok", |
| 247 | Params: []ast.Pattern{ |
| 248 | &ast.VariablePattern{Name: "x"}, |
| 249 | }, |
| 250 | }, |
| 251 | Guard: &ast.RawExpr{Text: "x > 0"}, |
| 252 | GuardPos: 20, |
| 253 | Body: &ast.RawExpr{Text: "x * 2"}, |
| 254 | }, |
| 255 | { |
| 256 | Pattern: &ast.WildcardPattern{}, |
| 257 | Body: &ast.RawExpr{Text: "0"}, |
| 258 | }, |
| 259 | }, |
| 260 | IsExpr: false, |
| 261 | } |
| 262 | |
| 263 | gen := NewMatchCodeGen(match).(*MatchCodeGen) |
| 264 | result := gen.Generate() |
| 265 | |
| 266 | code := string(result.Output) |
| 267 | |
| 268 | // Should contain guard condition |
| 269 | if !strings.Contains(code, "if x > 0") { |
| 270 | t.Errorf("Expected guard condition 'if x > 0', got: %s", code) |
| 271 | } |
| 272 | |
| 273 | // Should have nested body in guard |
| 274 | if !strings.Contains(code, "x * 2") { |
| 275 | t.Errorf("Expected body 'x * 2', got: %s", code) |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | // TestMatchCodeGen_MatchExpression tests IIFE generation for match expressions. |
| 280 | func TestMatchCodeGen_MatchExpression(t *testing.T) { |
nothing calls this directly
no test coverage detected