test(mcp): Add tests for C/C++ skeleton and outline tools
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
import os
|
||||
import sys
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
# Add project root to sys.path
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
|
||||
from src.mcp_client import dispatch
|
||||
|
||||
@pytest.fixture
|
||||
def mock_resolve():
|
||||
from src import mcp_client
|
||||
original_resolve = mcp_client._resolve_and_check
|
||||
mcp_client._resolve_and_check = lambda path: (Path(path), None)
|
||||
yield
|
||||
mcp_client._resolve_and_check = original_resolve
|
||||
|
||||
def test_ts_c_get_skeleton_dispatch(tmp_path, mock_resolve):
|
||||
# Verify ts_c_get_skeleton via dispatch
|
||||
c_file = tmp_path / "test.c"
|
||||
c_file.write_text("void main() { }")
|
||||
|
||||
with patch("src.file_cache.ASTParser") as mock_parser_cls:
|
||||
mock_instance = mock_parser_cls.return_value
|
||||
mock_instance.get_skeleton.return_value = "void main() { ... }"
|
||||
|
||||
result = dispatch("ts_c_get_skeleton", {"path": str(c_file)})
|
||||
|
||||
# Verify ASTParser called with correct language
|
||||
mock_parser_cls.assert_called_once_with("c")
|
||||
# Verify get_skeleton called
|
||||
mock_instance.get_skeleton.assert_called_once()
|
||||
# Verify non-empty result
|
||||
assert result and len(result) > 0
|
||||
assert "void main() { ... }" in result
|
||||
|
||||
def test_ts_cpp_get_skeleton_dispatch(tmp_path, mock_resolve):
|
||||
# Verify ts_cpp_get_skeleton via dispatch
|
||||
cpp_file = tmp_path / "test.cpp"
|
||||
cpp_file.write_text("void main() { }")
|
||||
|
||||
with patch("src.file_cache.ASTParser") as mock_parser_cls:
|
||||
mock_instance = mock_parser_cls.return_value
|
||||
mock_instance.get_skeleton.return_value = "void main() { ... }"
|
||||
|
||||
result = dispatch("ts_cpp_get_skeleton", {"path": str(cpp_file)})
|
||||
|
||||
# Verify ASTParser called with correct language
|
||||
mock_parser_cls.assert_called_once_with("cpp")
|
||||
mock_instance.get_skeleton.assert_called_once()
|
||||
assert result and len(result) > 0
|
||||
assert "void main() { ... }" in result
|
||||
|
||||
def test_ts_c_get_code_outline_dispatch(tmp_path, mock_resolve):
|
||||
# Verify ts_c_get_code_outline via dispatch
|
||||
c_file = tmp_path / "test.c"
|
||||
c_file.write_text("void main() { }")
|
||||
|
||||
with patch("src.file_cache.ASTParser") as mock_parser_cls:
|
||||
mock_instance = mock_parser_cls.return_value
|
||||
mock_instance.get_code_outline.return_value = "[Func] main (Lines 1-1)"
|
||||
|
||||
result = dispatch("ts_c_get_code_outline", {"path": str(c_file)})
|
||||
|
||||
# Verify ASTParser called with correct language
|
||||
mock_parser_cls.assert_called_once_with("c")
|
||||
mock_instance.get_code_outline.assert_called_once()
|
||||
assert result and len(result) > 0
|
||||
assert "[Func] main (Lines 1-1)" in result
|
||||
|
||||
def test_ts_cpp_get_code_outline_dispatch(tmp_path, mock_resolve):
|
||||
# Verify ts_cpp_get_code_outline via dispatch
|
||||
cpp_file = tmp_path / "test.cpp"
|
||||
cpp_file.write_text("void main() { }")
|
||||
|
||||
with patch("src.file_cache.ASTParser") as mock_parser_cls:
|
||||
mock_instance = mock_parser_cls.return_value
|
||||
mock_instance.get_code_outline.return_value = "[Func] main (Lines 1-1)"
|
||||
|
||||
result = dispatch("ts_cpp_get_code_outline", {"path": str(cpp_file)})
|
||||
|
||||
# Verify ASTParser called with correct language
|
||||
mock_parser_cls.assert_called_once_with("cpp")
|
||||
mock_instance.get_code_outline.assert_called_once()
|
||||
assert result and len(result) > 0
|
||||
assert "[Func] main (Lines 1-1)" in result
|
||||
Reference in New Issue
Block a user