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

Function TestParser_Format

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

Source from the content-addressed store, hash-verified

72}
73
74func TestParser_Format(t *testing.T) {
75 for _, dir := range []string{"./testdata/dml", "./testdata/ddl", "./testdata/query", "./testdata/basic"} {
76 outputDir := dir + "/format"
77
78 entries, err := os.ReadDir(dir)
79 if err != nil {
80 require.NoError(t, err)
81 }
82 for _, entry := range entries {
83 if !strings.HasSuffix(entry.Name(), ".sql") {
84 continue
85 }
86 t.Run(entry.Name(), func(t *testing.T) {
87 fileBytes, err := os.ReadFile(filepath.Join(dir, entry.Name()))
88 require.NoError(t, err)
89 parser := Parser{
90 lexer: NewLexer(string(fileBytes)),
91 }
92 stmts, err := parser.ParseStmts()
93 require.NoError(t, err)
94 var builder strings.Builder
95 builder.WriteString("-- Origin SQL:\n")
96 builder.Write(fileBytes)
97 builder.WriteString("\n\n-- Format SQL:\n")
98 var formatSQLBuilder strings.Builder
99 for _, stmt := range stmts {
100 formatSQLBuilder.WriteString(Format(stmt))
101 formatSQLBuilder.WriteByte(';')
102 formatSQLBuilder.WriteByte('\n')
103 }
104 formatSQL := formatSQLBuilder.String()
105 builder.WriteString(formatSQL)
106 validFormatSQL(t, formatSQL)
107 g := goldie.New(t,
108 goldie.WithNameSuffix(""),
109 goldie.WithDiffEngine(goldie.ColoredDiff),
110 goldie.WithFixtureDir(outputDir))
111 g.Assert(t, entry.Name(), []byte(builder.String()))
112 })
113 }
114 }
115}
116
117func TestParser_FormatBeautify(t *testing.T) {
118 for _, dir := range []string{"./testdata/dml", "./testdata/ddl", "./testdata/query", "./testdata/basic"} {

Callers

nothing calls this directly

Calls 7

ParseStmtsMethod · 0.95
NewLexerFunction · 0.85
FormatFunction · 0.85
validFormatSQLFunction · 0.85
WriteStringMethod · 0.80
WriteByteMethod · 0.80
StringMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…