If turning on spell checking doesn't work, report the error.
[rox-edit.git] / tests / testreplace.py
blobc57c1710172e6d946c8edcea3d279fca971b1ee0
1 #!/usr/bin/env python2.2
2 import unittest
3 import sys
4 import os, time
5 from os.path import dirname, abspath, join
7 sys.path.insert(0, '..')
8 sys.argv[0] = dirname(sys.argv[0])
10 import setup
11 from EditWindow import EditWindow
12 import search
14 class TestReplace(unittest.TestCase):
15 def setUp(self):
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()
22 def tearDown(self):
23 self.win.destroy()
25 def get_text(self):
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]))
36 def testSimple(self):
37 self.win.process_selected(lambda x: "World")
38 self.assertNow("World\n")
39 self.win.undo()
40 self.assertNow("Hello\n")
42 def testReplace(self):
43 self.win.undo()
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")
54 self.win.undo()
55 self.assertNow("deàça")
58 sys.argv.append('-v')
59 unittest.main()