From 7c8d43b16d6b47555caeb00234590bc8d335ed71 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 13 Apr 2020 12:24:21 +0100 Subject: [PATCH] test markup --- tests/test_markup.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_markup.py diff --git a/tests/test_markup.py b/tests/test_markup.py new file mode 100644 index 00000000..7ce42496 --- /dev/null +++ b/tests/test_markup.py @@ -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]")