from docling_core.types.doc.page import BoundingRectangle, TextCell from docling.utils.layout_postprocessor import LayoutPostprocessor def _text_cell(index: int) -> TextCell: return TextCell( index=index, rect=BoundingRectangle( r_x0=0, r_y0=0, r_x1=1, r_y1=0, r_x2=1, r_y2=1, r_x3=0, r_y3=1, ), text=str(index), orig=str(index), from_ocr=False, ) def test_sort_cells_uses_native_cell_index_order() -> None: processor = object.__new__(LayoutPostprocessor) cells = [_text_cell(3), _text_cell(1), _text_cell(2)] sorted_cells = processor._sort_cells(cells) assert [cell.index for cell in sorted_cells] == [1, 2, 3] assert [cell.index for cell in cells] == [3, 1, 2]