Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions code_review_graph/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class EdgeInfo:
".c": "c",
".h": "c",
".hpp": "cpp",
".hh": "cpp",
".kt": "kotlin",
".swift": "swift",
".php": "php",
Expand Down
22 changes: 22 additions & 0 deletions tests/fixtures/sample.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#include <string>

class Shape {
public:
std::string color;

Shape(std::string c) : color(c) {}
virtual double area() const = 0;
};

class Circle : public Shape {
public:
double radius;

Circle(std::string c, double r) : Shape(c), radius(r) {}
double area() const override { return 3.14159 * radius * radius; }
};

inline double perimeter(const Circle& circle) {
return 2.0 * 3.14159 * circle.radius;
}
24 changes: 24 additions & 0 deletions tests/test_multilang.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,30 @@ def test_finds_inheritance(self):
assert len(inherits) >= 1


class TestHhParsing:
def setup_method(self):
self.parser = CodeParser()
self.nodes, self.edges = self.parser.parse_file(FIXTURES / "sample.hh")

def test_detects_language(self):
assert self.parser.detect_language(Path("types.hh")) == "cpp"

def test_finds_classes(self):
classes = [n for n in self.nodes if n.kind == "Class"]
names = {c.name for c in classes}
assert "Shape" in names
assert "Circle" in names

def test_finds_functions(self):
funcs = [n for n in self.nodes if n.kind == "Function"]
names = {f.name for f in funcs}
assert "perimeter" in names

def test_finds_inheritance(self):
inherits = [e for e in self.edges if e.kind == "INHERITS"]
assert len(inherits) >= 1


def _has_csharp_parser():
try:
import tree_sitter_language_pack as tslp
Expand Down