Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions tests/test_api/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,51 @@ def test_src_char_code_follows_src():
state.src = "xyz"
with pytest.warns(DeprecationWarning):
assert list(state.srcCharCode) == [120, 121, 122]


def test_options_update_positional_type_error():
"""Catches the signature change where renderer_cls was not used as a key-word."""
with pytest.raises(TypeError, match="options_update should be a mapping"):
MarkdownIt("commonmark", "zero")


def test_wrong_preset_name():
with pytest.raises(KeyError, match="preset 'wrong'"):
MarkdownIt("wrong")


def test_empty_config():
with pytest.raises(ValueError, match="can't be empty"):
MarkdownIt({})


def test_configure_with_components():
md = MarkdownIt("zero")
md.configure({"options": {}, "components": {"core": {"rules": ["normalize"]}}})
assert md.get_active_rules()["core"] == ["normalize"]


def test_add_render_rule():
md = MarkdownIt()

def render_text(self, tokens, idx, options, env):
return "OVERRIDDEN"

md.add_render_rule("text", render_text)
assert md.render("hello") == "<p>OVERRIDDEN</p>\n"


def test_parse_invalid_input_types():
md = MarkdownIt()
with pytest.raises(TypeError, match="MutableMapping"):
md.parse("# hi", env="not a mapping")
with pytest.raises(TypeError, match="string"):
md.parse(123)


def test_parse_inline_invalid_input_types():
md = MarkdownIt()
with pytest.raises(TypeError, match="MutableMapping"):
md.parseInline("hi", env="not a mapping")
with pytest.raises(TypeError, match="string"):
md.parseInline(123)
52 changes: 52 additions & 0 deletions tests/test_api/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import pytest

from markdown_it.common.utils import (
arrayReplaceAt,
isValidEntityCode,
isWhiteSpace,
stripEscape,
unescapeAll,
)


@pytest.mark.parametrize(
"code",
[
0xFDD0, # never used range start
0xFDEF, # never used range end
0xFFFE, # ends in FFFE
0x1FFFF, # ends in FFFF
0x0B, # vertical tab
0x0E, # control range start
0x1F, # control range end
0x7F, # DEL range start
0x9F, # DEL range end
],
)
def test_is_valid_entity_code_invalid(code: int) -> None:
assert not isValidEntityCode(code)


@pytest.mark.parametrize("code", [0x41, 0x0A, 0x20, 0x10FFFD])
def test_is_valid_entity_code_valid(code: int) -> None:
assert isValidEntityCode(code)


def test_array_replace_at() -> None:
assert arrayReplaceAt([1, 2, 3], 1, ["a", "b"]) == [1, "a", "b", 3]
assert arrayReplaceAt([1, 2, 3], 0, []) == [2, 3]


def test_strip_escape() -> None:
assert stripEscape(r"\*not emphasised\*") == "*not emphasised*"


def test_is_white_space_unicode_space_separators() -> None:
assert isWhiteSpace(0x2000) # en quad
assert isWhiteSpace(0x200A) # hair space
assert not isWhiteSpace(0x200B) # zero width space is not a separator


def test_unescape_all_decimal_entity() -> None:
assert unescapeAll("&#35;") == "#"
assert unescapeAll("&#x23;") == "#"