~pyreadline/pyreadline/trunk

« back to all changes in this revision

Viewing changes to pyreadline/test/test_history.py

  • Committer: Jorgen Stenarson
  • Date: 2011-04-14 16:52:22 UTC
  • Revision ID: jorgen.stenarson@bostream.nu-20110414165222-i77zmr4fjt6jlf0d
Fix for reverse and forward incremental search

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#----------------------------------------------------------------------
19
19
RL=lineobj.ReadLineTextBuffer
20
20
 
21
 
class Test_linepos (unittest.TestCase):
22
 
    t=u"test text"
 
21
class Test_prev_next_history(unittest.TestCase):
 
22
    t = u"test text"
23
23
 
24
 
    def init_test(self):
25
 
        history._ignore_leading_spaces=False
26
 
        self.q=q=LineHistory()
27
 
        for x in [u"aaaa",u"aaba",u"aaca",u"akca",u"bbb",u"ako"]:
 
24
    def setUp(self):
 
25
        self.q = q = LineHistory()
 
26
        for x in [u"aaaa", u"aaba", u"aaca", u"akca", u"bbb", u"ako"]:
28
27
            q.add_history(RL(x))
29
28
 
30
29
    def test_previous_history (self):
31
 
        self.init_test()
32
 
        hist=self.q
33
 
        assert hist.history_cursor==6
34
 
        l=RL(u"")
35
 
        hist.previous_history(l)
36
 
        assert l.get_line_text()==u"ako"
37
 
        hist.previous_history(l)
38
 
        assert l.get_line_text()==u"bbb"
39
 
        hist.previous_history(l)
40
 
        assert l.get_line_text()==u"akca"
41
 
        hist.previous_history(l)
42
 
        assert l.get_line_text()==u"aaca"
43
 
        hist.previous_history(l)
44
 
        assert l.get_line_text()==u"aaba"
45
 
        hist.previous_history(l)
46
 
        assert l.get_line_text()==u"aaaa"
47
 
        hist.previous_history(l)
48
 
        assert l.get_line_text()==u"aaaa"
 
30
        hist = self.q
 
31
        assert hist.history_cursor == 6
 
32
        l = RL(u"")
 
33
        hist.previous_history(l)
 
34
        assert l.get_line_text() == u"ako"
 
35
        hist.previous_history(l)
 
36
        assert l.get_line_text() == u"bbb"
 
37
        hist.previous_history(l)
 
38
        assert l.get_line_text() == u"akca"
 
39
        hist.previous_history(l)
 
40
        assert l.get_line_text() == u"aaca"
 
41
        hist.previous_history(l)
 
42
        assert l.get_line_text() == u"aaba"
 
43
        hist.previous_history(l)
 
44
        assert l.get_line_text() == u"aaaa"
 
45
        hist.previous_history(l)
 
46
        assert l.get_line_text() == u"aaaa"
49
47
 
50
48
    def test_next_history (self):
51
 
        self.init_test()
52
49
        hist=self.q
53
50
        hist.beginning_of_history()
54
51
        assert hist.history_cursor==0
66
63
        hist.next_history(l)
67
64
        assert l.get_line_text()==u"ako"
68
65
 
69
 
    def init_test2(self):
70
 
        self.q=q=LineHistory()
 
66
class Test_prev_next_history(unittest.TestCase):
 
67
    t = u"test text"
 
68
 
 
69
    def setUp(self):
 
70
        self.q = q = LineHistory()
71
71
        for x in [u"aaaa",u"aaba",u"aaca",u"akca",u"bbb",u"ako"]:
72
72
            q.add_history(RL(x))
73
73
        
74
74
    def test_history_search_backward (self):
75
 
        history._ignore_leading_spaces=False
76
 
        q=LineHistory()
 
75
        q = LineHistory()
77
76
        for x in [u"aaaa",u"aaba",u"aaca",u"    aacax",u"akca",u"bbb",u"ako"]:
78
77
            q.add_history(RL(x))
79
78
        a=RL(u"aa",point=2)
82
81
            assert res.get_line_text()==x
83
82
        
84
83
    def test_history_search_forward (self):
85
 
        history._ignore_leading_spaces=False
86
 
        q=LineHistory()
 
84
        q = LineHistory()
87
85
        for x in [u"aaaa",u"aaba",u"aaca",u"    aacax",u"akca",u"bbb",u"ako"]:
88
86
            q.add_history(RL(x))
89
87
        q.beginning_of_history()
92
90
            res=q.history_search_forward(a)
93
91
            assert res.get_line_text()==x
94
92
 
 
93
class Test_history_search_incr_fwd_backwd(unittest.TestCase):
 
94
    def setUp(self):
 
95
        self.q = q = LineHistory()
 
96
        for x in [u"aaaa",u"aaba",u"aaca",u"akca",u"bbb",u"ako"]:
 
97
            q.add_history(RL(x))
 
98
 
 
99
    def test_backward_1(self):
 
100
        q = self.q
 
101
        self.assertEqual(q.reverse_search_history(u"b"), u"bbb") 
 
102
        self.assertEqual(q.reverse_search_history(u"b"), u"aaba") 
 
103
        self.assertEqual(q.reverse_search_history(u"bb"), u"aaba") 
 
104
 
 
105
    def test_backward_2(self):
 
106
        q = self.q
 
107
        self.assertEqual(q.reverse_search_history(u"a"), u"ako") 
 
108
        self.assertEqual(q.reverse_search_history(u"aa"), u"aaca") 
 
109
        self.assertEqual(q.reverse_search_history(u"a"), u"aaca") 
 
110
        self.assertEqual(q.reverse_search_history(u"ab"), u"aaba") 
 
111
 
 
112
 
 
113
    def test_forward_1(self):
 
114
        q = self.q
 
115
        self.assertEqual(q.forward_search_history(u"a"), u"") 
 
116
 
 
117
    def test_forward_2(self):
 
118
        q = self.q
 
119
        q.history_cursor = 0
 
120
        self.assertEqual(q.forward_search_history(u"a"), u"aaaa") 
 
121
        self.assertEqual(q.forward_search_history(u"a"), u"aaba") 
 
122
        self.assertEqual(q.forward_search_history(u"ak"), u"akca") 
 
123
        self.assertEqual(q.forward_search_history(u"akl"), u"akca") 
 
124
        self.assertEqual(q.forward_search_history(u"ak"), u"akca") 
 
125
        self.assertEqual(q.forward_search_history(u"ako"), u"ako") 
 
126
        
95
127
 
96
128
#----------------------------------------------------------------------
97
129
# utility functions