File: test_query.py

package info (click to toggle)
sqlfmt 0.29.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,580 kB
  • sloc: python: 10,007; sql: 5,626; makefile: 39
file content (24 lines) | stat: -rw-r--r-- 867 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pytest

from sqlfmt.analyzer import Analyzer


def test_whitespace_formatting(default_analyzer: Analyzer) -> None:
    source_string = "  select 1\n    from my_table\nwhere true"
    expected_string = "select 1\nfrom my_table\nwhere true\n"
    q = default_analyzer.parse_query(source_string=source_string)
    assert str(q) == expected_string


def test_only_comment_formatting(default_analyzer: Analyzer) -> None:
    source_string = "-- a comment"
    expected_string = "-- a comment\n"
    q = default_analyzer.parse_query(source_string=source_string)
    assert str(q) == expected_string


@pytest.mark.parametrize("source_string", ["", "\n"])
def test_empty_formatting(default_analyzer: Analyzer, source_string: str) -> None:
    expected_string = ""
    q = default_analyzer.parse_query(source_string=source_string)
    assert str(q) == expected_string