(t *testing.T)
| 244 | } |
| 245 | |
| 246 | func 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 | |
| 291 | func TestParseDropCommand(t *testing.T) { |
| 292 | input := "DROP TABLE table;" |
nothing calls this directly
no test coverage detected