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

Function TestMatchParser_NestedPatterns

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

Source from the content-addressed store, hash-verified

101}
102
103func TestMatchParser_NestedPatterns(t *testing.T) {
104 tests := []struct {
105 name string
106 input string
107 wantPattern string
108 wantNested bool
109 }{
110 {
111 name: "Ok(Some(x))",
112 input: "match wrapped { Ok(Some(x)) => x }",
113 wantPattern: "Ok(Some(x))",
114 wantNested: true,
115 },
116 {
117 name: "Err(Error(code, msg))",
118 input: "match result { Err(Error(code, msg)) => code }",
119 wantPattern: "Err(Error(code, msg))",
120 wantNested: true,
121 },
122 {
123 name: "Ok(Some(Ok(value)))",
124 input: "match deep { Ok(Some(Ok(value))) => value }",
125 wantPattern: "Ok(Some(Ok(value)))",
126 wantNested: true,
127 },
128 {
129 name: "tuple with nested",
130 input: "match pair { (Ok(x), Err(e)) => x }",
131 wantPattern: "(Ok(x), Err(e))",
132 wantNested: true,
133 },
134 }
135
136 for _, tt := range tests {
137 t.Run(tt.name, func(t *testing.T) {
138 tok := tokenizer.New([]byte(tt.input))
139 _, err := tok.Tokenize()
140 if err != nil {
141 t.Fatalf("tokenize error: %v", err)
142 }
143
144 parser := NewMatchParser(tok)
145 expr, err := parser.ParseMatchExpr()
146 if err != nil {
147 t.Fatalf("parse error: %v", err)
148 }
149
150 if len(expr.Arms) == 0 {
151 t.Fatal("no arms parsed")
152 }
153
154 gotPattern := expr.Arms[0].Pattern.String()
155 if gotPattern != tt.wantPattern {
156 t.Errorf("got pattern %q, want %q", gotPattern, tt.wantPattern)
157 }
158
159 // Verify nesting by checking pattern structure
160 if tt.wantNested {

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected