-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_diff_improvements.py
More file actions
78 lines (61 loc) · 2.39 KB
/
test_diff_improvements.py
File metadata and controls
78 lines (61 loc) · 2.39 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
"""Test the improved diff display features."""
from diff_display import create_file_diff, compute_diff_stats
# Test 1: Simple edit
old_content = """def hello():
print("Hello")
return True
def goodbye():
print("Bye")
"""
new_content = """def hello():
print("Hello, World!")
return True
def greet(name):
print(f"Hi {name}")
def goodbye():
print("Bye")
"""
print("=" * 60)
print("Test 1: Simple function addition and modification")
print("=" * 60)
file_diff = create_file_diff("example.py", old_content, new_content, context=3)
additions, deletions, context = compute_diff_stats(file_diff.lines)
print(f"\nSummary: {file_diff.summary}")
print(f"Stats: +{additions} -{deletions} (context: {context})")
print(f"Total lines in diff: {len(file_diff.lines)}")
print("\nDiff lines:")
for i, line in enumerate(file_diff.lines[:20]): # Show first 20
change_type = line.change_type
symbol = "+" if change_type == "add" else "-" if change_type == "delete" else " "
line_num = line.line_num or line.old_line_num or "?"
print(f"{symbol} {line_num:>4} | {line.content}")
print("\n" + "=" * 60)
print("Test 2: Large file to test truncation")
print("=" * 60)
# Create a large diff
large_old = "\n".join([f"line {i}" for i in range(1, 101)])
large_new = "\n".join([f"line {i}" for i in range(1, 101)] + [f"new line {i}" for i in range(101, 201)])
large_diff = create_file_diff("large.py", large_old, large_new, context=3)
print(f"\nSummary: {large_diff.summary}")
print(f"Total lines in diff: {len(large_diff.lines)}")
print("This would be truncated in the UI, showing 'expand large.py' option")
print("\n" + "=" * 60)
print("Test 3: Analyze change types for smart explanations")
print("=" * 60)
# Test different types of changes
changes = [
("def new_function():\n pass", "Function definition"),
("class MyClass:\n pass", "Class definition"),
("import os", "Import statement"),
("result = calculate(x, y)", "Variable assignment"),
("return value", "Control flow"),
]
for code, expected in changes:
old = "# empty file\n"
new = f"# empty file\n{code}\n"
diff = create_file_diff("test.py", old, new, context=1)
added_lines = [line.content for line in diff.lines if line.change_type == 'add']
first_added = added_lines[0].strip() if added_lines else ""
print(f"✓ {expected}: '{first_added[:40]}'")
print("\nAll tests passed!")