2018-06-19 20:12:52 -03:00
|
|
|
"Test rstrip, coverage 100%."
|
|
|
|
|
|
|
|
from idlelib import rstrip
|
2013-07-13 03:34:43 -03:00
|
|
|
import unittest
|
|
|
|
from idlelib.idle_test.mock_idle import Editor
|
|
|
|
|
|
|
|
class rstripTest(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_rstrip_line(self):
|
|
|
|
editor = Editor()
|
|
|
|
text = editor.text
|
2018-06-20 04:42:13 -03:00
|
|
|
do_rstrip = rstrip.Rstrip(editor).do_rstrip
|
2013-07-13 03:34:43 -03:00
|
|
|
|
|
|
|
do_rstrip()
|
|
|
|
self.assertEqual(text.get('1.0', 'insert'), '')
|
|
|
|
text.insert('1.0', ' ')
|
|
|
|
do_rstrip()
|
|
|
|
self.assertEqual(text.get('1.0', 'insert'), '')
|
|
|
|
text.insert('1.0', ' \n')
|
|
|
|
do_rstrip()
|
|
|
|
self.assertEqual(text.get('1.0', 'insert'), '\n')
|
|
|
|
|
|
|
|
def test_rstrip_multiple(self):
|
|
|
|
editor = Editor()
|
2018-06-19 20:12:52 -03:00
|
|
|
# Comment above, uncomment 3 below to test with real Editor & Text.
|
|
|
|
#from idlelib.editor import EditorWindow as Editor
|
|
|
|
#from tkinter import Tk
|
|
|
|
#editor = Editor(root=Tk())
|
2013-07-13 03:34:43 -03:00
|
|
|
text = editor.text
|
2018-06-20 04:42:13 -03:00
|
|
|
do_rstrip = rstrip.Rstrip(editor).do_rstrip
|
2013-07-13 03:34:43 -03:00
|
|
|
|
|
|
|
original = (
|
|
|
|
"Line with an ending tab \n"
|
|
|
|
"Line ending in 5 spaces \n"
|
|
|
|
"Linewithnospaces\n"
|
|
|
|
" indented line\n"
|
|
|
|
" indented line with trailing space \n"
|
|
|
|
" ")
|
|
|
|
stripped = (
|
|
|
|
"Line with an ending tab\n"
|
|
|
|
"Line ending in 5 spaces\n"
|
|
|
|
"Linewithnospaces\n"
|
|
|
|
" indented line\n"
|
|
|
|
" indented line with trailing space\n")
|
|
|
|
|
|
|
|
text.insert('1.0', original)
|
|
|
|
do_rstrip()
|
|
|
|
self.assertEqual(text.get('1.0', 'insert'), stripped)
|
|
|
|
|
2018-06-19 20:12:52 -03:00
|
|
|
|
|
|
|
|
2013-07-13 03:34:43 -03:00
|
|
|
if __name__ == '__main__':
|
2018-06-19 20:12:52 -03:00
|
|
|
unittest.main(verbosity=2)
|