-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathhistory_test.rb
85 lines (65 loc) · 1.62 KB
/
history_test.rb
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
require File.expand_path("helpers.rb", File.dirname(__FILE__))
context "a newly created history" do
setup do
Coolline::History.new(path_to("history"), 10)
end
asserts(:size).equals 0
asserts(:max_size).equals 10
context "after inserting a new-line" do
hookup do
topic << "1"
end
asserts(:size).equals 1
asserts(:max_size).equals 10
asserts(:[], 0).equals "1"
context "and many others" do
hookup do
2.upto(11) { |n| topic << n.to_s }
end
asserts(:size).equals 10
asserts(:max_size).equals 10
2.upto(11) do |n|
asserts(:[], n - 2).equals n.to_s
end
end
end
teardown do
File.delete path_to("history")
end
end
context "an history from an existing file" do
setup do
open(path_to("history"), 'w') do |io|
io.puts((1..13).to_a)
end
Coolline::History.new(path_to("history"), 15)
end
asserts(:size).equals 13
asserts(:max_size).equals 15
1.upto(13) do |n|
asserts(:[], n - 1).equals n.to_s
end
asserts("search for 3") { topic.search(/3/).to_a }.equals [["13",12], ["3",2]]
asserts("search for 3 before last line") {
topic.search(/3/, -2).to_a
}.equals [["3",2]]
teardown do
File.delete path_to("history")
end
end
context "an history from a huge existing file" do
setup do
open(path_to("history"), 'w') do |io|
io.puts((1..20).to_a)
end
Coolline::History.new(path_to("history"), 15)
end
asserts(:size).equals 15
asserts(:max_size).equals 15
6.upto(20) do |n|
asserts(:[], n - 6).equals n.to_s
end
teardown do
File.delete path_to("history")
end
end