feat(models): Extend FileItem.custom_slices with tag and comment fields
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import pytest
|
||||
from src.models import FileItem
|
||||
|
||||
def test_file_item_custom_slices_serialization_with_annotations():
|
||||
# Test that FileItem correctly serializes custom_slices with tag and comment.
|
||||
slices = [
|
||||
{'start_line': 1, 'end_line': 10, 'tag': 'init', 'comment': 'Constructor logic'},
|
||||
{'start_line': 20, 'end_line': 30, 'tag': 'process', 'comment': 'Main processing loop'}
|
||||
]
|
||||
item = FileItem(path='src/app.py', custom_slices=slices)
|
||||
|
||||
serialized = item.to_dict()
|
||||
assert 'custom_slices' in serialized
|
||||
assert len(serialized['custom_slices']) == 2
|
||||
assert serialized['custom_slices'][0]['tag'] == 'init'
|
||||
assert serialized['custom_slices'][0]['comment'] == 'Constructor logic'
|
||||
assert serialized['custom_slices'][1]['tag'] == 'process'
|
||||
assert serialized['custom_slices'][1]['comment'] == 'Main processing loop'
|
||||
|
||||
def test_file_item_custom_slices_deserialization_with_annotations():
|
||||
# Test that FileItem correctly deserializes custom_slices with tag and comment.
|
||||
data = {
|
||||
'path': 'src/app.py',
|
||||
'custom_slices': [
|
||||
{'start_line': 5, 'end_line': 15, 'tag': 'helper', 'comment': 'Utility function'},
|
||||
{'start_line': 40, 'end_line': 50} # Missing optional fields
|
||||
]
|
||||
}
|
||||
|
||||
item = FileItem.from_dict(data)
|
||||
assert len(item.custom_slices) == 2
|
||||
|
||||
# First slice has annotations
|
||||
assert item.custom_slices[0]['tag'] == 'helper'
|
||||
assert item.custom_slices[0]['comment'] == 'Utility function'
|
||||
|
||||
# Second slice should have default None or empty string for optional fields
|
||||
# This is where it will likely FAIL if we haven't updated from_dict to inject defaults
|
||||
assert 'tag' in item.custom_slices[1]
|
||||
assert 'comment' in item.custom_slices[1]
|
||||
assert item.custom_slices[1]['tag'] is None
|
||||
assert item.custom_slices[1]['comment'] is None
|
||||
|
||||
def test_file_item_custom_slices_round_trip_annotations():
|
||||
# Test a full round trip of FileItem with slice annotations.
|
||||
item = FileItem(path='src/test.py', custom_slices=[
|
||||
{'start_line': 1, 'end_line': 5, 'tag': 'test', 'comment': 'Unit test case'}
|
||||
])
|
||||
|
||||
serialized = item.to_dict()
|
||||
deserialized = FileItem.from_dict(serialized)
|
||||
|
||||
assert deserialized.custom_slices == item.custom_slices
|
||||
assert deserialized.custom_slices[0]['tag'] == 'test'
|
||||
assert deserialized.custom_slices[0]['comment'] == 'Unit test case'
|
||||
|
||||
Reference in New Issue
Block a user