Skip to content

Commit 2601ddf

Browse files
authored
Add test cases to test_text.py
1 parent 7196a88 commit 2601ddf

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Lib/test/test_tkinter/test_text.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,33 @@ def test_count(self):
9494
self.assertEqual(text.count('1.3', '1.3', 'update', return_ints=True), 0)
9595
self.assertEqual(text.count('1.3', '1.3', 'update'), None)
9696

97+
class TextSearchOptionsTest(AbstractTkTest, unittest.TestCase):
98+
def setUp(self):
99+
super().setUp()
100+
self.text = tkinter.Text(self.root)
101+
self.text.pack()
102+
self.text.insert('1.0',
103+
'This is a test. This is only a test.\n'
104+
'Another line.\nYet another line.')
105+
106+
def test_nolinestop(self):
107+
result = self.text.search('line', '1.0', 'end', nolinestop=True, regexp=True)
108+
self.assertEqual(result, '2.8')
109+
110+
def test_all(self):
111+
result = self.text.search('test', '1.0', 'end', all=True)
112+
self.assertIsInstance(result, tuple)
113+
self.assertGreaterEqual(len(result), 2)
114+
self.assertTrue(all(str(index) for index in result)) # ensure valid index strings
115+
116+
def test_overlap(self):
117+
result = self.text.search('test', '1.0', 'end', all=True, overlap=True)
118+
self.assertIsInstance(result, tuple)
119+
self.assertGreaterEqual(len(result), 2)
120+
121+
def test_strictlimits(self):
122+
result = self.text.search('test', '1.0', '1.20', strictlimits=True)
123+
self.assertEqual(result, '1.10')
97124

98125
if __name__ == "__main__":
99126
unittest.main()

0 commit comments

Comments
 (0)