Skip to content

Commit

Permalink
Add markdown unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
f0reachARR committed Dec 30, 2024
1 parent 5be815f commit c73161b
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"deepdiff>=8.1.1",
"google-genai>=0.3.0",
"litellm>=1.55.12",
"marko>=2.1.2",
Expand Down
219 changes: 219 additions & 0 deletions tests/test_renderer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
from deepdiff import DeepDiff


def test_slack_renderer_1():
from marko import Markdown
from suisei.slack_markdown.renderer import SlackRenderer
from suisei.slack_markdown.extensions import SLACK_EXTENSION

MARKDOWN_TEXT = """
**Hello *world***
~~strike~~
```cpp
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}
```
[Hello, world!](https://example.com)
https://example.com
![Hello, world!](https://example.com/hello.png)
- List item 1
- List item 1.1
- List item 1.2
- List item 1.2
1. List item 1
2. List item 2
1. List item 2.1
1. List item 2.1
> Hello, world!
> - Scramble Egg
> - Bacon
> - Ham
> - ???
"""

markdown = Markdown(renderer=SlackRenderer)
markdown.use(SLACK_EXTENSION)
parsed = markdown.parse(MARKDOWN_TEXT)
rendered = markdown.render(parsed)
rendered = SlackRenderer.postprocess(rendered)
expected = [
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_section",
"elements": [
{"type": "text", "text": "Hello ", "style": {"bold": True}},
{
"type": "text",
"text": "world",
"style": {"italic": True, "bold": True},
},
{"type": "text", "text": "\n"},
{"type": "text", "text": "strike", "style": {"strike": True}},
],
},
{
"type": "rich_text_preformatted",
"elements": [
{
"type": "text",
"text": '#include <iostream>\n\nint main() {\n std::cout << "Hello, world!" << std::endl;\n return 0;\n}',
}
],
},
{
"type": "rich_text_section",
"elements": [
{
"type": "link",
"url": "https://example.com",
"text": "Hello, world!",
}
],
},
{
"type": "rich_text_section",
"elements": [
{
"type": "link",
"url": "https://example.com",
"text": "https://example.com",
}
],
},
{
"type": "rich_text_section",
"elements": [
{
"type": "link",
"url": "https://example.com/hello.png",
"text": "Hello, world!",
}
],
},
{
"type": "rich_text_list",
"style": "bullet",
"elements": [
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": "List item 1"}],
}
],
"indent": 0,
},
{
"type": "rich_text_list",
"style": "bullet",
"elements": [
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": "List item 1.1"}],
},
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": "List item 1.2"}],
},
],
"indent": 1,
},
{
"type": "rich_text_list",
"style": "bullet",
"elements": [
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": "List item 1.2"}],
}
],
"indent": 2,
},
{
"type": "rich_text_list",
"style": "ordered",
"elements": [
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": "List item 1"}],
},
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": "List item 2"}],
},
],
"indent": 0,
},
{
"type": "rich_text_list",
"style": "ordered",
"elements": [
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": "List item 2.1"}],
},
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": "List item 2.1"}],
},
],
"indent": 1,
},
{
"type": "rich_text_quote",
"elements": [{"type": "text", "text": "Hello, world!"}],
},
],
},
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_list",
"style": "bullet",
"elements": [
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": "Scramble Egg"}],
},
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": "Bacon"}],
},
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": "Ham"}],
},
],
"indent": 0,
"border": 1,
},
{
"type": "rich_text_list",
"style": "bullet",
"elements": [
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": "???"}],
}
],
"indent": 1,
"border": 1,
},
],
},
]

assert not DeepDiff(rendered, expected)
23 changes: 23 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c73161b

Please sign in to comment.