TestMatchCodeGen_WildcardPattern tests wildcard pattern generation.
(t *testing.T)
| 167 | |
| 168 | // TestMatchCodeGen_WildcardPattern tests wildcard pattern generation. |
| 169 | func 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. |
| 203 | func TestMatchCodeGen_VariablePattern(t *testing.T) { |
nothing calls this directly
no test coverage detected