TestSQLFormatter_DDLStatements tests DDL statement formatting
(t *testing.T)
| 352 | |
| 353 | // TestSQLFormatter_DDLStatements tests DDL statement formatting |
| 354 | func TestSQLFormatter_DDLStatements(t *testing.T) { |
| 355 | tests := []struct { |
| 356 | name string |
| 357 | sql string |
| 358 | expectWords []string |
| 359 | }{ |
| 360 | { |
| 361 | name: "CREATE TABLE", |
| 362 | sql: "CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(100))", |
| 363 | expectWords: []string{"create", "table"}, |
| 364 | }, |
| 365 | { |
| 366 | name: "ALTER TABLE", |
| 367 | sql: "ALTER TABLE users ADD COLUMN email VARCHAR(255)", |
| 368 | expectWords: []string{"alter", "table"}, |
| 369 | }, |
| 370 | { |
| 371 | name: "DROP TABLE", |
| 372 | sql: "DROP TABLE temp_data", |
| 373 | expectWords: []string{"drop", "table"}, |
| 374 | }, |
| 375 | } |
| 376 | |
| 377 | for _, tt := range tests { |
| 378 | t.Run(tt.name, func(t *testing.T) { |
| 379 | tkz := tokenizer.GetTokenizer() |
| 380 | defer tokenizer.PutTokenizer(tkz) |
| 381 | |
| 382 | tokens, err := tkz.Tokenize([]byte(tt.sql)) |
| 383 | if err != nil { |
| 384 | t.Fatalf("Tokenization failed: %v", err) |
| 385 | } |
| 386 | |
| 387 | p := parser.NewParser() |
| 388 | astObj := ast.NewAST() |
| 389 | defer ast.ReleaseAST(astObj) |
| 390 | |
| 391 | result, err := p.ParseFromModelTokens(tokens) |
| 392 | if err != nil { |
| 393 | t.Skipf("Parsing failed (may not be supported yet): %v", err) |
| 394 | return |
| 395 | } |
| 396 | astObj.Statements = result.Statements |
| 397 | |
| 398 | formatter := NewSQLFormatter(FormatterOptions{ |
| 399 | Indent: " ", |
| 400 | UppercaseKw: false, |
| 401 | }) |
| 402 | |
| 403 | output, err := formatter.Format(astObj) |
| 404 | if err != nil { |
| 405 | t.Fatalf("Formatting failed: %v", err) |
| 406 | } |
| 407 | |
| 408 | for _, word := range tt.expectWords { |
| 409 | if !strings.Contains(strings.ToLower(output), word) { |
| 410 | t.Errorf("Expected '%s' in output:\n%s", word, output) |
| 411 | } |
nothing calls this directly
no test coverage detected