1 | n/a | import unittest |
---|
2 | n/a | import idlelib.rstrip as rs |
---|
3 | n/a | from idlelib.idle_test.mock_idle import Editor |
---|
4 | n/a | |
---|
5 | n/a | class rstripTest(unittest.TestCase): |
---|
6 | n/a | |
---|
7 | n/a | def test_rstrip_line(self): |
---|
8 | n/a | editor = Editor() |
---|
9 | n/a | text = editor.text |
---|
10 | n/a | do_rstrip = rs.RstripExtension(editor).do_rstrip |
---|
11 | n/a | |
---|
12 | n/a | do_rstrip() |
---|
13 | n/a | self.assertEqual(text.get('1.0', 'insert'), '') |
---|
14 | n/a | text.insert('1.0', ' ') |
---|
15 | n/a | do_rstrip() |
---|
16 | n/a | self.assertEqual(text.get('1.0', 'insert'), '') |
---|
17 | n/a | text.insert('1.0', ' \n') |
---|
18 | n/a | do_rstrip() |
---|
19 | n/a | self.assertEqual(text.get('1.0', 'insert'), '\n') |
---|
20 | n/a | |
---|
21 | n/a | def test_rstrip_multiple(self): |
---|
22 | n/a | editor = Editor() |
---|
23 | n/a | # Uncomment following to verify that test passes with real widgets. |
---|
24 | n/a | ## from idlelib.editor import EditorWindow as Editor |
---|
25 | n/a | ## from tkinter import Tk |
---|
26 | n/a | ## editor = Editor(root=Tk()) |
---|
27 | n/a | text = editor.text |
---|
28 | n/a | do_rstrip = rs.RstripExtension(editor).do_rstrip |
---|
29 | n/a | |
---|
30 | n/a | original = ( |
---|
31 | n/a | "Line with an ending tab \n" |
---|
32 | n/a | "Line ending in 5 spaces \n" |
---|
33 | n/a | "Linewithnospaces\n" |
---|
34 | n/a | " indented line\n" |
---|
35 | n/a | " indented line with trailing space \n" |
---|
36 | n/a | " ") |
---|
37 | n/a | stripped = ( |
---|
38 | n/a | "Line with an ending tab\n" |
---|
39 | n/a | "Line ending in 5 spaces\n" |
---|
40 | n/a | "Linewithnospaces\n" |
---|
41 | n/a | " indented line\n" |
---|
42 | n/a | " indented line with trailing space\n") |
---|
43 | n/a | |
---|
44 | n/a | text.insert('1.0', original) |
---|
45 | n/a | do_rstrip() |
---|
46 | n/a | self.assertEqual(text.get('1.0', 'insert'), stripped) |
---|
47 | n/a | |
---|
48 | n/a | if __name__ == '__main__': |
---|
49 | n/a | unittest.main(verbosity=2, exit=False) |
---|