1 #!/usr/bin/env python2.2
5 from os
.path
import dirname
, abspath
, join
7 sys
.path
.insert(0, '..')
8 sys
.argv
[0] = dirname(sys
.argv
[0])
11 from EditWindow
import EditWindow
14 class TestReplace(unittest
.TestCase
):
16 self
.win
= EditWindow(show
= False)
17 self
.win
.buffer.begin_user_action()
18 self
.win
.buffer.insert_at_cursor("Hello\n")
19 self
.win
.buffer.end_user_action()
20 self
.win
.buffer.start_undo_history()
26 s
= self
.win
.buffer.get_start_iter()
27 e
= self
.win
.buffer.get_end_iter()
28 return self
.win
.buffer.get_text(s
, e
, True)
30 def assertNow(self
, expected
):
31 actual
= self
.get_text()
32 if actual
!= expected
:
33 raise AssertionError("Incorrect final text.\n"
34 "Expected:\n%s\nActual:\n%s" % (expected
[:100], actual
[:100]))
37 self
.win
.process_selected(lambda x
: "World")
38 self
.assertNow("World\n")
40 self
.assertNow("Hello\n")
42 def testReplace(self
):
44 self
.win
.buffer.begin_user_action()
45 self
.win
.buffer.insert_at_cursor("deàça")
46 self
.win
.buffer.end_user_action()
47 replace
= search
.Replace(self
.win
)
48 replace
.replace_entry
.set_text("a")
49 replace
.with_entry
.set_text("b")
50 replace
.do_replace(show_info
= False)
52 self
.assertNow("deàçb")
55 self
.assertNow("deàça")