MCPcopy Create free account
hub / github.com/LissaGreense/GO4SQL / TestParseDeleteCommand

Function TestParseDeleteCommand

parser/parser_test.go:246–289  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

244}
245
246func TestParseDeleteCommand(t *testing.T) {
247 input := "DELETE FROM colName1 WHERE colName2 EQUAL 6462389;"
248 expectedDeleteCommand := ast.DeleteCommand{
249 Token: token.Token{Type: token.DELETE, Literal: "DELETE"},
250 Name: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "colName1"}},
251 }
252 expectedWhereCommand := ast.ConditionExpression{
253 Left: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "colName2"}},
254 Right: ast.Anonymitifier{Token: token.Token{Type: token.LITERAL, Literal: "6462389"}},
255 Condition: token.Token{Type: token.EQUAL, Literal: "EQUAL"},
256 }
257
258 lexer := lexer.RunLexer(input)
259 parserInstance := New(lexer)
260 sequences, err := parserInstance.ParseSequence()
261 if err != nil {
262 t.Fatalf("Got error from parser: %s", err)
263 }
264
265 if len(sequences.Commands) != 1 {
266 t.Fatalf("sequences does not contain 1 statements. got=%d", len(sequences.Commands))
267 }
268
269 actualDeleteCommand, ok := sequences.Commands[0].(*ast.DeleteCommand)
270 if !ok {
271 t.Errorf("actualDeleteCommand is not %T. got=%T", &ast.DeleteCommand{}, sequences.Commands[0])
272 }
273
274 if expectedDeleteCommand.TokenLiteral() != actualDeleteCommand.TokenLiteral() {
275 t.Errorf("TokenLiteral of DeleteCommand is not %s. got=%s", expectedDeleteCommand.TokenLiteral(), actualDeleteCommand.TokenLiteral())
276 }
277
278 if expectedDeleteCommand.Name.GetToken().Literal != actualDeleteCommand.Name.GetToken().Literal {
279 t.Errorf("Table name of DeleteCommand is not %s. got=%s", expectedDeleteCommand.Name.GetToken().Literal, actualDeleteCommand.Name.GetToken().Literal)
280 }
281
282 if !actualDeleteCommand.HasWhereCommand() {
283 t.Fatalf("sequences does not contain where command")
284 }
285
286 if !whereStatementIsValid(t, actualDeleteCommand.WhereCommand, expectedWhereCommand) {
287 return
288 }
289}
290
291func TestParseDropCommand(t *testing.T) {
292 input := "DROP TABLE table;"

Callers

nothing calls this directly

Calls 8

TokenLiteralMethod · 0.95
RunLexerFunction · 0.92
whereStatementIsValidFunction · 0.85
ParseSequenceMethod · 0.80
NewFunction · 0.70
TokenLiteralMethod · 0.65
GetTokenMethod · 0.65
HasWhereCommandMethod · 0.45

Tested by

no test coverage detected