feat: format SQL code via sqlparse in the /format endpoint

This commit is contained in:
2026-07-05 00:07:20 -06:00
parent 8ca04c2e17
commit 7355610f37
5 changed files with 49 additions and 0 deletions

View File

@@ -31,3 +31,24 @@ def test_format_cpp_uses_allman_braces():
def test_format_unsupported_language_raises():
with pytest.raises(FormatError):
format_code("print(1)", "java")
def test_format_sql_uppercases_keywords():
result = format_code("select * from students where score>60", "sql")
assert result == "SELECT * FROM students WHERE score>60"
def test_format_sql_splits_multiple_statements():
result = format_code(
"delete from students where score<60;insert into students (id) values (9);",
"sql",
)
assert result == (
"DELETE FROM students WHERE score<60;\n\n"
"INSERT INTO students (id) VALUES (9);"
)
def test_format_sql_tolerates_syntax_errors():
result = format_code("select from where", "sql")
assert result == "SELECT FROM WHERE"