Skip to content

Commit a631557

Browse files
gkorlandCopilot
andcommitted
test: add coverage for docstring, error paths, and resolve_path
Covers get_entity_docstring (with and without comments), ValueError for unknown entity types in get_entity_label/get_entity_name, and resolve_path passthrough behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f4bbb1f commit a631557

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

tests/source_files/c/src.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "myheader.h"
22
#include <stdio.h>
33

4+
/* Adds two integers */
45
int add
56
(
67
int a,

tests/test_c_analyzer.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,43 @@ def test_is_dependency(self):
8888
"""is_dependency should return False for C files."""
8989
self.assertFalse(self.analyzer.is_dependency("src/main.c"))
9090

91+
def test_docstring_extraction(self):
92+
"""Docstring (comment above entity) should be extracted."""
93+
for entity in self.file.entities.values():
94+
if _entity_name(self.analyzer, entity) == "add":
95+
doc = self.analyzer.get_entity_docstring(entity.node)
96+
self.assertIsNotNone(doc)
97+
self.assertIn("Adds two integers", doc)
98+
return
99+
self.fail("Function 'add' not found")
100+
101+
def test_no_docstring(self):
102+
"""Entities without a preceding comment should return None."""
103+
for entity in self.file.entities.values():
104+
if _entity_name(self.analyzer, entity) == "main":
105+
doc = self.analyzer.get_entity_docstring(entity.node)
106+
self.assertIsNone(doc)
107+
return
108+
self.fail("Function 'main' not found")
109+
110+
def test_unknown_entity_label_raises(self):
111+
"""get_entity_label should raise for unknown node types."""
112+
# Use the tree root node which is 'translation_unit', not a known entity
113+
with self.assertRaises(ValueError):
114+
self.analyzer.get_entity_label(self.file.tree.root_node)
115+
116+
def test_unknown_entity_name_raises(self):
117+
"""get_entity_name should raise for unknown node types."""
118+
with self.assertRaises(ValueError):
119+
self.analyzer.get_entity_name(self.file.tree.root_node)
120+
121+
def test_resolve_path(self):
122+
"""resolve_path should return the file path unchanged."""
123+
self.assertEqual(
124+
self.analyzer.resolve_path("/foo/bar.c", Path("/root")),
125+
"/foo/bar.c",
126+
)
127+
91128

92129
if __name__ == "__main__":
93130
unittest.main()

0 commit comments

Comments
 (0)