From 943e3dc057eca53e68ddec51529bd6a1279ebd8e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 29 Apr 2024 06:23:02 +0200 Subject: Adding upstream version 0.18.1. Signed-off-by: Daniel Baumann --- tests/test_html/test_parse_html.py | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/test_html/test_parse_html.py (limited to 'tests/test_html/test_parse_html.py') diff --git a/tests/test_html/test_parse_html.py b/tests/test_html/test_parse_html.py new file mode 100644 index 0000000..3b4cdc1 --- /dev/null +++ b/tests/test_html/test_parse_html.py @@ -0,0 +1,41 @@ +from pathlib import Path + +import pytest + +from myst_parser.parsers.parse_html import tokenize_html + +FIXTURE_PATH = Path(__file__).parent + + +@pytest.mark.param_file(FIXTURE_PATH / "html_ast.md") +def test_html_ast(file_params): + tokens = "\n".join( + repr(t) for t in tokenize_html(file_params.content).walk(include_self=True) + ) + file_params.assert_expected(tokens, rstrip=True) + + +@pytest.mark.param_file(FIXTURE_PATH / "html_round_trip.md") +def test_html_round_trip(file_params): + ast = tokenize_html(file_params.content) + file_params.assert_expected(str(ast), rstrip=True) + + +def test_render_overrides(): + text = "
" + ast = tokenize_html(text) + + def _render_abc(element, *args, **kwargs): + return "hallo" + + output = ast.render(tag_overrides={"abc": _render_abc}) + assert output == "
hallo
" + + +def test_ast_find(): + text = ( + '
z
' + ) + ast = tokenize_html(text) + found = list(ast.find("div", classes=["a"])) + assert [e.attrs.classes for e in found] == [["a"], ["a", "b"]] -- cgit v1.2.3