MCPcopy Index your code
hub / github.com/python/cpython / test_replace_simple

Method test_replace_simple

Lib/idlelib/idle_test/test_replace.py:55–123  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

53 self.text.delete('1.0', 'end')
54
55 def test_replace_simple(self):
56 # Test replace function with all options at default setting.
57 # Wrap around - True
58 # Regular Expression - False
59 # Match case - False
60 # Match word - False
61 # Direction - Forwards
62 text = self.text
63 equal = self.assertEqual
64 pv = self.engine.patvar
65 rv = self.dialog.replvar
66 replace = self.dialog.replace_it
67
68 # test accessor method
69 self.engine.setpat('asdf')
70 equal(self.engine.getpat(), pv.get())
71
72 # text found and replaced
73 pv.set('a')
74 rv.set('asdf')
75 replace()
76 equal(text.get('1.8', '1.12'), 'asdf')
77
78 # don't "match word" case
79 text.mark_set('insert', '1.0')
80 pv.set('is')
81 rv.set('hello')
82 replace()
83 equal(text.get('1.2', '1.7'), 'hello')
84
85 # don't "match case" case
86 pv.set('string')
87 rv.set('world')
88 replace()
89 equal(text.get('1.23', '1.28'), 'world')
90
91 # without "regular expression" case
92 text.mark_set('insert', 'end')
93 text.insert('insert', '\nline42:')
94 before_text = text.get('1.0', 'end')
95 pv.set(r'[a-z][\d]+')
96 replace()
97 after_text = text.get('1.0', 'end')
98 equal(before_text, after_text)
99
100 # test with wrap around selected and complete a cycle
101 text.mark_set('insert', '1.9')
102 pv.set('i')
103 rv.set('j')
104 replace()
105 equal(text.get('1.8'), 'i')
106 equal(text.get('2.1'), 'j')
107 replace()
108 equal(text.get('2.1'), 'j')
109 equal(text.get('1.8'), 'j')
110 before_text = text.get('1.0', 'end')
111 replace()
112 after_text = text.get('1.0', 'end')

Callers

nothing calls this directly

Calls 8

setpatMethod · 0.80
find_itMethod · 0.80
replaceFunction · 0.50
getpatMethod · 0.45
getMethod · 0.45
setMethod · 0.45
mark_setMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected