-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed history and added tests for it
- Loading branch information
Showing
5 changed files
with
113 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
task :test do | ||
ruby "test/run_all.rb" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
$LOAD_PATH.unshift File.expand_path(File.join("../lib"), File.dirname(__FILE__)) | ||
|
||
require 'riot' | ||
require 'coolline' | ||
|
||
Riot.reporter = Riot::PrettyDotMatrixReporter | ||
|
||
TestDir = File.dirname(__FILE__) | ||
|
||
def path_to(file) | ||
File.join(TestDir, file) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require File.expand_path("helpers.rb", File.dirname(__FILE__)) | ||
|
||
Dir.glob(File.join(File.dirname(__FILE__), "**/*_test.rb")) do |file| | ||
load file | ||
end |