(t *testing.T)
| 357 | } |
| 358 | |
| 359 | func TestConvertStatementToJSON(t *testing.T) { |
| 360 | // Create a simple SELECT statement |
| 361 | sqlQuery := "SELECT id, name FROM users WHERE active = true ORDER BY id LIMIT 10" |
| 362 | |
| 363 | tkz := tokenizer.GetTokenizer() |
| 364 | defer tokenizer.PutTokenizer(tkz) |
| 365 | |
| 366 | tokens, err := tkz.Tokenize([]byte(sqlQuery)) |
| 367 | if err != nil { |
| 368 | t.Fatalf("Tokenization failed: %v", err) |
| 369 | } |
| 370 | |
| 371 | p := parser.NewParser() |
| 372 | astObj, err := p.ParseFromModelTokens(tokens) |
| 373 | if err != nil { |
| 374 | t.Fatalf("Parsing failed: %v", err) |
| 375 | } |
| 376 | defer ast.ReleaseAST(astObj) |
| 377 | |
| 378 | if len(astObj.Statements) == 0 { |
| 379 | t.Fatal("Expected at least one statement") |
| 380 | } |
| 381 | |
| 382 | jsonStmt := convertStatementToJSON(astObj.Statements[0]) |
| 383 | |
| 384 | if jsonStmt.Type != "SelectStatement" { |
| 385 | t.Errorf("Expected type 'SelectStatement', got '%s'", jsonStmt.Type) |
| 386 | } |
| 387 | |
| 388 | if jsonStmt.Details == nil { |
| 389 | t.Fatal("Expected details to be present") |
| 390 | } |
| 391 | |
| 392 | // Check for expected details |
| 393 | if hasWhere, ok := jsonStmt.Details["has_where"].(bool); !ok || !hasWhere { |
| 394 | t.Error("Expected has_where to be true") |
| 395 | } |
| 396 | |
| 397 | if hasOrderBy, ok := jsonStmt.Details["has_order_by"].(bool); !ok || !hasOrderBy { |
| 398 | t.Error("Expected has_order_by to be true") |
| 399 | } |
| 400 | |
| 401 | if hasLimit, ok := jsonStmt.Details["has_limit"].(bool); !ok || !hasLimit { |
| 402 | t.Error("Expected has_limit to be true") |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | // testError is a simple error type for testing |
| 407 | type testError struct { |
nothing calls this directly
no test coverage detected