| from __future__ import annotations | |
| import pytest | |
| from app.rag.chunk import chunk_text | |
| def test_chunk_windows_and_overlap(): | |
| chunks = chunk_text("a" * 2500, size=1000, overlap=200) | |
| assert all(len(c) <= 1000 for c in chunks) | |
| assert len(chunks) == 4 # step=800 over 2500 chars | |
| # consecutive chunks overlap by `overlap` chars | |
| assert chunks[0][-200:] == chunks[1][:200] | |
| def test_chunk_empty_returns_nothing(): | |
| assert chunk_text(" \n\t ") == [] | |
| assert chunk_text("") == [] | |
| def test_chunk_short_text_single_chunk(): | |
| assert chunk_text("hola mundo", size=1000, overlap=200) == ["hola mundo"] | |
| def test_chunk_invalid_overlap(): | |
| with pytest.raises(ValueError): | |
| chunk_text("abc", size=100, overlap=100) | |