@@ -27,20 +27,37 @@ def test_debug(self):
2727 def test_search (self ):
2828 text = self .text
2929
30- # pattern and index are obligatory arguments.
3130 self .assertRaises (tkinter .TclError , text .search , None , '1.0' )
3231 self .assertRaises (tkinter .TclError , text .search , 'a' , None )
3332 self .assertRaises (tkinter .TclError , text .search , None , None )
34-
35- # Invalid text index.
3633 self .assertRaises (tkinter .TclError , text .search , '' , 0 )
3734
38- # Check if we are getting the indices as strings -- you are likely
39- # to get Tcl_Obj under Tk 8.5 if Tkinter doesn't convert it.
4035 text .insert ('1.0' , 'hi-test' )
4136 self .assertEqual (text .search ('-test' , '1.0' , 'end' ), '1.2' )
4237 self .assertEqual (text .search ('test' , '1.0' , 'end' ), '1.3' )
4338
39+ text .delete ('1.0' , 'end' )
40+ text .insert ('1.0' ,
41+ 'This is a test. This is only a test.\n '
42+ 'Another line.\n '
43+ 'Yet another line.' )
44+
45+ result = text .search ('line' , '1.0' , 'end' , nolinestop = True , regexp = True )
46+ self .assertEqual (result , '2.8' )
47+
48+ all_res = text .search ('test' , '1.0' , 'end' , all = True )
49+ self .assertIsInstance (all_res , str )
50+ indices = all_res .split ()
51+ self .assertGreaterEqual (len (indices ), 2 )
52+ self .assertTrue (all (isinstance (i , str ) for i in indices ))
53+
54+ overlap_res = text .search ('test' , '1.0' , 'end' , all = True , overlap = True )
55+ self .assertIsInstance (overlap_res , str )
56+ self .assertIn ('textindex' , overlap_res )
57+
58+ strict_res = text .search ('test' , '1.0' , '1.20' , strictlimits = True )
59+ self .assertEqual (strict_res , '1.10' )
60+
4461 def test_count (self ):
4562 text = self .text
4663 text .insert ('1.0' ,
@@ -94,34 +111,5 @@ def test_count(self):
94111 self .assertEqual (text .count ('1.3' , '1.3' , 'update' , return_ints = True ), 0 )
95112 self .assertEqual (text .count ('1.3' , '1.3' , 'update' ), None )
96113
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.\n Yet 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 , str )
113- indices = result .split ()
114- self .assertGreaterEqual (len (indices ), 2 )
115- self .assertTrue (all (isinstance (i , str ) for i in indices ))
116-
117- def test_overlap (self ):
118- result = self .text .search ('test' , '1.0' , 'end' , all = True , overlap = True )
119- self .assertIsInstance (result , str )
120- self .assertIn ("textindex" , result )
121-
122- def test_strictlimits (self ):
123- result = self .text .search ('test' , '1.0' , '1.20' , strictlimits = True )
124- self .assertEqual (result , '1.10' )
125-
126114if __name__ == "__main__" :
127115 unittest .main ()
0 commit comments