1import pytest
2
3from marko import helpers
4
5
6@pytest.mark.parametrize(
7    "raw_string",
8    [
9        "(hello(to)world)",
10        r"(hello\)world)",
11        r"he\(llo(world)",
12        "",
13        "hello world",
14        "(hello), (world)",
15    ],
16)
17def test_is_paired(raw_string):
18    assert helpers.is_paired(raw_string)
19
20
21@pytest.mark.parametrize(
22    "raw_string",
23    [
24        "(hello(toworld)",
25        "(hello)world)",
26        "(",
27    ],
28)
29def test_is_not_paired(raw_string):
30    assert not helpers.is_paired(raw_string)
31
32
33def test_source_no_state():
34    source = helpers.Source("hello world")
35
36    with pytest.raises(RuntimeError, match="Need to push a state first"):
37        source.root
38
39    with pytest.raises(RuntimeError, match="Need to push a state first"):
40        source.state
41
42
43def test_load_extension_object():
44    ext = helpers.load_extension_object("pangu")()
45    assert len(ext.renderer_mixins) == 1
46
47    ext = helpers.load_extension_object("marko.ext.pangu")()
48    assert len(ext.renderer_mixins) == 1
49
50    with pytest.raises(ImportError, match="Extension foobar cannot be found"):
51        helpers.load_extension_object("foobar")()
52
53
54def test_load_illegal_extension_object():
55    with pytest.raises(
56        AttributeError,
57        match="Module marko.block does not have 'make_extension' attributte",
58    ):
59        helpers.load_extension_object("marko.block")()
60