(t *testing.T)
| 115 | } |
| 116 | |
| 117 | func 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 |
| 160 | func validFormatSQL(t *testing.T, sql string) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…