2 # -*- coding: utf-8 -*-
7 from os
.path
import dirname
, abspath
, join
9 sys
.path
.insert(0, '..')
10 sys
.argv
[0] = dirname(sys
.argv
[0])
13 from EditWindow
import EditWindow
16 class TestReplace(unittest
.TestCase
):
18 self
.win
= EditWindow(show
= False)
19 self
.win
.buffer.begin_user_action()
20 self
.win
.buffer.insert_at_cursor("Hello\n")
21 self
.win
.buffer.end_user_action()
22 self
.win
.buffer.start_undo_history()
28 s
= self
.win
.buffer.get_start_iter()
29 e
= self
.win
.buffer.get_end_iter()
30 return self
.win
.buffer.get_text(s
, e
, True)
32 def assertNow(self
, expected
):
33 actual
= self
.get_text()
34 if actual
!= expected
:
35 raise AssertionError("Incorrect final text.\n"
36 "Expected:\n%s\nActual:\n%s" % (expected
[:100], actual
[:100]))
39 self
.win
.process_selected(lambda x
: "World")
40 self
.assertNow("World\n")
42 self
.assertNow("Hello\n")
44 def testReplace(self
):
46 self
.win
.buffer.begin_user_action()
47 self
.win
.buffer.insert_at_cursor("deàça")
48 self
.win
.buffer.end_user_action()
49 replace
= search
.Replace(self
.win
)
50 replace
.replace_entry
.set_text("a")
51 replace
.with_entry
.set_text("b")
52 replace
.do_replace(show_info
= False)
54 self
.assertNow("deàçb")
57 self
.assertNow("deàça")