summaryrefslogtreecommitdiffstats
path: root/tests/test_myst_role.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_myst_role.py')
-rw-r--r--tests/test_myst_role.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/test_myst_role.py b/tests/test_myst_role.py
new file mode 100644
index 0000000..f70e3f8
--- /dev/null
+++ b/tests/test_myst_role.py
@@ -0,0 +1,89 @@
+from pathlib import Path
+
+from markdown_it import MarkdownIt
+from markdown_it.token import Token
+from markdown_it.utils import read_fixture_file
+import pytest
+
+from mdit_py_plugins.myst_role import myst_role_plugin
+
+FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures", "myst_role.md")
+
+
+def test_basic():
+ md = MarkdownIt().use(myst_role_plugin)
+ src = "{abc}``` a ```"
+ tokens = md.parse(src)
+ print(tokens)
+ assert tokens == [
+ Token(
+ type="paragraph_open",
+ tag="p",
+ nesting=1,
+ attrs=None,
+ map=[0, 1],
+ level=0,
+ children=None,
+ content="",
+ markup="",
+ info="",
+ meta={},
+ block=True,
+ hidden=False,
+ ),
+ Token(
+ type="inline",
+ tag="",
+ nesting=0,
+ attrs=None,
+ map=[0, 1],
+ level=1,
+ children=[
+ Token(
+ type="myst_role",
+ tag="",
+ nesting=0,
+ attrs=None,
+ map=None,
+ level=0,
+ children=None,
+ content=" a ",
+ markup="",
+ info="",
+ meta={"name": "abc"},
+ block=False,
+ hidden=False,
+ )
+ ],
+ content="{abc}``` a ```",
+ markup="",
+ info="",
+ meta={},
+ block=True,
+ hidden=False,
+ ),
+ Token(
+ type="paragraph_close",
+ tag="p",
+ nesting=-1,
+ attrs=None,
+ map=None,
+ level=0,
+ children=None,
+ content="",
+ markup="",
+ info="",
+ meta={},
+ block=True,
+ hidden=False,
+ ),
+ ]
+
+
+@pytest.mark.parametrize("line,title,input,expected", read_fixture_file(FIXTURE_PATH))
+def test_all(line, title, input, expected):
+ md = MarkdownIt("commonmark").use(myst_role_plugin)
+ md.options["xhtmlOut"] = False
+ text = md.render(input)
+ print(text)
+ assert text.rstrip() == expected.rstrip()