Skip to content

Commit

Permalink
Make link names case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedThree committed Apr 3, 2024
1 parent 97a4621 commit a2f553a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ford/fortran_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def find(

if entity is not None:
try:
collection = getattr(self, LINK_TYPES[entity])
collection = getattr(self, LINK_TYPES[entity.lower()])
except KeyError:
raise ValueError(f"Unknown class of entity {entity!r}")
else:
Expand Down
4 changes: 2 additions & 2 deletions ford/sourceform.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _find_in_list(collection: Iterable, name: str) -> Optional[FortranBase]:
# correlate it for whatever reason, if so skip it
if not isinstance(item, FortranBase):
continue
if name == item.name.lower():
if name.lower() == item.name.lower():
return item
return None

Expand Down Expand Up @@ -591,7 +591,7 @@ def find_child(

if entity is not None:
try:
collection_name = SUBLINK_TYPES[entity]
collection_name = SUBLINK_TYPES[entity.lower()]
except KeyError:
raise ValueError(f"Unknown class of entity {entity!r}")
if not hasattr(self, collection_name):
Expand Down
68 changes: 66 additions & 2 deletions test/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,71 @@ def test_submodule_uses(copy_fortran_file):


def test_make_links(copy_fortran_file):
links = "[[a]] [[b(type)]] [[b:c]] [[a:d]] [[b:e]] [[f(proc)]] [[a:g]] [[h]]"
links = "[[a]] [[b(type)]] [[b:c]] [[a:d]] [[b:e]] [[F(proc)]] [[A:G]] [[H]]"

data = f"""\
module a !! {links}
type b !! {links}
integer :: c !! {links}
contains
final :: d !! {links}
procedure :: e !! {links}
end type b
interface b !! {links}
module procedure f
end interface b
type(b) :: g !! {links}
contains
subroutine d(self) !! {links}
type(b) :: self !! {links}
end subroutine d
subroutine e(self) !! {links}
class(b) :: self !! {links}
end subroutine e
function f() !! {links}
type(b) :: f !! {links}
end function f
end module a
program h !! {links}
end program h
"""
settings = copy_fortran_file(data)
project = create_project(settings)
md = MetaMarkdown(project=project)
project.markdown(md)

expected_links = {
"a": "../module/a.html",
"b": "../type/b.html",
"c": "../type/b.html#variable-c",
"d": "../proc/d.html",
"e": "../type/b.html#boundprocedure-e",
"f": "../proc/f.html",
"g": "../module/a.html#variable-g",
"h": "../program/h.html",
}

for item in chain(
project.files[0].children,
project.types[0].children,
project.procedures[0].children,
project.procedures[2].children,
):
docstring = BeautifulSoup(item.doc, features="html.parser")
link_locations = {a.string: a.get("href", None) for a in docstring("a")}

assert link_locations == expected_links, (item, item.name)


def test_make_links_with_entity_spec(copy_fortran_file):
links = (
"[[a(module)]] [[b(type)]] [[b(type):c(variable)]] "
"[[A(MODULE):D(SUBROUTINE)]] [[B(TYPE):E]] [[F(PROC)]] "
"[[A(module):G(variable)]] [[H(program)]]"
)

data = f"""\
module a !! {links}
Expand Down Expand Up @@ -1113,7 +1177,7 @@ def test_link_with_context(copy_fortran_file):
type(b) :: g
contains
subroutine d(i) !! [[i]] [[f]] [[f:x]]
subroutine d(i) !! [[I]] [[F]] [[F:X]]
type(b) :: i
contains
integer function f(x)
Expand Down

0 comments on commit a2f553a

Please sign in to comment.