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

Function TestMatchCodeGen_WildcardPattern

pkg/codegen/match_test.go:169–200  ·  view source on GitHub ↗

TestMatchCodeGen_WildcardPattern tests wildcard pattern generation.

(t *testing.T)

Source from the content-addressed store, hash-verified

167
168// TestMatchCodeGen_WildcardPattern tests wildcard pattern generation.
169func TestMatchCodeGen_WildcardPattern(t *testing.T) {
170 match := &ast.MatchExpr{
171 Match: 1,
172 Scrutinee: &ast.RawExpr{
173 Text: "value",
174 },
175 Arms: []*ast.MatchArm{
176 {
177 Pattern: &ast.WildcardPattern{
178 Pos_: 10,
179 },
180 Body: &ast.RawExpr{Text: "42"},
181 },
182 },
183 IsExpr: false,
184 }
185
186 gen := NewMatchCodeGen(match).(*MatchCodeGen)
187 result := gen.Generate()
188
189 code := string(result.Output)
190
191 // Wildcard should generate default case
192 if !strings.Contains(code, "default:") {
193 t.Errorf("Expected 'default:' for wildcard pattern, got: %s", code)
194 }
195
196 // Should contain body
197 if !strings.Contains(code, "42") {
198 t.Errorf("Expected body '42', got: %s", code)
199 }
200}
201
202// TestMatchCodeGen_VariablePattern tests variable pattern with binding.
203func TestMatchCodeGen_VariablePattern(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