Unit tests for evennia/utils/text2html.
This commit is contained in:
parent
88a49334f2
commit
9e38cef5ff
2 changed files with 94 additions and 3 deletions
92
evennia/utils/tests/test_text2html.py
Normal file
92
evennia/utils/tests/test_text2html.py
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
"""Tests for text2html """
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
from evennia.utils import ansi, text2html
|
||||||
|
import mock
|
||||||
|
|
||||||
|
|
||||||
|
class TestText2Html(TestCase):
|
||||||
|
|
||||||
|
def test_re_color(self):
|
||||||
|
parser = text2html.HTML_PARSER
|
||||||
|
self.assertEqual("foo", parser.re_color("foo"))
|
||||||
|
self.assertEqual(
|
||||||
|
"<span class=\"err\">red</span>foo",
|
||||||
|
parser.re_color(ansi.ANSI_RED + "red" + ansi.ANSI_NORMAL + "foo"))
|
||||||
|
|
||||||
|
def test_re_bold(self):
|
||||||
|
parser = text2html.HTML_PARSER
|
||||||
|
self.assertEqual("foo", parser.re_bold("foo"))
|
||||||
|
self.assertEqual(
|
||||||
|
# "a <strong>red</strong>foo", # TODO: why not?
|
||||||
|
"a <strong>redfoo</strong>",
|
||||||
|
parser.re_bold(
|
||||||
|
"a " + ansi.ANSI_HILITE + "red" + ansi.ANSI_UNHILITE + "foo"))
|
||||||
|
|
||||||
|
def test_re_underline(self):
|
||||||
|
parser = text2html.HTML_PARSER
|
||||||
|
self.assertEqual("foo", parser.re_underline("foo"))
|
||||||
|
self.assertEqual(
|
||||||
|
"a <span class=\"underline\">red</span>" + ansi.ANSI_NORMAL + "foo",
|
||||||
|
parser.re_underline(
|
||||||
|
"a " + ansi.ANSI_UNDERLINE + "red"
|
||||||
|
+ ansi.ANSI_NORMAL # TODO: why does it keep it?
|
||||||
|
+ "foo"))
|
||||||
|
|
||||||
|
def test_re_blinking(self):
|
||||||
|
parser = text2html.HTML_PARSER
|
||||||
|
self.assertEqual("foo", parser.re_blinking("foo"))
|
||||||
|
self.assertEqual(
|
||||||
|
"a <span class=\"blink\">red</span>" + ansi.ANSI_NORMAL + "foo",
|
||||||
|
parser.re_blinking(
|
||||||
|
"a " + ansi.ANSI_BLINK + "red"
|
||||||
|
+ ansi.ANSI_NORMAL # TODO: why does it keep it?
|
||||||
|
+ "foo"))
|
||||||
|
|
||||||
|
def test_re_inversing(self):
|
||||||
|
parser = text2html.HTML_PARSER
|
||||||
|
self.assertEqual("foo", parser.re_inversing("foo"))
|
||||||
|
self.assertEqual(
|
||||||
|
"a <span class=\"inverse\">red</span>" + ansi.ANSI_NORMAL + "foo",
|
||||||
|
parser.re_inversing(
|
||||||
|
"a " + ansi.ANSI_INVERSE + "red"
|
||||||
|
+ ansi.ANSI_NORMAL # TODO: why does it keep it?
|
||||||
|
+ "foo"))
|
||||||
|
|
||||||
|
def test_remove_bells(self):
|
||||||
|
parser = text2html.HTML_PARSER
|
||||||
|
self.assertEqual("foo", parser.remove_bells("foo"))
|
||||||
|
self.assertEqual(
|
||||||
|
"a red" + ansi.ANSI_NORMAL + "foo",
|
||||||
|
parser.remove_bells(
|
||||||
|
"a " + ansi.ANSI_BEEP + "red"
|
||||||
|
+ ansi.ANSI_NORMAL # TODO: why does it keep it?
|
||||||
|
+ "foo"))
|
||||||
|
|
||||||
|
def test_remove_backspaces(self):
|
||||||
|
parser = text2html.HTML_PARSER
|
||||||
|
self.assertEqual("foo", parser.remove_backspaces("foo"))
|
||||||
|
self.assertEqual("redfoo",
|
||||||
|
parser.remove_backspaces("a\010redfoo"))
|
||||||
|
|
||||||
|
def test_convert_linebreaks(self):
|
||||||
|
parser = text2html.HTML_PARSER
|
||||||
|
self.assertEqual("foo", parser.convert_linebreaks("foo"))
|
||||||
|
self.assertEqual(
|
||||||
|
"a<br> redfoo<br>",
|
||||||
|
parser.convert_linebreaks("a\n redfoo\n"))
|
||||||
|
|
||||||
|
def test_convert_urls(self):
|
||||||
|
parser = text2html.HTML_PARSER
|
||||||
|
self.assertEqual("foo", parser.convert_urls("foo"))
|
||||||
|
self.assertEqual(
|
||||||
|
"a <a href=\"http://redfoo\" target=\"_blank\">http://redfoo</a> runs",
|
||||||
|
parser.convert_urls("a http://redfoo runs"))
|
||||||
|
# TODO: doesn't URL encode correctly
|
||||||
|
|
||||||
|
def test_re_double_space(self):
|
||||||
|
parser = text2html.HTML_PARSER
|
||||||
|
self.assertEqual("foo", parser.re_double_space("foo"))
|
||||||
|
self.assertEqual(
|
||||||
|
"a red foo",
|
||||||
|
parser.re_double_space("a red foo"))
|
||||||
|
|
@ -246,8 +246,7 @@ class TextToHTMLparser(object):
|
||||||
text (str): Processed text.
|
text (str): Processed text.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return text
|
return text.replace("\n", r"<br>")
|
||||||
return text.replace(r"\n", r"<br>")
|
|
||||||
|
|
||||||
def convert_urls(self, text):
|
def convert_urls(self, text):
|
||||||
"""
|
"""
|
||||||
|
|
@ -277,7 +276,7 @@ class TextToHTMLparser(object):
|
||||||
replaces MXP links with HTML code.
|
replaces MXP links with HTML code.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
text (str): Text to process.
|
match (re.Matchobject): Match for substitution.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
text (str): Processed text.
|
text (str): Processed text.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue