MCPcopy Create free account
hub / github.com/AfterShip/clickhouse-sql-parser / TestParser_FormatBeautify

Function TestParser_FormatBeautify

parser/parser_test.go:117–157  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

115}
116
117func TestParser_FormatBeautify(t *testing.T) {
118 for _, dir := range []string{"./testdata/dml", "./testdata/ddl", "./testdata/query", "./testdata/basic"} {
119 outputDir := dir + "/format/beautify"
120
121 entries, err := os.ReadDir(dir)
122 if err != nil {
123 require.NoError(t, err)
124 }
125 for _, entry := range entries {
126 if !strings.HasSuffix(entry.Name(), ".sql") {
127 continue
128 }
129 t.Run(entry.Name(), func(t *testing.T) {
130 fileBytes, err := os.ReadFile(filepath.Join(dir, entry.Name()))
131 require.NoError(t, err)
132 parser := Parser{
133 lexer: NewLexer(string(fileBytes)),
134 }
135 stmts, err := parser.ParseStmts()
136 require.NoError(t, err)
137 var builder strings.Builder
138 builder.WriteString("-- Origin SQL:\n")
139 builder.Write(fileBytes)
140 builder.WriteString("\n\n-- Beautify SQL:\n")
141 for _, stmt := range stmts {
142 formatter := NewFormatter()
143 formatter.WithBeautify()
144 formatter.WriteExpr(stmt)
145 builder.WriteString(formatter.String())
146 builder.WriteByte(';')
147 builder.WriteByte('\n')
148 }
149 g := goldie.New(t,
150 goldie.WithNameSuffix(""),
151 goldie.WithDiffEngine(goldie.ColoredDiff),
152 goldie.WithFixtureDir(outputDir))
153 g.Assert(t, entry.Name(), []byte(builder.String()))
154 })
155 }
156 }
157}
158
159// validFormatSQL Verify that the format sql can be re-parsed with consistent results
160func validFormatSQL(t *testing.T, sql string) {

Callers

nothing calls this directly

Calls 8

ParseStmtsMethod · 0.95
WithBeautifyMethod · 0.95
WriteExprMethod · 0.95
StringMethod · 0.95
NewLexerFunction · 0.85
NewFormatterFunction · 0.85
WriteStringMethod · 0.80
WriteByteMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…