Skip to content

Commit 515995b

Browse files
committed
Add tests
1 parent 5328636 commit 515995b

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

openformats/tests/formats/markdown_jsx/__ini__.py

Whitespace-only changes.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Alert, Button } from './components'
2+
3+
# Welcome to My MDX Page 🎉
4+
5+
This is a regular Markdown heading. Below is a list:
6+
7+
- Works with **Markdown**
8+
- Supports _emphasis_, **bold**, and `inline code`
9+
- Lets you embed components 👇
10+
11+
---
12+
13+
## 🚀 Interactive Component
14+
15+
<Alert type="success">
16+
✅ Success! You can render React components inside Markdown.
17+
</Alert>
18+
19+
---
20+
21+
## 📦 Props in Components
22+
23+
You can pass props like this:
24+
25+
<Button onClick={() => alert('You clicked the button!')}>
26+
Click Me
27+
</Button>
28+
29+
---
30+
31+
## 📜 Code Block
32+
33+
```js
34+
console.log('MDX supports code highlighting too!');
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import unittest
2+
from io import open
3+
from os import path
4+
5+
from openformats.formats.markdown_jsx import MarkdownJsxHandler
6+
from openformats.tests.formats.common import CommonFormatTestMixin
7+
8+
9+
class MarkdownJsxTestCase(CommonFormatTestMixin, unittest.TestCase):
10+
"""Tests the basic functionality of MarkdownJsxHandler."""
11+
HANDLER_CLASS = MarkdownJsxHandler
12+
TESTFILE_BASE = "openformats/tests/formats/markdown_jsx/files"
13+
14+
def __init__(self, *args, **kwargs):
15+
super(MarkdownJsxTestCase, self).__init__(*args, **kwargs)
16+
filepath = path.join(self.TESTFILE_BASE, "test.mdx")
17+
with open(filepath, "r", encoding='utf-8') as myfile:
18+
self.data['test'] = myfile.read()
19+
20+
def test_compile(self):
21+
"""Test that import-export is the same as the original file."""
22+
remade_orig_content = self.handler.compile(self.tmpl, self.strset)
23+
self.assertEqual(remade_orig_content, self.data["test"])
24+
25+
def test_parse(self):
26+
"""Test parse converts tabs to spaces"""
27+
content_with_tab = self.handler.parse(content=u"# foo bar")
28+
content_with_spaces = self.handler.parse(content=u"# foo bar")
29+
self.assertEqual(content_with_tab[0], content_with_spaces[0])

0 commit comments

Comments
 (0)