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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user