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

Function TestMatchParser_MultipleArms

pkg/matchparser/match_parser_test.go:370–405  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

368}
369
370func TestMatchParser_MultipleArms(t *testing.T) {
371 input := `match result {
372 Ok(x) => x,
373 Err(e) => 0,
374 _ => -1
375 }`
376
377 tok := tokenizer.New([]byte(input))
378 _, err := tok.Tokenize()
379 if err != nil {
380 t.Fatalf("tokenize error: %v", err)
381 }
382
383 parser := NewMatchParser(tok)
384 expr, err := parser.ParseMatchExpr()
385 if err != nil {
386 t.Fatalf("parse error: %v", err)
387 }
388
389 if len(expr.Arms) != 3 {
390 t.Errorf("got %d arms, want 3", len(expr.Arms))
391 }
392
393 // Verify pattern types
394 if _, ok := expr.Arms[0].Pattern.(*ast.ConstructorPattern); !ok {
395 t.Errorf("arm 0 pattern should be ConstructorPattern, got %T", expr.Arms[0].Pattern)
396 }
397
398 if _, ok := expr.Arms[1].Pattern.(*ast.ConstructorPattern); !ok {
399 t.Errorf("arm 1 pattern should be ConstructorPattern, got %T", expr.Arms[1].Pattern)
400 }
401
402 if _, ok := expr.Arms[2].Pattern.(*ast.WildcardPattern); !ok {
403 t.Errorf("arm 2 pattern should be WildcardPattern, got %T", expr.Arms[2].Pattern)
404 }
405}
406
407func TestMatchParser_ComplexScrutinee(t *testing.T) {
408 tests := []struct {

Callers

nothing calls this directly

Calls 6

ParseMatchExprMethod · 0.95
NewFunction · 0.92
NewMatchParserFunction · 0.85
TokenizeMethod · 0.80
FatalfMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected