aboutsummaryrefslogtreecommitdiffstats
path: root/spec/rubyspec/library/readline/history
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubyspec/library/readline/history')
-rw-r--r--spec/rubyspec/library/readline/history/append_spec.rb28
-rw-r--r--spec/rubyspec/library/readline/history/delete_at_spec.rb45
-rw-r--r--spec/rubyspec/library/readline/history/each_spec.rb29
-rw-r--r--spec/rubyspec/library/readline/history/element_reference_spec.rb40
-rw-r--r--spec/rubyspec/library/readline/history/element_set_spec.rb35
-rw-r--r--spec/rubyspec/library/readline/history/empty_spec.rb13
-rw-r--r--spec/rubyspec/library/readline/history/history_spec.rb9
-rw-r--r--spec/rubyspec/library/readline/history/length_spec.rb9
-rw-r--r--spec/rubyspec/library/readline/history/pop_spec.rb30
-rw-r--r--spec/rubyspec/library/readline/history/push_spec.rb26
-rw-r--r--spec/rubyspec/library/readline/history/shared/size.rb14
-rw-r--r--spec/rubyspec/library/readline/history/shift_spec.rb30
-rw-r--r--spec/rubyspec/library/readline/history/size_spec.rb9
-rw-r--r--spec/rubyspec/library/readline/history/to_s_spec.rb9
14 files changed, 326 insertions, 0 deletions
diff --git a/spec/rubyspec/library/readline/history/append_spec.rb b/spec/rubyspec/library/readline/history/append_spec.rb
new file mode 100644
index 0000000000..3ea0bbf57f
--- /dev/null
+++ b/spec/rubyspec/library/readline/history/append_spec.rb
@@ -0,0 +1,28 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+with_feature :readline do
+ describe "Readline::HISTORY.<<" do
+ it "appends the given Object to the history" do
+ Readline::HISTORY << "1"
+ Readline::HISTORY.size.should == 1
+
+ Readline::HISTORY << "2"
+ Readline::HISTORY.size.should == 2
+
+ Readline::HISTORY.pop.should == "2"
+ Readline::HISTORY.pop.should == "1"
+ end
+
+ it "tries to convert the passed Object to a String using #to_str" do
+ obj = mock("Converted to String")
+ obj.should_receive(:to_str).and_return("converted")
+
+ Readline::HISTORY << obj
+ Readline::HISTORY.pop.should == "converted"
+ end
+
+ it "raises a TypeError when the passed Object can't be converted to a String" do
+ lambda { Readline::HISTORY << mock("Object") }.should raise_error(TypeError)
+ end
+ end
+end
diff --git a/spec/rubyspec/library/readline/history/delete_at_spec.rb b/spec/rubyspec/library/readline/history/delete_at_spec.rb
new file mode 100644
index 0000000000..38f180ca08
--- /dev/null
+++ b/spec/rubyspec/library/readline/history/delete_at_spec.rb
@@ -0,0 +1,45 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+with_feature :readline do
+ describe "Readline::HISTORY.delete_at" do
+ it "deletes and returns the history entry at the specified index" do
+ Readline::HISTORY.push("1", "2", "3")
+
+ Readline::HISTORY.delete_at(1).should == "2"
+ Readline::HISTORY.size.should == 2
+
+ Readline::HISTORY.delete_at(1).should == "3"
+ Readline::HISTORY.size.should == 1
+
+ Readline::HISTORY.delete_at(0).should == "1"
+ Readline::HISTORY.size.should == 0
+
+
+ Readline::HISTORY.push("1", "2", "3", "4")
+
+ Readline::HISTORY.delete_at(-2).should == "3"
+ Readline::HISTORY.size.should == 3
+
+ Readline::HISTORY.delete_at(-2).should == "2"
+ Readline::HISTORY.size.should == 2
+
+ Readline::HISTORY.delete_at(0).should == "1"
+ Readline::HISTORY.size.should == 1
+
+ Readline::HISTORY.delete_at(0).should == "4"
+ Readline::HISTORY.size.should == 0
+ end
+
+ it "raises an IndexError when the given index is greater than the history size" do
+ lambda { Readline::HISTORY.delete_at(10) }.should raise_error(IndexError)
+ lambda { Readline::HISTORY.delete_at(-10) }.should raise_error(IndexError)
+ end
+
+ it "taints the returned strings" do
+ Readline::HISTORY.push("1", "2", "3")
+ Readline::HISTORY.delete_at(0).tainted?.should be_true
+ Readline::HISTORY.delete_at(0).tainted?.should be_true
+ Readline::HISTORY.delete_at(0).tainted?.should be_true
+ end
+ end
+end
diff --git a/spec/rubyspec/library/readline/history/each_spec.rb b/spec/rubyspec/library/readline/history/each_spec.rb
new file mode 100644
index 0000000000..5057e04970
--- /dev/null
+++ b/spec/rubyspec/library/readline/history/each_spec.rb
@@ -0,0 +1,29 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+with_feature :readline do
+ describe "Readline::HISTORY.each" do
+ before :each do
+ Readline::HISTORY.push("1", "2", "3")
+ end
+
+ after :each do
+ Readline::HISTORY.pop
+ Readline::HISTORY.pop
+ Readline::HISTORY.pop
+ end
+
+ it "yields each item in the history" do
+ result = []
+ Readline::HISTORY.each do |x|
+ result << x
+ end
+ result.should == ["1", "2", "3"]
+ end
+
+ it "yields tainted Objects" do
+ Readline::HISTORY.each do |x|
+ x.tainted?.should be_true
+ end
+ end
+ end
+end
diff --git a/spec/rubyspec/library/readline/history/element_reference_spec.rb b/spec/rubyspec/library/readline/history/element_reference_spec.rb
new file mode 100644
index 0000000000..c656179ddd
--- /dev/null
+++ b/spec/rubyspec/library/readline/history/element_reference_spec.rb
@@ -0,0 +1,40 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+with_feature :readline do
+ describe "Readline::HISTORY.[]" do
+ before :each do
+ Readline::HISTORY.push("1", "2", "3")
+ end
+
+ after :each do
+ Readline::HISTORY.pop
+ Readline::HISTORY.pop
+ Readline::HISTORY.pop
+ end
+
+ it "returns tainted objects" do
+ Readline::HISTORY[0].tainted?.should be_true
+ Readline::HISTORY[1].tainted?.should be_true
+ end
+
+ it "returns the history item at the passed index" do
+ Readline::HISTORY[0].should == "1"
+ Readline::HISTORY[1].should == "2"
+ Readline::HISTORY[2].should == "3"
+
+ Readline::HISTORY[-1].should == "3"
+ Readline::HISTORY[-2].should == "2"
+ Readline::HISTORY[-3].should == "1"
+ end
+
+ it "raises an IndexError when there is no item at the passed index" do
+ lambda { Readline::HISTORY[-10] }.should raise_error(IndexError)
+ lambda { Readline::HISTORY[-9] }.should raise_error(IndexError)
+ lambda { Readline::HISTORY[-8] }.should raise_error(IndexError)
+
+ lambda { Readline::HISTORY[8] }.should raise_error(IndexError)
+ lambda { Readline::HISTORY[9] }.should raise_error(IndexError)
+ lambda { Readline::HISTORY[10] }.should raise_error(IndexError)
+ end
+ end
+end
diff --git a/spec/rubyspec/library/readline/history/element_set_spec.rb b/spec/rubyspec/library/readline/history/element_set_spec.rb
new file mode 100644
index 0000000000..8d6fe196ef
--- /dev/null
+++ b/spec/rubyspec/library/readline/history/element_set_spec.rb
@@ -0,0 +1,35 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+with_feature :readline do
+ describe "Readline::HISTORY.[]=" do
+ before :each do
+ Readline::HISTORY.push("1", "2", "3")
+ end
+
+ after :each do
+ Readline::HISTORY.pop
+ Readline::HISTORY.pop
+ Readline::HISTORY.pop
+ end
+
+ it "returns the new value for the passed index" do
+ (Readline::HISTORY[1] = "second test").should == "second test"
+ end
+
+ it "raises an IndexError when there is no item at the passed positive index" do
+ lambda { Readline::HISTORY[10] = "test" }.should raise_error(IndexError)
+ end
+
+ it "sets the item at the given index" do
+ Readline::HISTORY[0] = "test"
+ Readline::HISTORY[0].should == "test"
+
+ Readline::HISTORY[1] = "second test"
+ Readline::HISTORY[1].should == "second test"
+ end
+
+ it "raises an IndexError when there is no item at the passed negative index" do
+ lambda { Readline::HISTORY[10] = "test" }.should raise_error(IndexError)
+ end
+ end
+end
diff --git a/spec/rubyspec/library/readline/history/empty_spec.rb b/spec/rubyspec/library/readline/history/empty_spec.rb
new file mode 100644
index 0000000000..92a4fcd063
--- /dev/null
+++ b/spec/rubyspec/library/readline/history/empty_spec.rb
@@ -0,0 +1,13 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+with_feature :readline do
+ describe "Readline::HISTORY.empty?" do
+ it "returns true when the history is empty" do
+ Readline::HISTORY.should be_empty
+ Readline::HISTORY.push("test")
+ Readline::HISTORY.should_not be_empty
+ Readline::HISTORY.pop
+ Readline::HISTORY.should be_empty
+ end
+ end
+end
diff --git a/spec/rubyspec/library/readline/history/history_spec.rb b/spec/rubyspec/library/readline/history/history_spec.rb
new file mode 100644
index 0000000000..dfa6544036
--- /dev/null
+++ b/spec/rubyspec/library/readline/history/history_spec.rb
@@ -0,0 +1,9 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+with_feature :readline do
+ describe "Readline::HISTORY" do
+ it "is extended with the Enumerable module" do
+ Readline::HISTORY.should be_kind_of(Enumerable)
+ end
+ end
+end
diff --git a/spec/rubyspec/library/readline/history/length_spec.rb b/spec/rubyspec/library/readline/history/length_spec.rb
new file mode 100644
index 0000000000..6700d4f234
--- /dev/null
+++ b/spec/rubyspec/library/readline/history/length_spec.rb
@@ -0,0 +1,9 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+with_feature :readline do
+ require File.expand_path('../shared/size', __FILE__)
+
+ describe "Readline::HISTORY.length" do
+ it_behaves_like :readline_history_size, :length
+ end
+end
diff --git a/spec/rubyspec/library/readline/history/pop_spec.rb b/spec/rubyspec/library/readline/history/pop_spec.rb
new file mode 100644
index 0000000000..34562dff3b
--- /dev/null
+++ b/spec/rubyspec/library/readline/history/pop_spec.rb
@@ -0,0 +1,30 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+with_feature :readline do
+ describe "Readline::HISTORY.pop" do
+ it "returns nil when the history is empty" do
+ Readline::HISTORY.pop.should be_nil
+ end
+
+ it "returns and removes the last item from the history" do
+ Readline::HISTORY.push("1", "2", "3")
+ Readline::HISTORY.size.should == 3
+
+ Readline::HISTORY.pop.should == "3"
+ Readline::HISTORY.size.should == 2
+
+ Readline::HISTORY.pop.should == "2"
+ Readline::HISTORY.size.should == 1
+
+ Readline::HISTORY.pop.should == "1"
+ Readline::HISTORY.size.should == 0
+ end
+
+ it "taints the returned strings" do
+ Readline::HISTORY.push("1", "2", "3")
+ Readline::HISTORY.pop.tainted?.should be_true
+ Readline::HISTORY.pop.tainted?.should be_true
+ Readline::HISTORY.pop.tainted?.should be_true
+ end
+ end
+end
diff --git a/spec/rubyspec/library/readline/history/push_spec.rb b/spec/rubyspec/library/readline/history/push_spec.rb
new file mode 100644
index 0000000000..b59b17ed03
--- /dev/null
+++ b/spec/rubyspec/library/readline/history/push_spec.rb
@@ -0,0 +1,26 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+with_feature :readline do
+ describe "Readline::HISTORY.push" do
+ it "pushes all passed Objects into the history" do
+ Readline::HISTORY.push("1", "2", "3")
+ Readline::HISTORY.size.should == 3
+
+ Readline::HISTORY.pop.should == "3"
+ Readline::HISTORY.pop.should == "2"
+ Readline::HISTORY.pop.should == "1"
+ end
+
+ it "tries to convert the passed Object to a String using #to_str" do
+ obj = mock("Converted to String")
+ obj.should_receive(:to_str).and_return("converted")
+
+ Readline::HISTORY.push(obj)
+ Readline::HISTORY.pop.should == "converted"
+ end
+
+ it "raises a TypeError when the passed Object can't be converted to a String" do
+ lambda { Readline::HISTORY.push(mock("Object")) }.should raise_error(TypeError)
+ end
+ end
+end
diff --git a/spec/rubyspec/library/readline/history/shared/size.rb b/spec/rubyspec/library/readline/history/shared/size.rb
new file mode 100644
index 0000000000..1d6df86f78
--- /dev/null
+++ b/spec/rubyspec/library/readline/history/shared/size.rb
@@ -0,0 +1,14 @@
+describe :readline_history_size, shared: true do
+ it "returns the size of the history" do
+ Readline::HISTORY.send(@method).should == 0
+ Readline::HISTORY.push("1", "2", "")
+ Readline::HISTORY.send(@method).should == 3
+
+ Readline::HISTORY.pop
+ Readline::HISTORY.send(@method).should == 2
+
+ Readline::HISTORY.pop
+ Readline::HISTORY.pop
+ Readline::HISTORY.send(@method).should == 0
+ end
+end
diff --git a/spec/rubyspec/library/readline/history/shift_spec.rb b/spec/rubyspec/library/readline/history/shift_spec.rb
new file mode 100644
index 0000000000..3d4782998d
--- /dev/null
+++ b/spec/rubyspec/library/readline/history/shift_spec.rb
@@ -0,0 +1,30 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+with_feature :readline do
+ describe "Readline::HISTORY.shift" do
+ it "returns nil when the history is empty" do
+ Readline::HISTORY.shift.should be_nil
+ end
+
+ it "returns and removes the first item from the history" do
+ Readline::HISTORY.push("1", "2", "3")
+ Readline::HISTORY.size.should == 3
+
+ Readline::HISTORY.shift.should == "1"
+ Readline::HISTORY.size.should == 2
+
+ Readline::HISTORY.shift.should == "2"
+ Readline::HISTORY.size.should == 1
+
+ Readline::HISTORY.shift.should == "3"
+ Readline::HISTORY.size.should == 0
+ end
+
+ it "taints the returned strings" do
+ Readline::HISTORY.push("1", "2", "3")
+ Readline::HISTORY.shift.tainted?.should be_true
+ Readline::HISTORY.shift.tainted?.should be_true
+ Readline::HISTORY.shift.tainted?.should be_true
+ end
+ end
+end
diff --git a/spec/rubyspec/library/readline/history/size_spec.rb b/spec/rubyspec/library/readline/history/size_spec.rb
new file mode 100644
index 0000000000..815c68de27
--- /dev/null
+++ b/spec/rubyspec/library/readline/history/size_spec.rb
@@ -0,0 +1,9 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+with_feature :readline do
+ require File.expand_path('../shared/size', __FILE__)
+
+ describe "Readline::HISTORY.size" do
+ it_behaves_like :readline_history_size, :size
+ end
+end
diff --git a/spec/rubyspec/library/readline/history/to_s_spec.rb b/spec/rubyspec/library/readline/history/to_s_spec.rb
new file mode 100644
index 0000000000..30ba5a1249
--- /dev/null
+++ b/spec/rubyspec/library/readline/history/to_s_spec.rb
@@ -0,0 +1,9 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+with_feature :readline do
+ describe "Readline::HISTORY.to_s" do
+ it "returns 'HISTORY'" do
+ Readline::HISTORY.to_s.should == "HISTORY"
+ end
+ end
+end