Exemplo n.º 1
0
def test_custom_header_anchor_function():
    source = """
    = Title of the section
    """

    expected = [{
        "type": "header",
        "kwargs": {},
        "value": "Title of the section",
        "level": 1,
        "anchor": "XXXXXY",
    }]

    config = {"mau.header_anchor_function": lambda text, level: "XXXXXY"}

    _test = parser_test_factory(MainParser, variables=config)

    _test(source, expected)
Exemplo n.º 2
0
from mau.parsers.main_parser import MainParser

from tests.helpers import init_parser_factory, parser_test_factory

init_parser = init_parser_factory(MainParser)

_test = parser_test_factory(MainParser)


def test_include_image_with_only_path():
    source = """
    << image:/path/to/it.jpg
    """

    expected = [
        {
            "type": "content_image",
            "uri": "/path/to/it.jpg",
            "alt_text": None,
            "title": None,
            "classes": None,
            "kwargs": {},
        },
    ]

    _test(source, expected)


def test_include_image_with_full_uri():
    source = """
    << image:/path/to/it.jpg
Exemplo n.º 3
0
def test_parse_macro_footnote_commas_mau_v2(footnote_anchors_mock, ):
    footnote_anchors_mock.return_value = ("refXYZ", "defXYZ")

    source = r'text[footnote]("Some text, that should not, be split") other text'

    _test = parser_test_factory(TextParser)

    expected = [{
        "type":
        "sentence",
        "content": [
            {
                "type": "text",
                "value": "text"
            },
            {
                "type":
                "footnote_ref",
                "number":
                1,
                "refanchor":
                "refXYZ",
                "defanchor":
                "defXYZ",
                "content": [{
                    "type":
                    "sentence",
                    "content": [
                        {
                            "type": "text",
                            "value": "Some text, that should not, be split",
                        },
                    ],
                }],
            },
            {
                "type": "text",
                "value": " other text"
            },
        ],
    }]

    p = _test(source, expected)

    assert listasdict(p.footnote_defs) == [{
        "type":
        "footnote_def",
        "number":
        1,
        "refanchor":
        "refXYZ",
        "defanchor":
        "defXYZ",
        "content": [{
            "type":
            "sentence",
            "content": [
                {
                    "type": "text",
                    "value": "Some text, that should not, be split",
                },
            ],
        }],
    }]
Exemplo n.º 4
0
from unittest.mock import patch

from mau.parsers.text_parser import TextParser

from tests.helpers import listasdict, init_parser_factory, parser_test_factory

init_parser = init_parser_factory(TextParser)

_test = parser_test_factory(TextParser)


def test_collect_macro_arguments_single_argument():
    source = "(value1)"

    p = init_parser(source)
    assert p._collect_macro_args() == "value1"


def test_collect_macro_arguments_multiple_arguments():
    source = "(value1,value2)"

    p = init_parser(source)
    assert p._collect_macro_args() == "value1,value2"


def test_collect_macro_arguments_single_argument_with_quotes():
    source = '("value1")'

    p = init_parser(source)
    assert p._collect_macro_args() == '"value1"'