summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorLaurent Charignon <l.charignon@gmail.com>2016-01-31 17:58:42 -0800
committerLaurent Charignon <l.charignon@gmail.com>2016-01-31 17:59:13 -0800
commitf54fe5ac282254f6ecd6de70d21b20889fae5b43 (patch)
treedf1922e666632e41eac548554e3972a5d395a1cc /tests
parenta559816d67f5f6e3b9a26566798000d8e848feee (diff)
downloadranger-f54fe5ac282254f6ecd6de70d21b20889fae5b43.tar.gz
history: fix logic error and add test for all the methods
Diffstat (limited to 'tests')
-rw-r--r--tests/ranger/container/test_container.py98
1 files changed, 96 insertions, 2 deletions
diff --git a/tests/ranger/container/test_container.py b/tests/ranger/container/test_container.py
index 5125245a..fafb30c5 100644
--- a/tests/ranger/container/test_container.py
+++ b/tests/ranger/container/test_container.py
@@ -1,5 +1,99 @@
 from ranger.container import history
 
 
-def testhistory(tmpdir):
-    assert True
+HISTORY_TEST_ENTRIES = [str(k) for k in range(20)]
+OTHER_TEST_ENTRIES = [str(k) for k in range(40,45)]
+
+def testhistorybasic():
+    # A history is a buffer of limited size that stores the last `maxlen`
+    # item added to it. It has a `current` index that serves as a cursor.
+
+    # A history has a limited size, check that only `maxlen` items are stored
+    h = history.History(maxlen=10)
+    for entry in HISTORY_TEST_ENTRIES:
+        h.add(entry)
+
+    # 10 items are stored
+    assert len(h) == 10
+    assert h.current() == "19"
+    assert h.top() == "19"
+    assert h.bottom() == "10"
+
+    # going back in time affects only changes current item
+    h.back()
+    assert len(h) == 10
+    assert h.current() == "18"
+    assert h.top() == "19"
+    assert h.bottom() == "10"
+
+    # __iter__ is actually an interator and we can iterate through the list
+    it = iter(h)
+    assert iter(it) == it
+    assert list(it) == HISTORY_TEST_ENTRIES[10:]
+
+    # search allows to go back in time as long as a pattern matches and we don't
+    # go over a step limit
+    assert h.search("45", -9) == "18"
+    assert h.search("1", -5) == "13"
+
+    # fast forward selects the last item
+    h.fast_forward()
+    assert h.current() == "19"
+
+    # back followed by forward is a noop
+    h.back()
+    h.forward()
+    assert h.current() == "19"
+
+    # move can be expressed as multiple calls to back and forward
+    h.move(-3)
+    h.forward()
+    h.forward()
+    h.forward()
+    assert h.current() == "19"
+
+    # back, forward, move play well with boundaries
+    for _ in range(30):
+        h.back()
+
+    for _ in range(30):
+        h.forward()
+
+    for _ in range(30):
+        h.move(-2)
+
+    for _ in range(30):
+        h.move(2)
+    assert h.current() == "19"
+
+    # we can create an history from another history
+    h = history.History(maxlen=10)
+    for entry in HISTORY_TEST_ENTRIES:
+        h.add(entry)
+    # XXX maxlen should not be used to refer to something that isn't a length
+    otherh = history.History(maxlen=h)
+    assert(list(h) == list(otherh))
+
+    # Rebase allow to merge entries with another history
+    otherh = history.History(maxlen=h)
+    for entry in OTHER_TEST_ENTRIES:
+        otherh.add(entry)
+    assert list(otherh)[-3:] == ["42", "43", "44"]
+    h.rebase(otherh)
+    assert h.current() == "44"
+    assert list(h)[-3:] == ['42', '43', '44']
+
+    # modify, modifies the top of the stack
+    h.modify("23")
+    assert h.current() == "23"
+
+
+def testhistoryunique():
+    # Check that unique history refuses to store duplicated entries
+    h = history.History(maxlen=10, unique=True)
+    for entry in HISTORY_TEST_ENTRIES:
+        h.add(entry)
+    assert h.current() == "19"
+    h.add("17")
+    assert list(h).count("17") == 1
+    assert h.current() == "17"
shot of project "lynx", label v2-8-2dev_4' href='/ingrix/lynx-snapshots/commit/src/UCdomap.h?id=6d7ee0488b037f002a9fec0d060cc9842d5f8acd'>6d7ee048 ^
e4409c40 ^
d3f9d547 ^
b6d1143c ^

e4409c40 ^


1d80538b ^

0654c702 ^

1d80538b ^






6d7ee048 ^
e4409c40 ^
e4409c40 ^
1d80538b ^
e4409c40 ^


f7c3c4ca ^






2b52e9e6 ^
f7c3c4ca ^











ab1d1ae5 ^
2b52e9e6 ^








ab1d1ae5 ^

2b52e9e6 ^










ab1d1ae5 ^

2b52e9e6 ^










ab1d1ae5 ^

2b52e9e6 ^










ab1d1ae5 ^

2b52e9e6 ^










ab1d1ae5 ^

2b52e9e6 ^



f7c3c4ca ^


2b52e9e6 ^







ab1d1ae5 ^

2b52e9e6 ^
327b7c16 ^
2b52e9e6 ^








ab1d1ae5 ^

2b52e9e6 ^
f7c3c4ca ^

57bfc74f ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183