Skip to content

Commit

Permalink
Fix error detection when parsing extra_filetype
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedThree committed Jul 30, 2024
1 parent ac5ed02 commit 7f9b3f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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")

0 comments on commit 7f9b3f3

Please sign in to comment.