MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestDelete

Function TestDelete

pkg/sql/ast/dml_test.go:223–296  ·  view source on GitHub ↗

Test Delete node (DML)

(t *testing.T)

Source from the content-addressed store, hash-verified

221
222// Test Delete node (DML)
223func TestDelete(t *testing.T) {
224 tests := []struct {
225 name string
226 del *Delete
227 wantLiteral string
228 minChildren int
229 }{
230 {
231 name: "simple DELETE",
232 del: &Delete{
233 Table: TableReference{Name: "users"},
234 },
235 wantLiteral: "DELETE",
236 minChildren: 1,
237 },
238 {
239 name: "DELETE with WHERE",
240 del: &Delete{
241 Table: TableReference{Name: "users"},
242 Where: &BinaryExpression{
243 Left: &Identifier{Name: "id"},
244 Operator: "=",
245 Right: &LiteralValue{Value: "5"},
246 },
247 },
248 wantLiteral: "DELETE",
249 minChildren: 2,
250 },
251 {
252 name: "DELETE with RETURNING",
253 del: &Delete{
254 Table: TableReference{Name: "users"},
255 ReturningClause: []Expression{&Identifier{Name: "id"}, &Identifier{Name: "name"}},
256 },
257 wantLiteral: "DELETE",
258 minChildren: 3,
259 },
260 {
261 name: "DELETE with WHERE and RETURNING",
262 del: &Delete{
263 Table: TableReference{Name: "users"},
264 Where: &BinaryExpression{
265 Left: &Identifier{Name: "active"},
266 Operator: "=",
267 Right: &LiteralValue{Value: "false"},
268 },
269 ReturningClause: []Expression{&Identifier{Name: "*"}},
270 },
271 wantLiteral: "DELETE",
272 minChildren: 3,
273 },
274 }
275
276 for _, tt := range tests {
277 t.Run(tt.name, func(t *testing.T) {
278 // Test TokenLiteral
279 if got := tt.del.TokenLiteral(); got != tt.wantLiteral {
280 t.Errorf("Delete.TokenLiteral() = %v, want %v", got, tt.wantLiteral)

Callers

nothing calls this directly

Calls 5

RunMethod · 0.80
TokenLiteralMethod · 0.65
ErrorfMethod · 0.65
ChildrenMethod · 0.65
statementNodeMethod · 0.65

Tested by

no test coverage detected