Merge branch 'master' of git://github.com/vonzimr/evennia into vonzimr-master

This commit is contained in:
Griatch 2017-10-12 19:28:33 +02:00
commit eeacf01427
2 changed files with 86 additions and 4 deletions

View file

@ -20,6 +20,7 @@ IRC_BOLD = "\002"
IRC_COLOR = "\003"
IRC_RESET = "\017"
IRC_ITALIC = "\026"
IRC_INVERT = "\x16"
IRC_NORMAL = "99"
IRC_UNDERLINE = "37"
@ -38,7 +39,7 @@ IRC_CYAN = "11"
IRC_BLUE = "12"
IRC_MAGENTA = "13"
IRC_DGREY = "14"
IRC_GRAY = "15"
IRC_GREY = "15"
# obsolete test:
@ -57,7 +58,7 @@ IRC_COLOR_MAP = dict((
(r'|t', " "), # tab
(r'|-', " "), # fixed tab
(r'|_', " "), # space
(r'|*', ""), # invert
(r'|*', IRC_INVERT), # invert
(r'|^', ""), # blinking text
(r'|h', IRC_BOLD), # highlight, use bold instead
@ -76,7 +77,7 @@ IRC_COLOR_MAP = dict((
(r'|B', IRC_COLOR + IRC_DBLUE),
(r'|M', IRC_COLOR + IRC_DMAGENTA),
(r'|C', IRC_COLOR + IRC_DCYAN),
(r'|W', IRC_COLOR + IRC_GRAY), # light grey
(r'|W', IRC_COLOR + IRC_GREY), # light grey
(r'|X', IRC_COLOR + IRC_BLACK), # pure black
(r'|[r', IRC_COLOR + IRC_NORMAL + "," + IRC_DRED),
@ -85,7 +86,7 @@ IRC_COLOR_MAP = dict((
(r'|[b', IRC_COLOR + IRC_NORMAL + "," + IRC_DBLUE),
(r'|[m', IRC_COLOR + IRC_NORMAL + "," + IRC_DMAGENTA),
(r'|[c', IRC_COLOR + IRC_NORMAL + "," + IRC_DCYAN),
(r'|[w', IRC_COLOR + IRC_NORMAL + "," + IRC_GRAY), # light grey background
(r'|[w', IRC_COLOR + IRC_NORMAL + "," + IRC_GREY), # light grey background
(r'|[x', IRC_COLOR + IRC_NORMAL + "," + IRC_BLACK) # pure black background
))
# ansi->irc

View file

@ -0,0 +1,81 @@
try:
from django.utils.unittest import TestCase
except ImportError:
from django.test import TestCase
try:
from django.utils import unittest
except ImportError:
import unittest
import string
from evennia.server.portal import irc
class TestIRC(TestCase):
def test_plain_ansi(self):
"""
Test that printable characters do not get mangled.
"""
irc_ansi = irc.parse_ansi_to_irc(string.printable)
ansi_irc = irc.parse_irc_to_ansi(string.printable)
self.assertEqual(irc_ansi, string.printable)
self.assertEqual(ansi_irc, string.printable)
def test_evennia_strings(self):
pass
def test_irc_string(self):
pass
def test_bold(self):
s_irc = "\x02thisisatest"
s_eve = r'|hthisisatest'
self.assertEqual(irc.parse_ansi_to_irc(s_eve), s_irc)
self.assertEqual(s_eve, irc.parse_irc_to_ansi(s_irc))
def test_italic(self):
s_irc = "\x02thisisatest"
s_eve = r'|hthisisatest'
self.assertEqual(irc.parse_ansi_to_irc(s_eve), s_irc)
def test_colors(self):
color_map = (("\0030", r'|w'),
("\0031", r'|X'),
("\0032", r'|B'),
("\0033", r'|G'),
("\0034", r'|r'),
("\0035", r'|R'),
("\0036", r'|M'),
("\0037", r'|Y'),
("\0038", r'|y'),
("\0039", r'|g'),
("\00310", r'|C'),
("\00311", r'|c'),
("\00312", r'|b'),
("\00313", r'|m'),
("\00314", r'|x'),
("\00315", r'|W'),
("\00399,5", r'|[r'),
("\00399,3", r'|[g'),
("\00399,7", r'|[y'),
("\00399,2", r'|[b'),
("\00399,6", r'|[m'),
("\00399,10", r'|[c'),
("\00399,15", r'|[w'),
("\00399,1", r'|[x'))
for m in color_map:
self.assertEqual(irc.parse_irc_to_ansi(m[0]), m[1])
self.assertEqual(m[0], irc.parse_ansi_to_irc(m[1]))
def test_identity(self):
"""
Test that the composition of the function and
its inverse gives the correct string.
"""
s = r'|wthis|Xis|gis|Ma|C|complex|*string'
self.assertEqual(irc.parse_irc_to_ansi(irc.parse_ansi_to_irc(s)), s)