summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/idle_test/test_pyshell.py
diff options
context:
space:
mode:
authorTal Einat <532281+taleinat@users.noreply.github.com>2021-04-28 22:27:55 (GMT)
committerGitHub <noreply@github.com>2021-04-28 22:27:55 (GMT)
commit15d386185659683fc044ccaa300aa8cd7d49cc1a (patch)
tree6fac7df4ac125b39648d8f0d7fbb008212dc6ba8 /Lib/idlelib/idle_test/test_pyshell.py
parent103d5e420dd90489933ad9da8bb1d6008773384d (diff)
downloadcpython-15d386185659683fc044ccaa300aa8cd7d49cc1a.zip
cpython-15d386185659683fc044ccaa300aa8cd7d49cc1a.tar.gz
cpython-15d386185659683fc044ccaa300aa8cd7d49cc1a.tar.bz2
bpo-37903: IDLE: Shell sidebar with prompts (GH-22682)
The first followup will change shell indents to spaces. More are expected. Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib/idlelib/idle_test/test_pyshell.py')
-rw-r--r--Lib/idlelib/idle_test/test_pyshell.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/Lib/idlelib/idle_test/test_pyshell.py b/Lib/idlelib/idle_test/test_pyshell.py
index 4a09667..7067039 100644
--- a/Lib/idlelib/idle_test/test_pyshell.py
+++ b/Lib/idlelib/idle_test/test_pyshell.py
@@ -60,5 +60,89 @@ class PyShellFileListTest(unittest.TestCase):
## self.assertIsInstance(ps, pyshell.PyShell)
+class PyShellRemoveLastNewlineAndSurroundingWhitespaceTest(unittest.TestCase):
+ regexp = pyshell.PyShell._last_newline_re
+
+ def all_removed(self, text):
+ self.assertEqual('', self.regexp.sub('', text))
+
+ def none_removed(self, text):
+ self.assertEqual(text, self.regexp.sub('', text))
+
+ def check_result(self, text, expected):
+ self.assertEqual(expected, self.regexp.sub('', text))
+
+ def test_empty(self):
+ self.all_removed('')
+
+ def test_newline(self):
+ self.all_removed('\n')
+
+ def test_whitespace_no_newline(self):
+ self.all_removed(' ')
+ self.all_removed(' ')
+ self.all_removed(' ')
+ self.all_removed(' ' * 20)
+ self.all_removed('\t')
+ self.all_removed('\t\t')
+ self.all_removed('\t\t\t')
+ self.all_removed('\t' * 20)
+ self.all_removed('\t ')
+ self.all_removed(' \t')
+ self.all_removed(' \t \t ')
+ self.all_removed('\t \t \t')
+
+ def test_newline_with_whitespace(self):
+ self.all_removed(' \n')
+ self.all_removed('\t\n')
+ self.all_removed(' \t\n')
+ self.all_removed('\t \n')
+ self.all_removed('\n ')
+ self.all_removed('\n\t')
+ self.all_removed('\n \t')
+ self.all_removed('\n\t ')
+ self.all_removed(' \n ')
+ self.all_removed('\t\n ')
+ self.all_removed(' \n\t')
+ self.all_removed('\t\n\t')
+ self.all_removed('\t \t \t\n')
+ self.all_removed(' \t \t \n')
+ self.all_removed('\n\t \t \t')
+ self.all_removed('\n \t \t ')
+
+ def test_multiple_newlines(self):
+ self.check_result('\n\n', '\n')
+ self.check_result('\n' * 5, '\n' * 4)
+ self.check_result('\n' * 5 + '\t', '\n' * 4)
+ self.check_result('\n' * 20, '\n' * 19)
+ self.check_result('\n' * 20 + ' ', '\n' * 19)
+ self.check_result(' \n \n ', ' \n')
+ self.check_result(' \n\n ', ' \n')
+ self.check_result(' \n\n', ' \n')
+ self.check_result('\t\n\n', '\t\n')
+ self.check_result('\n\n ', '\n')
+ self.check_result('\n\n\t', '\n')
+ self.check_result(' \n \n ', ' \n')
+ self.check_result('\t\n\t\n\t', '\t\n')
+
+ def test_non_whitespace(self):
+ self.none_removed('a')
+ self.check_result('a\n', 'a')
+ self.check_result('a\n ', 'a')
+ self.check_result('a \n ', 'a')
+ self.check_result('a \n\t', 'a')
+ self.none_removed('-')
+ self.check_result('-\n', '-')
+ self.none_removed('.')
+ self.check_result('.\n', '.')
+
+ def test_unsupported_whitespace(self):
+ self.none_removed('\v')
+ self.none_removed('\n\v')
+ self.check_result('\v\n', '\v')
+ self.none_removed(' \n\v')
+ self.check_result('\v\n ', '\v')
+
+
if __name__ == '__main__':
unittest.main(verbosity=2)