TestSQLFormatter_BasicFormatting tests basic formatter functionality
(t *testing.T)
| 25 | |
| 26 | // TestSQLFormatter_BasicFormatting tests basic formatter functionality |
| 27 | func TestSQLFormatter_BasicFormatting(t *testing.T) { |
| 28 | tests := []struct { |
| 29 | name string |
| 30 | sql string |
| 31 | indentSpaces int |
| 32 | uppercase bool |
| 33 | expectKeywords []string |
| 34 | shouldSkip bool |
| 35 | }{ |
| 36 | { |
| 37 | name: "simple SELECT with default options", |
| 38 | sql: "SELECT id, name FROM users WHERE active = true", |
| 39 | indentSpaces: 2, |
| 40 | uppercase: false, |
| 41 | expectKeywords: []string{"select", "from", "where"}, |
| 42 | }, |
| 43 | { |
| 44 | name: "SELECT with uppercase keywords", |
| 45 | sql: "select id from users", |
| 46 | indentSpaces: 2, |
| 47 | uppercase: true, |
| 48 | expectKeywords: []string{"SELECT", "FROM"}, |
| 49 | }, |
| 50 | { |
| 51 | name: "SELECT with different indent", |
| 52 | sql: "SELECT id FROM users", |
| 53 | indentSpaces: 4, |
| 54 | uppercase: false, |
| 55 | expectKeywords: []string{"select", "from"}, |
| 56 | }, |
| 57 | } |
| 58 | |
| 59 | for _, tt := range tests { |
| 60 | t.Run(tt.name, func(t *testing.T) { |
| 61 | if tt.shouldSkip { |
| 62 | t.Skip("Skipping due to parser limitations") |
| 63 | } |
| 64 | |
| 65 | // Tokenize and parse |
| 66 | tkz := tokenizer.GetTokenizer() |
| 67 | defer tokenizer.PutTokenizer(tkz) |
| 68 | |
| 69 | tokens, err := tkz.Tokenize([]byte(tt.sql)) |
| 70 | if err != nil { |
| 71 | t.Fatalf("Tokenization failed: %v", err) |
| 72 | } |
| 73 | |
| 74 | p := parser.NewParser() |
| 75 | astObj := ast.NewAST() |
| 76 | defer ast.ReleaseAST(astObj) |
| 77 | |
| 78 | result, err := p.ParseFromModelTokens(tokens) |
| 79 | if err != nil { |
| 80 | t.Skipf("Parsing failed (may not be supported yet): %v", err) |
| 81 | return |
| 82 | } |
| 83 | astObj.Statements = result.Statements |
| 84 |
nothing calls this directly
no test coverage detected