Skip to content

Commit c649e2f

Browse files
committed
Test tree-sitter parser on example project
1 parent 5675bdd commit c649e2f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

ford/sourceform.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,6 +3422,10 @@ def __init__(self):
34223422
self._items = {}
34233423
self._counts = {}
34243424

3425+
def reset(self):
3426+
self._items = {}
3427+
self._counts = {}
3428+
34253429
def get_name(self, item):
34263430
"""
34273431
Return the name for this item registered with this NameSelector.

test/test_example.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,21 @@ def front_page_list(settings, items):
2323
return sorted(items)[:max_frontpage_items]
2424

2525

26+
def pytest_generate_tests(metafunc):
27+
if "example_project" in metafunc.fixturenames:
28+
metafunc.parametrize("example_project", (False, True), indirect=True)
29+
30+
31+
projects = {}
32+
2633
@pytest.fixture(scope="module")
27-
def example_project(tmp_path_factory):
34+
def example_project(tmp_path_factory, request):
35+
use_tree_sitter = request.param
36+
if use_tree_sitter in projects:
37+
return projects[use_tree_sitter]
38+
2839
this_dir = pathlib.Path(__file__).parent
29-
tmp_path = tmp_path_factory.getbasetemp() / "example"
40+
tmp_path = tmp_path_factory.getbasetemp() / f"example_tree_sitter_{use_tree_sitter}"
3041
shutil.copytree(this_dir / "../example", tmp_path)
3142

3243
with pytest.MonkeyPatch.context() as m:
@@ -38,10 +49,13 @@ def example_project(tmp_path_factory):
3849
project_file = f.read()
3950

4051
project_file, project_settings = ford.load_settings(project_file)
52+
project_settings.use_tree_sitter = use_tree_sitter
53+
ford.sourceform.namelist.reset()
4154
settings, _ = ford.parse_arguments({}, project_file, project_settings, tmp_path)
4255

4356
doc_path = tmp_path / "doc"
4457

58+
projects[use_tree_sitter] = (doc_path, settings)
4559
return doc_path, settings
4660

4761

0 commit comments

Comments
 (0)