1 # -*- test-case-name: twisted.conch.test.test_text -*-
2 # Copyright (c) Twisted Matrix Laboratories.
3 # See LICENSE for details.
5 from twisted.trial import unittest
7 from twisted.conch.insults import helper, text
11 class Serialization(unittest.TestCase):
13 self.attrs = helper.CharacterAttribute()
15 def testTrivial(self):
17 text.flatten(A.normal['Hello, world.'], self.attrs),
22 text.flatten(A.bold['Hello, world.'], self.attrs),
23 '\x1b[1mHello, world.')
25 def testUnderline(self):
27 text.flatten(A.underline['Hello, world.'], self.attrs),
28 '\x1b[4mHello, world.')
32 text.flatten(A.blink['Hello, world.'], self.attrs),
33 '\x1b[5mHello, world.')
35 def testReverseVideo(self):
37 text.flatten(A.reverseVideo['Hello, world.'], self.attrs),
38 '\x1b[7mHello, world.')
43 A.bold[A.blink['Hello', -A.bold[' world'], '.']],
45 '\x1b[1;5mHello\x1b[0;5m world\x1b[1;5m.')
47 def testForeground(self):
50 A.normal[A.fg.red['Hello, '], A.fg.green['world!']],
52 '\x1b[31mHello, \x1b[32mworld!')
54 def testBackground(self):
57 A.normal[A.bg.red['Hello, '], A.bg.green['world!']],
59 '\x1b[41mHello, \x1b[42mworld!')
62 class EfficiencyTestCase(unittest.TestCase):
63 todo = ("flatten() isn't quite stateful enough to avoid emitting a few extra bytes in "
64 "certain circumstances, so these tests fail. The failures take the form of "
65 "additional elements in the ;-delimited character attribute lists. For example, "
66 "\\x1b[0;31;46m might be emitted instead of \\x[46m, even if 31 has already been "
67 "activated and no conflicting attributes are set which need to be cleared.")
70 self.attrs = helper.CharacterAttribute()
72 def testComplexStructure(self):
77 "Foreground Red, Background Cyan, Bold",
81 "Foreground Red, Background Cyan, normal"]],
83 "Foreground Green, Background Cyan, Bold"]]]]
86 text.flatten(output, self.attrs),
87 "\x1b[1;31;46mForeground Red, Background Cyan, Bold"
89 "\x1b[0;31;46mForeground Red, Background Cyan, normal"
90 "\x1b[1;32;46mForeground Green, Background Cyan, Bold")
92 def testNesting(self):
94 text.flatten(A.bold['Hello, ', A.underline['world.']], self.attrs),
95 '\x1b[1mHello, \x1b[4mworld.')
99 A.bold[A.reverseVideo['Hello, ', A.normal['world'], '.']],
101 '\x1b[1;7mHello, \x1b[0mworld\x1b[1;7m.')