mirror of
https://github.com/evennia/evennia.git
synced 2026-03-23 00:06:30 +01:00
Increase coverage in evennia/utils/text2html
This commit is contained in:
parent
77965fadd3
commit
cea0e1a0a4
2 changed files with 58 additions and 2 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
from django.test import TestCase
|
||||
from evennia.utils import ansi, text2html
|
||||
import mock
|
||||
|
||||
|
||||
class TestText2Html(TestCase):
|
||||
|
|
@ -90,6 +91,62 @@ class TestText2Html(TestCase):
|
|||
"a red foo",
|
||||
parser.re_double_space("a red foo"))
|
||||
|
||||
def test_sub_text(self):
|
||||
parser = text2html.HTML_PARSER
|
||||
mocked_match = mock.Mock()
|
||||
mocked_match.groupdict.return_value = {
|
||||
"htmlchars": "foo"
|
||||
}
|
||||
self.assertEqual(
|
||||
"foo",
|
||||
parser.sub_text(mocked_match))
|
||||
mocked_match.groupdict.return_value = {
|
||||
"htmlchars": "",
|
||||
"lineend": "foo",
|
||||
}
|
||||
self.assertEqual(
|
||||
"<br>",
|
||||
parser.sub_text(mocked_match))
|
||||
mocked_match.groupdict.return_value = {
|
||||
"htmlchars": "",
|
||||
"lineend": "",
|
||||
"firstspace": "foo"
|
||||
}
|
||||
self.assertEqual(
|
||||
" ",
|
||||
parser.sub_text(mocked_match))
|
||||
parser.tabstop = 2
|
||||
mocked_match.groupdict.return_value = {
|
||||
"htmlchars": "",
|
||||
"lineend": "",
|
||||
"firstspace": "",
|
||||
"space": "\t"
|
||||
}
|
||||
self.assertEqual(
|
||||
" ",
|
||||
parser.sub_text(mocked_match))
|
||||
mocked_match.groupdict.return_value = {
|
||||
"htmlchars": "",
|
||||
"lineend": "",
|
||||
"firstspace": "",
|
||||
"space": " ",
|
||||
"spacestart": " "
|
||||
}
|
||||
mocked_match.group.return_value = " \t "
|
||||
self.assertEqual(
|
||||
" ",
|
||||
parser.sub_text(mocked_match))
|
||||
mocked_match.groupdict.return_value = {
|
||||
"htmlchars": "",
|
||||
"lineend": "",
|
||||
"firstspace": "",
|
||||
"space": "",
|
||||
"spacestart": ""
|
||||
}
|
||||
self.assertEqual(
|
||||
None,
|
||||
parser.sub_text(mocked_match))
|
||||
|
||||
def test_parse_html(self):
|
||||
self.assertEqual("foo", text2html.parse_html("foo"))
|
||||
self.maxDiff = None
|
||||
|
|
|
|||
|
|
@ -310,8 +310,7 @@ class TextToHTMLparser(object):
|
|||
elif cdict["firstspace"]:
|
||||
return " "
|
||||
elif cdict["space"] == "\t":
|
||||
text = match.group()
|
||||
return " " if tabstop == 1 else " " + " " * tabstop
|
||||
return " " if self.tabstop == 1 else " " + " " * self.tabstop
|
||||
elif cdict["space"] or cdict["spacestart"]:
|
||||
text = match.group().replace("\t", " " * self.tabstop)
|
||||
text = text.replace(" ", " ")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue