a7d8e2adfd
Migrates 3 sites in src/outline_tool.py: 1. L49 (outline body) - the ast.parse SyntaxError handler. outline() now returns Result[str]. On SyntaxError, the data is the formatted error string (preserved for backwards-compat with callers that read the formatted string), and the errors list has the ErrorInfo. 2. L90 (walk ast.unparse for returns) - was except ...: pass. Now appends ErrorInfo to enclosing parse_errors list. 3. L109 (walk ast.unparse for ImGui context) - same. outline() returns Result(data='\n'.join(output), errors=parse_errors). get_outline() also returns Result[str]. Tests updated to check result.ok and use result.data.
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import pytest
|
|
import ast
|
|
from pathlib import Path
|
|
from src.outline_tool import CodeOutliner
|
|
|
|
def test_code_outliner_type_hints():
|
|
code = """
|
|
class Test:
|
|
def my_method(self, x: int) -> str:
|
|
return "hello"
|
|
|
|
def my_func(a: bool) -> None:
|
|
pass
|
|
"""
|
|
outliner = CodeOutliner()
|
|
result = outliner.outline(code)
|
|
assert result.ok, f"outline failed: {result.errors}"
|
|
assert "[Method] my_method -> str (Lines 3-4)" in result.data
|
|
assert "[Func] my_func -> None (Lines 6-7)" in result.data
|
|
|
|
def test_code_outliner_imgui_scopes():
|
|
code = """
|
|
def render_gui() -> None:
|
|
with imscope.window("My Window"):
|
|
imgui.text("Hello")
|
|
with imscope.child("My Child"):
|
|
pass
|
|
"""
|
|
outliner = CodeOutliner()
|
|
result = outliner.outline(code)
|
|
assert result.ok, f"outline failed: {result.errors}"
|
|
assert "[ImGui Scope] imscope.window('My Window') (Lines 3-6)" in result.data
|
|
assert "[ImGui Scope] imscope.child('My Child') (Lines 5-6)" in result.data
|
|
|
|
def test_code_outliner_nested_ifs():
|
|
code = """
|
|
def render_gui() -> None:
|
|
if True:
|
|
with imscope.window("My Window"):
|
|
pass
|
|
"""
|
|
outliner = CodeOutliner()
|
|
result = outliner.outline(code)
|
|
assert result.ok, f"outline failed: {result.errors}"
|
|
assert "[ImGui Scope] imscope.window('My Window') (Lines 4-5)" in result.data
|