MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestSQLFormatter_BasicFormatting

Function TestSQLFormatter_BasicFormatting

cmd/gosqlx/cmd/sql_formatter_test.go:27–110  ·  view source on GitHub ↗

TestSQLFormatter_BasicFormatting tests basic formatter functionality

(t *testing.T)

Source from the content-addressed store, hash-verified

25
26// TestSQLFormatter_BasicFormatting tests basic formatter functionality
27func 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

Callers

nothing calls this directly

Calls 13

ParseFromModelTokensMethod · 0.95
FormatMethod · 0.95
GetTokenizerFunction · 0.92
PutTokenizerFunction · 0.92
NewParserFunction · 0.92
NewASTFunction · 0.92
ReleaseASTFunction · 0.92
NewSQLFormatterFunction · 0.85
RunMethod · 0.80
TokenizeMethod · 0.80
FatalfMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected