feat(format): add PL/pgSQL body formatting and tests

* Implemented formatting for BEGIN...END blocks in PL/pgSQL.
* Added logic to handle indentation and blank lines.
* Introduced tests for broken formatting cases.
This commit is contained in:
2026-06-27 19:10:02 +02:00
parent 6492ab35b7
commit d4e6102932
5 changed files with 406 additions and 193 deletions
+22
View File
@@ -49,6 +49,28 @@ func TestIdempotentSmall(t *testing.T) {
}
}
func TestFormatBodyBroken(t *testing.T) {
dir := filepath.Join("..", "..", "testdata", "corpus")
brokenData, err := os.ReadFile(filepath.Join(dir, "test_a_broken.pgsql"))
if err != nil {
t.Skipf("no test_a_broken.pgsql: %v", err)
}
goldenData, err := os.ReadFile(filepath.Join(dir, "test_a.pgsql"))
if err != nil {
t.Skipf("no test_a.pgsql: %v", err)
}
got := format(string(brokenData))
want := string(goldenData)
if got != want {
t.Errorf("format(test_a_broken) != test_a.pgsql\n--- got ---\n%s\n--- want ---\n%s", got, want)
}
twice := format(got)
if twice != got {
t.Errorf("format(test_a_broken) is not idempotent")
}
}
func TestCorpusIdempotentAndSafe(t *testing.T) {
dir := filepath.Join("..", "..", "testdata", "corpus")
entries, err := os.ReadDir(dir)