MCPcopy
hub / github.com/MadAppGang/dingo / TestMatchCodeGen_MatchExpression

Function TestMatchCodeGen_MatchExpression

pkg/codegen/match_test.go:280–328  ·  view source on GitHub ↗

TestMatchCodeGen_MatchExpression tests IIFE generation for match expressions.

(t *testing.T)

Source from the content-addressed store, hash-verified

278
279// TestMatchCodeGen_MatchExpression tests IIFE generation for match expressions.
280func TestMatchCodeGen_MatchExpression(t *testing.T) {
281 match := &ast.MatchExpr{
282 Match: 1,
283 Scrutinee: &ast.RawExpr{
284 Text: "result",
285 },
286 Arms: []*ast.MatchArm{
287 {
288 Pattern: &ast.ConstructorPattern{
289 Name: "Ok",
290 Params: []ast.Pattern{
291 &ast.VariablePattern{Name: "value"},
292 },
293 },
294 Body: &ast.RawExpr{Text: "value"},
295 },
296 {
297 Pattern: &ast.ConstructorPattern{
298 Name: "Err",
299 Params: []ast.Pattern{
300 &ast.VariablePattern{Name: "e"},
301 },
302 },
303 Body: &ast.RawExpr{Text: "0"},
304 },
305 },
306 IsExpr: true, // This is an expression
307 }
308
309 gen := NewMatchCodeGen(match).(*MatchCodeGen)
310 result := gen.Generate()
311
312 code := string(result.Output)
313
314 // Should wrap in IIFE
315 if !strings.Contains(code, "func()") {
316 t.Errorf("Expected IIFE wrapper 'func()', got: %s", code)
317 }
318
319 // Should have immediate invocation
320 if !strings.Contains(code, "}()") {
321 t.Errorf("Expected IIFE invocation '}()', got: %s", code)
322 }
323
324 // Should have return statements
325 if !strings.Contains(code, "return") {
326 t.Errorf("Expected return statements in IIFE, got: %s", code)
327 }
328}
329
330// TestMatchCodeGen_EmptyMatch tests handling of empty match expression.
331func TestMatchCodeGen_EmptyMatch(t *testing.T) {

Callers

nothing calls this directly

Calls 4

NewMatchCodeGenFunction · 0.85
ContainsMethod · 0.80
GenerateMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected