Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/sc 61/rationalize testing improve coverage #13

Merged
merged 9 commits into from
Oct 26, 2021
Merged
Prev Previous commit
Next Next commit
improve parser test coverage
  • Loading branch information
tconbeer committed Oct 20, 2021
commit 5fa471c1d5f5a5a61dfb9657b1ba5fc37327366e
21 changes: 21 additions & 0 deletions tests/unit_tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,24 @@ def test_open_paren_parsing(source: str, expected_prefix: str) -> None:
assert (
node.prefix == expected_prefix
), "Open paren prefixed by wrong number of spaces"


def test_dont_parse_twice(monkeypatch: pytest.MonkeyPatch) -> None:
source_string = "select 1, 2, 3 from my_table where a = b"
q = Query.from_source(source_string=source_string, mode=Mode())

assert q.lines and q.tokens

# should raise a name error if we parse source again
monkeypatch.delattr("sqlfmt.dialect.Postgres.tokenize_line")
q.tokenize_from_source()
assert q.lines and q.tokens


def test_unterminated_multiline_token() -> None:
source_string = "{% \n config = {}\n"

with pytest.raises(ValueError) as excinfo:
_ = Query.from_source(source_string=source_string, mode=Mode())

assert "Unterminated multiline" in str(excinfo.value)