test markup

This commit is contained in:
Will McGugan 2020-04-13 12:24:21 +01:00
parent 6b59f45c70
commit 7c8d43b16d
1 changed files with 35 additions and 0 deletions

35
tests/test_markup.py Normal file
View File

@ -0,0 +1,35 @@
import pytest
from rich.markup import MarkupError, _parse, render
from rich.text import Span
def test_parse():
result = list(_parse("[foo]hello[/foo][bar]world[/][[escaped]]"))
expected = [
(None, "[foo]"),
("hello", None),
(None, "[/foo]"),
(None, "[bar]"),
("world", None),
(None, "[/]"),
("[", None),
("escaped", None),
("]", None),
]
assert result == expected
def test_render():
result = render("[bold]FOO[/bold]")
assert str(result) == "FOO"
assert result.spans == [Span(0, 3, "bold")]
def test_markup_error():
with pytest.raises(MarkupError):
assert render("foo[/]")
with pytest.raises(MarkupError):
assert render("foo[/bar]")
with pytest.raises(MarkupError):
assert render("[foo]hello[/bar]")