Example #1
0
    def test_replace_cursor(self):
        w = prompt.Search(mocks.FE(),
                          forward=False,
                          prompt='search ',
                          history='test_search',
                          target=mocks.Window([]))

        w.insert('fo')
        mark = w.make_mark(w.cursor)
        w.target.find_ret = False
        w.insert('o')
        self.assertEqual(w.cursor.point, mark.point + 1)
Example #2
0
    def test_search(self):
        w = prompt.Search(
            mocks.FE(),
            forward=False,
            prompt='search ',
            history='test_search',
            target=mocks.Window([]))

        self.assertFalse(w.forward)

        do(w.search(None, True))

        self.assertTrue(w.forward)

        w.setprompt()
        self.assertEqual(w.buf[:w.divider], 'search forward: ')

        self.assertIsNone(w.target.match_string)
        self.assertIsNone(w.target.match_forward)
        self.assertIsNone(w.target.find_string)
        self.assertIsNone(w.target.find_forward)

        w.insert('foo')
        self.assertEqual(w.target.match_re.pattern, 'foo')
        self.assertEqual(w.target.match_forward, True)
        self.assertEqual(w.target.find_re.pattern, 'foo')
        self.assertEqual(w.target.find_forward, True)

        self.assertEqual(w.target.search_re.pattern, 'foo')

        w.target.match_ret = True
        w.insert('f')
        self.assertEqual(w.target.match_re.pattern, 'foof')

        # sneak around w.replace
        w.buf.replace(w.divider, len(w.buf), 'bar', False)
        w.target.search_re = re.compile('bar')
        do(w.search(None, True))
        self.assertEqual(w.target.find_re.pattern, 'bar')

        w.delete_window()
        self.assertIn('set_active_input', w.fe.called)
        self.assertIn('delete_current_window', w.fe.called)

        w.destroy()
        self.assertIsNone(w.target.search_re)
Example #3
0
    def test_search1(self):
        x = editor.Editor(mocks.FE())
        x.insert('\n\n\nfoo\n\n\nfoo\n\n\n')

        self.assertEqual(x.cursor.point, len(x.buf))

        w = prompt.Search(
            mocks.FE(),
            forward=True,
            prompt='search ',
            history='test_search',
            target=x,
            start=x.make_mark(x.cursor.point),
        )

        w.insert('foo')

        do(w.search_forward())

        self.assertEqual(x.cursor.point, 3)

        do(w.search_backward())

        self.assertEqual(w.buf[:7], 'failing')

        do(w.search_backward())

        self.assertEqual(x.cursor.point, 9)

        w.abort()

        self.assertEqual(x.cursor.point, len(x.buf))

        del w

        x.cursor.point = 0

        w = prompt.Search(
            mocks.FE(),
            forward=True,
            prompt='search ',
            history='test_search',
            target=x,
            start=x.make_mark(x.cursor.point),
        )

        w.insert('foo')

        self.assertEqual(x.cursor.point, 3)

        w.callout('\n')

        self.assertEqual(x.cursor.point, 3)
        self.assertEqual(x.the_mark.point, 0)

        del w

        x.cursor.point = 6
        w = prompt.Search(
            mocks.FE(),
            forward=True,
            prompt='search ',
            history='test_search',
            target=x,
            start=x.make_mark(x.cursor.point),
        )

        w.insert('bar')
        do(w.search_forward())

        self.assertEqual(x.cursor.point, 6)