fix: align PLpgSQL formatting clauses
This commit is contained in:
@@ -107,6 +107,66 @@ func TestFormatMmProcBroken(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatIssue1PLpgSQLIndenting(t *testing.T) {
|
||||
src := "CREATE FUNCTION f() RETURNS void LANGUAGE plpgsql AS $$\n" +
|
||||
"DECLARE\n" +
|
||||
" r_lp record;\n" +
|
||||
"BEGIN\n" +
|
||||
" if r_lp.total > 0\n" +
|
||||
" and r_lp.totaldone >= r_lp.total\n" +
|
||||
" then\n" +
|
||||
" update core.process u\n" +
|
||||
" set status = 'done'\n" +
|
||||
" where u.rid_process = r_lp.rid_process\n" +
|
||||
" and nv(u.status) <> 'done';\n" +
|
||||
" elsif r_lp.total > 0\n" +
|
||||
" then\n" +
|
||||
" update core.process u\n" +
|
||||
" set status = 'open'\n" +
|
||||
" where u.rid_process = r_lp.rid_process\n" +
|
||||
" and nv(u.status) <> 'open';\n" +
|
||||
"\n" +
|
||||
" end if;\n" +
|
||||
"$$;\n"
|
||||
|
||||
want := "CREATE FUNCTION f(\n" +
|
||||
")\n" +
|
||||
"RETURNS void\n" +
|
||||
"LANGUAGE plpgsql\n" +
|
||||
"AS\n" +
|
||||
"$$\n" +
|
||||
"DECLARE\n" +
|
||||
" r_lp record;\n" +
|
||||
"BEGIN\n" +
|
||||
" if r_lp.total > 0\n" +
|
||||
" and r_lp.totaldone >= r_lp.total\n" +
|
||||
" then\n" +
|
||||
" update core.process u\n" +
|
||||
" set status = 'done'\n" +
|
||||
" where\n" +
|
||||
" u.rid_process = r_lp.rid_process\n" +
|
||||
" and nv(u.status) <> 'done';\n" +
|
||||
" elsif r_lp.total > 0\n" +
|
||||
" then\n" +
|
||||
" update core.process u\n" +
|
||||
" set status = 'open'\n" +
|
||||
" where\n" +
|
||||
" u.rid_process = r_lp.rid_process\n" +
|
||||
" and nv(u.status) <> 'open';\n" +
|
||||
"\n" +
|
||||
" end if;\n" +
|
||||
"$$;\n"
|
||||
|
||||
got := format(src)
|
||||
if got != want {
|
||||
t.Errorf("issue #1 PL/pgSQL indenting\n--- got ---\n%s\n--- want ---\n%s", got, want)
|
||||
}
|
||||
checkDML(t, "issue #1 PL/pgSQL indenting", got)
|
||||
if !semanticallyEqual(src, got) {
|
||||
t.Errorf("issue #1 PL/pgSQL indenting changed semantics")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCorpusIdempotentAndSafe(t *testing.T) {
|
||||
dir := filepath.Join("..", "..", "testdata", "corpus")
|
||||
entries, err := os.ReadDir(dir)
|
||||
|
||||
Reference in New Issue
Block a user