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

Fix error detection when parsing extra_filetype #660

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ford/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class ExtraFileType:
@classmethod
def from_string(cls, string: str):
parts = string.split()
if 3 < len(parts) < 2:
if not (2 <= len(parts) <= 3):
raise ValueError(
f"Unexpected format for 'extra_filetype': expected 'extension comment [lexer]', got {string!r}"
)
Expand Down
16 changes: 16 additions & 0 deletions test/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,19 @@ def test_update_entity_settings():

assert settings.source is True
assert settings.version == expected_version


def test_extra_filetype():
c = ExtraFileType.from_string("c //")
assert c == ExtraFileType("c", "//")

c_with_lexer = ExtraFileType.from_string("c // c_lexer")
assert c_with_lexer == ExtraFileType("c", "//", "c_lexer")


def test_extra_filetype_error():
with pytest.raises(ValueError):
ExtraFileType.from_string("c")

with pytest.raises(ValueError):
ExtraFileType.from_string("c // c lexer")
Loading