Skip to content

Commit

Permalink
Merge pull request #660 from Fortran-FOSS-Programmers/fix-extra_filet…
Browse files Browse the repository at this point in the history
…ype-error

Fix error detection when parsing `extra_filetype`
  • Loading branch information
ZedThree authored Jul 31, 2024
2 parents 51bf8de + 7f9b3f3 commit f8a8a04
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 f8a8a04

Please sign in to comment.