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

Function TestMatchCodeGen_NoConstructorPatterns

pkg/codegen/match_test.go:341–382  ·  view source on GitHub ↗

TestMatchCodeGen_NoConstructorPatterns tests value switch for non-constructor patterns.

(t *testing.T)

Source from the content-addressed store, hash-verified

339
340// TestMatchCodeGen_NoConstructorPatterns tests value switch for non-constructor patterns.
341func TestMatchCodeGen_NoConstructorPatterns(t *testing.T) {
342 match := &ast.MatchExpr{
343 Match: 1,
344 Scrutinee: &ast.RawExpr{
345 Text: "status",
346 },
347 Arms: []*ast.MatchArm{
348 {
349 Pattern: &ast.LiteralPattern{
350 Value: "\"active\"",
351 Kind: ast.StringLiteral,
352 },
353 Body: &ast.RawExpr{Text: "1"},
354 },
355 {
356 Pattern: &ast.WildcardPattern{},
357 Body: &ast.RawExpr{Text: "0"},
358 },
359 },
360 IsExpr: false,
361 }
362
363 gen := NewMatchCodeGen(match).(*MatchCodeGen)
364 result := gen.Generate()
365
366 code := string(result.Output)
367
368 // Should use value switch, not type switch
369 if strings.Contains(code, ".(type)") {
370 t.Errorf("Expected value switch (no type assertion), got: %s", code)
371 }
372
373 // Should have value caching
374 if !strings.Contains(code, "val := status") {
375 t.Errorf("Expected value caching, got: %s", code)
376 }
377
378 // Should have switch statement using cached variable
379 if !strings.Contains(code, "switch val") {
380 t.Errorf("Expected switch using cached val, got: %s", code)
381 }
382}
383
384// =============================================================================
385// Value Enum Match Tests (Phase 3)

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