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>
This commit is contained in:
Tal Einat 2021-04-29 01:27:55 +03:00 committed by GitHub
parent 103d5e420d
commit 15d3861856
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 888 additions and 132 deletions

View file

@ -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)