feat: add initial parser data structure & test
Signed-off-by: Konstantin Fickel <mail@konstantinfickel.de>
This commit is contained in:
parent
f73c6d16cb
commit
2091e5c98d
8 changed files with 375 additions and 30 deletions
83
test/test_parse.py
Normal file
83
test/test_parse.py
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
from streamer.parse import StreamFile, parse_markdown_file, Shard
|
||||
from faker import Faker
|
||||
|
||||
fake = Faker()
|
||||
|
||||
|
||||
class TestParseProcess:
|
||||
file_name: str = fake.file_name(extension="md")
|
||||
|
||||
def test_parse_empty_file(self):
|
||||
assert parse_markdown_file(self.file_name, "") == StreamFile(
|
||||
filename=self.file_name, shard=None
|
||||
)
|
||||
|
||||
def test_parse_basic_one_line_file(self):
|
||||
test_file = "Hello World"
|
||||
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
|
||||
filename=self.file_name,
|
||||
shard=Shard(
|
||||
markers=[],
|
||||
tags=[],
|
||||
content=test_file,
|
||||
start_line=1,
|
||||
end_line=1,
|
||||
children=[],
|
||||
),
|
||||
)
|
||||
|
||||
def test_parse_basic_multi_line_file(self):
|
||||
test_file = "Hello World\nHello again!"
|
||||
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
|
||||
filename=self.file_name,
|
||||
shard=Shard(
|
||||
markers=[],
|
||||
tags=[],
|
||||
content=test_file,
|
||||
start_line=1,
|
||||
end_line=2,
|
||||
children=[],
|
||||
),
|
||||
)
|
||||
|
||||
def test_parse_single_line_with_tag(self):
|
||||
test_file = "@Tag Hello World"
|
||||
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
|
||||
filename=self.file_name,
|
||||
shard=Shard(
|
||||
markers=["Tag"],
|
||||
tags=[],
|
||||
content=test_file,
|
||||
start_line=1,
|
||||
end_line=1,
|
||||
children=[],
|
||||
),
|
||||
)
|
||||
|
||||
def test_parse_single_line_with_two_tags(self):
|
||||
test_file = "@Tag1 @Tag2 Hello World"
|
||||
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
|
||||
filename=self.file_name,
|
||||
shard=Shard(
|
||||
markers=["Tag1", "Tag2"],
|
||||
tags=[],
|
||||
content=test_file,
|
||||
start_line=1,
|
||||
end_line=1,
|
||||
children=[],
|
||||
),
|
||||
)
|
||||
|
||||
def test_parse_single_line_with_two_tags_and_misplaced_tag(self):
|
||||
test_file = "@Tag1 @Tag2 Hello World @Tag3"
|
||||
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
|
||||
filename=self.file_name,
|
||||
shard=Shard(
|
||||
markers=["Tag1", "Tag2"],
|
||||
tags=["Tag3"],
|
||||
content=test_file,
|
||||
start_line=1,
|
||||
end_line=1,
|
||||
children=[],
|
||||
),
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue