feat: format SQL code via sqlparse in the /format endpoint
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user