import pytest from src.file_cache import ASTParser def test_ast_parser_initialization() -> None: """Verify that ASTParser can be initialized with a language string.""" parser = ASTParser(language="python") assert parser.language == "python" def test_ast_parser_parse() -> None: """Verify that the parse method returns a tree_sitter.Tree.""" parser = ASTParser(language="python") code = "def hello(): print('world')" tree = parser.parse(code) assert tree is not None assert tree.root_node.type == "module" def test_ast_parser_get_skeleton_python() -> None: """Verify that get_skeleton replaces function bodies with '...' while preserving docstrings.""" parser = ASTParser(language="python") code = ''' def complex_function(a, b): """This is a docstring.""" x = a + b return x class MyClass: def method(self): """Method docstring.""" pass ''' skeleton = parser.get_skeleton(code) assert 'def complex_function(a, b):' in skeleton assert '"""This is a docstring."""' in skeleton assert '...' in skeleton assert 'x = a + b' not in skeleton assert 'class MyClass:' in skeleton assert 'def method(self):' in skeleton assert '"""Method docstring."""' in skeleton def test_ast_parser_invalid_language() -> None: """Verify handling of unsupported or invalid languages.""" # Currently ASTParser defaults to Python if language not supported or just fails tree-sitter init # If it's intended to raise or handle gracefully, test it here. pass def test_ast_parser_get_curated_view() -> None: """Verify that get_curated_view preserves function bodies with @core_logic or # [HOT].""" parser = ASTParser(language="python") code = ''' def normal_func(): print("hide me") @core_logic def important_func(): print("keep me") def hot_func(): # [HOT] print("keep me too") ''' curated = parser.get_curated_view(code) assert 'print("hide me")' not in curated assert 'print("keep me")' in curated assert 'print("keep me too")' in curated assert '@core_logic' in curated assert '# [HOT]' in curated