diff --git a/src/streamer/parse/parse.py b/src/streamer/parse/parse.py index a4c8421..4a8258f 100644 --- a/src/streamer/parse/parse.py +++ b/src/streamer/parse/parse.py @@ -20,8 +20,8 @@ def get_line_number(block_token: BlockToken) -> int: def build_shard( - start_line, - end_line, + start_line: int, + end_line: int, markers: list[str] = [], tags: list[str] = [], children: list[Shard] = [], diff --git a/test/parse/test_attach_markdown.py b/test/parse/test_attach_markdown.py new file mode 100644 index 0000000..21f8a1b --- /dev/null +++ b/test/parse/test_attach_markdown.py @@ -0,0 +1,76 @@ +from faker import Faker + +from streamer.parse import Shard, StreamFile +from streamer.parse.attach_markdown import ( + ShardWithMarkdown, + StreamFileWithMarkdown, + attach_markdown, +) + +fake = Faker() + + +class TestAttachMarkdown: + file_name: str = fake.file_name(extension="md") + + def test_attach_markdown_with_shard(self): + markdown_text = "Hello World\n\nThis is a test." + shard = Shard(start_line=1, end_line=3) + stream_file = StreamFile(filename=self.file_name, shard=shard) + + result = attach_markdown(stream_file, markdown_text) + + assert result == StreamFileWithMarkdown( + filename=self.file_name, + shard=ShardWithMarkdown( + start_line=1, + end_line=3, + markdown_content=markdown_text, + markers=[], + tags=[], + children=[], + ), + ) + + def test_attach_markdown_without_shard(self): + stream_file = StreamFile(filename=self.file_name, shard=None) + + result = attach_markdown(stream_file, "Some markdown text") + + assert result == StreamFileWithMarkdown(filename=self.file_name, shard=None) + + def test_attach_markdown_with_nested_shards(self): + markdown_text = "Header\n\n@Marker1 Content 1\n\n@Marker2 Content 2" + shard = Shard( + start_line=1, + end_line=5, + children=[ + Shard(markers=["Marker1"], start_line=3, end_line=3), + Shard(markers=["Marker2"], start_line=5, end_line=5), + ], + ) + stream_file = StreamFile(filename=self.file_name, shard=shard) + + result = attach_markdown(stream_file, markdown_text) + + assert result.filename == self.file_name + assert result.shard is not None + assert result.shard.start_line == 1 + assert result.shard.end_line == 5 + assert ( + result.shard.markdown_content + == "Header\n\n@Marker1 Content 1\n\n@Marker2 Content 2" + ) + assert len(result.shard.children) == 2 + + # Check first child + assert result.shard.children[0].markers == ["Marker1"] + assert result.shard.children[0].start_line == 3 + assert result.shard.children[0].end_line == 3 + assert result.shard.children[0].markdown_content == "@Marker1 Content 1" + + # Check second child + assert result.shard.children[1].markers == ["Marker2"] + assert result.shard.children[1].start_line == 5 + assert result.shard.children[1].end_line == 5 + assert result.shard.children[1].markdown_content == "@Marker2 Content 2" diff --git a/test/test_parse.py b/test/parse/test_parse.py similarity index 99% rename from test/test_parse.py rename to test/parse/test_parse.py index e9c27ba..0a71671 100644 --- a/test/test_parse.py +++ b/test/parse/test_parse.py @@ -1,6 +1,7 @@ -from streamer.parse import StreamFile, parse_markdown_file, Shard from faker import Faker +from streamer.parse import Shard, StreamFile, parse_markdown_file + fake = Faker()