|
6 | 6 | import os
|
7 | 7 |
|
8 | 8 | from IPython.testing import tools as tt, decorators as dec
|
9 |
| -from IPython.core.prompts import PromptManager, LazyEvaluate |
| 9 | +from IPython.core.prompts import PromptManager, LazyEvaluate, _invisible_characters |
10 | 10 | from IPython.testing.globalipapp import get_ipython
|
11 | 11 | from IPython.utils.tempdir import TemporaryWorkingDirectory
|
12 | 12 | from IPython.utils import py3compat
|
@@ -106,4 +106,24 @@ def test_cwd_x(self):
|
106 | 106 | self.assertEqual(p, '~')
|
107 | 107 | finally:
|
108 | 108 | os.chdir(save)
|
109 |
| - |
| 109 | + |
| 110 | + def test_invisible_chars(self): |
| 111 | + self.assertEqual(_invisible_characters('abc'), 0) |
| 112 | + self.assertEqual(_invisible_characters('\001\033[1;37m\002'), 9) |
| 113 | + # Sequences must be between \001 and \002 to be counted |
| 114 | + self.assertEqual(_invisible_characters('\033[1;37m'), 0) |
| 115 | + # Test custom escape sequences |
| 116 | + self.assertEqual(_invisible_characters('\001\033]133;A\a\002'), 10) |
| 117 | + |
| 118 | + def test_width(self): |
| 119 | + default_in = '\x01\x1b]133;A\x07\x02In [1]: \x01\x1b]133;B\x07\x02' |
| 120 | + self.pm.in_template = default_in |
| 121 | + self.pm.render('in') |
| 122 | + self.assertEqual(self.pm.width, 8) |
| 123 | + self.assertEqual(self.pm.txtwidth, 8) |
| 124 | + |
| 125 | + # Test custom escape sequences |
| 126 | + self.pm.in_template = '\001\033]133;A\a\002' + default_in + '\001\033]133;B\a\002' |
| 127 | + self.pm.render('in') |
| 128 | + self.assertEqual(self.pm.width, 8) |
| 129 | + self.assertEqual(self.pm.txtwidth, 8) |
0 commit comments