Implement Edit Feature #28
3 changed files with 80 additions and 3 deletions
|
|
@ -20,8 +20,8 @@ def get_line_number(block_token: BlockToken) -> int:
|
||||||
|
|
||||||
|
|
||||||
def build_shard(
|
def build_shard(
|
||||||
start_line,
|
start_line: int,
|
||||||
end_line,
|
end_line: int,
|
||||||
markers: list[str] = [],
|
markers: list[str] = [],
|
||||||
tags: list[str] = [],
|
tags: list[str] = [],
|
||||||
children: list[Shard] = [],
|
children: list[Shard] = [],
|
||||||
|
|
|
||||||
76
test/parse/test_attach_markdown.py
Normal file
76
test/parse/test_attach_markdown.py
Normal file
|
|
@ -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"
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
from streamer.parse import StreamFile, parse_markdown_file, Shard
|
|
||||||
from faker import Faker
|
from faker import Faker
|
||||||
|
|
||||||
|
from streamer.parse import Shard, StreamFile, parse_markdown_file
|
||||||
|
|
||||||
fake = Faker()
|
fake = Faker()
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue