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

Function TestMatchCodeGen_GuardCondition

pkg/codegen/match_test.go:237–277  ·  view source on GitHub ↗

TestMatchCodeGen_GuardCondition tests guard condition generation.

(t *testing.T)

Source from the content-addressed store, hash-verified

235
236// TestMatchCodeGen_GuardCondition tests guard condition generation.
237func 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.
280func TestMatchCodeGen_MatchExpression(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