mirror of https://github.com/Textualize/rich.git
test markup
This commit is contained in:
parent
6b59f45c70
commit
7c8d43b16d
|
@ -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]")
|
Loading…
Reference in New Issue