Skip to content

Commit

Permalink
Merge pull request #592 from Fortran-FOSS-Programmers/fix-issue-591
Browse files Browse the repository at this point in the history
Handle entities that might not have be correlated in resolving links
  • Loading branch information
ZedThree authored Nov 13, 2023
2 parents e2784cb + 0957ca4 commit 3bbca47
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ford/sourceform.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@

def _find_in_list(collection: Iterable, name: str) -> Optional[FortranBase]:
for item in collection:
# `item` might still be a string if we've not managed to
# correlate it for whatever reason, if so skip it
if not isinstance(item, FortranBase):
continue
if name == item.name.lower():
return item
return None
Expand Down
32 changes: 32 additions & 0 deletions test/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,3 +1256,35 @@ def test_find(copy_fortran_file):
assert isinstance(prog_foo, FortranProgram)
mod_foo = project.find("foo", entity="module")
assert isinstance(mod_foo, FortranModule)


def test_links_in_deferred_bound_methods(copy_fortran_file):
"""Test for issue #591"""

data = """\
module test
type, abstract :: foo_t
contains
!> See [[foo_t]] for more information about [[foo]]
procedure(foo_iface), deferred :: foo
end type
abstract interface
subroutine foo_iface(self)
import :: foo_t
class(foo_t), intent(in) :: self
end subroutine
end interface
end module
"""

settings = copy_fortran_file(data)
project = create_project(settings)
md = MetaMarkdown(settings.md_base_dir, project=project)
project.markdown(md, ".")

docstring = BeautifulSoup(
project.modules[0].types[0].boundprocs[0].doc, features="html.parser"
)
links = {link.text: link["href"] for link in docstring.find_all("a")}
assert links["foo_t"] == "./type/foo_t.html"
assert links["foo"] == "./type/foo_t.html#boundprocedure-foo"

0 comments on commit 3bbca47

Please sign in to comment.