-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cpp_enums.py
More file actions
52 lines (39 loc) · 1.43 KB
/
Copy pathtest_cpp_enums.py
File metadata and controls
52 lines (39 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from unittest.mock import MagicMock
import pytest
from codegraphcontext_cpp._parser import CppTreeSitterParser
from codegraphcontext.utils.tree_sitter_manager import get_tree_sitter_manager
@pytest.fixture(scope="module")
def cpp_parser():
manager = get_tree_sitter_manager()
if not manager.is_language_available("cpp"):
pytest.skip("C++ tree-sitter grammar is not available in this environment")
wrapper = MagicMock()
wrapper.language_name = "cpp"
wrapper.language = manager.get_language_safe("cpp")
wrapper.parser = manager.create_parser("cpp")
return CppTreeSitterParser(wrapper)
def test_enum_parsing(cpp_parser, temp_test_dir):
code = """
enum Color { RED, GREEN, BLUE };
enum class Status { OK = 0, ERROR = 1 };
"""
f = temp_test_dir / "enums.cpp"
f.write_text(code)
result = cpp_parser.parse(f)
enum_names = [e["name"] for e in result.get("enums", [])]
assert "Color" in enum_names
assert "Status" in enum_names
def test_file_with_enums_and_classes(cpp_parser, temp_test_dir):
"""Ensure files containing both enums and classes parse without errors."""
code = """
enum DataType { INT = 0, VARCHAR = 1 };
class Foo {
public:
void bar() {}
};
"""
f = temp_test_dir / "mixed.cpp"
f.write_text(code)
result = cpp_parser.parse(f)
assert any(c["name"] == "Foo" for c in result["classes"])
assert any(e["name"] == "DataType" for e in result.get("enums", []))