diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-07 12:04:49 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-07 12:04:49 +0000 |
commit | 95e8c48dd3348503a8c7db5d0498894a1b676395 (patch) | |
tree | 9eef7f720314ebaff56845a74e203770e62284e4 /spec/rubyspec/library/readline | |
parent | ed7d803500de38186c74bce94d233e85ef51e503 (diff) |
Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers.
* .gitignore: track changes under spec.
* spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec.
These files can therefore be updated like any other file in MRI.
Instructions are provided in spec/README.
[Feature #13156] [ruby-core:79246]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/rubyspec/library/readline')
27 files changed, 550 insertions, 0 deletions
diff --git a/spec/rubyspec/library/readline/basic_quote_characters_spec.rb b/spec/rubyspec/library/readline/basic_quote_characters_spec.rb new file mode 100644 index 0000000000..7d25df2047 --- /dev/null +++ b/spec/rubyspec/library/readline/basic_quote_characters_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path('../spec_helper', __FILE__) + +platform_is_not :darwin do + with_feature :readline do + describe "Readline.basic_quote_characters" do + it "returns not nil" do + Readline.basic_quote_characters.should_not be_nil + end + end + + describe "Readline.basic_quote_characters=" do + it "returns the passed string" do + Readline.basic_quote_characters = "test" + Readline.basic_quote_characters.should == "test" + end + end + end +end diff --git a/spec/rubyspec/library/readline/basic_word_break_characters_spec.rb b/spec/rubyspec/library/readline/basic_word_break_characters_spec.rb new file mode 100644 index 0000000000..c2ec6cede7 --- /dev/null +++ b/spec/rubyspec/library/readline/basic_word_break_characters_spec.rb @@ -0,0 +1,16 @@ +require File.expand_path('../spec_helper', __FILE__) + +with_feature :readline do + describe "Readline.basic_word_break_characters" do + it "returns not nil" do + Readline.basic_word_break_characters.should_not be_nil + end + end + + describe "Readline.basic_word_break_characters=" do + it "returns the passed string" do + Readline.basic_word_break_characters = "test" + Readline.basic_word_break_characters.should == "test" + end + end +end diff --git a/spec/rubyspec/library/readline/completer_quote_characters_spec.rb b/spec/rubyspec/library/readline/completer_quote_characters_spec.rb new file mode 100644 index 0000000000..a836a0591e --- /dev/null +++ b/spec/rubyspec/library/readline/completer_quote_characters_spec.rb @@ -0,0 +1,16 @@ +require File.expand_path('../spec_helper', __FILE__) + +with_feature :readline do + describe "Readline.completer_quote_characters" do + it "returns nil" do + Readline.completer_quote_characters.should be_nil + end + end + + describe "Readline.completer_quote_characters=" do + it "returns the passed string" do + Readline.completer_quote_characters = "test" + Readline.completer_quote_characters.should == "test" + end + end +end diff --git a/spec/rubyspec/library/readline/completer_word_break_characters_spec.rb b/spec/rubyspec/library/readline/completer_word_break_characters_spec.rb new file mode 100644 index 0000000000..2e0cc277a6 --- /dev/null +++ b/spec/rubyspec/library/readline/completer_word_break_characters_spec.rb @@ -0,0 +1,16 @@ +require File.expand_path('../spec_helper', __FILE__) + +with_feature :readline do + describe "Readline.completer_word_break_characters" do + it "returns nil" do + Readline.completer_word_break_characters.should be_nil + end + end + + describe "Readline.completer_word_break_characters=" do + it "returns the passed string" do + Readline.completer_word_break_characters = "test" + Readline.completer_word_break_characters.should == "test" + end + end +end diff --git a/spec/rubyspec/library/readline/completion_append_character_spec.rb b/spec/rubyspec/library/readline/completion_append_character_spec.rb new file mode 100644 index 0000000000..ee41abea05 --- /dev/null +++ b/spec/rubyspec/library/readline/completion_append_character_spec.rb @@ -0,0 +1,16 @@ +require File.expand_path('../spec_helper', __FILE__) + +with_feature :readline do + describe "Readline.completion_append_character" do + it "returns not nil" do + Readline.completion_append_character.should_not be_nil + end + end + + describe "Readline.completion_append_character=" do + it "returns the first character of the passed string" do + Readline.completion_append_character = "test" + Readline.completion_append_character.should == "t" + end + end +end diff --git a/spec/rubyspec/library/readline/completion_case_fold_spec.rb b/spec/rubyspec/library/readline/completion_case_fold_spec.rb new file mode 100644 index 0000000000..604460869e --- /dev/null +++ b/spec/rubyspec/library/readline/completion_case_fold_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path('../spec_helper', __FILE__) + +with_feature :readline do + describe "Readline.completion_case_fold" do + it "returns nil" do + Readline.completion_case_fold.should be_nil + end + end + + describe "Readline.completion_case_fold=" do + it "returns the passed boolean" do + Readline.completion_case_fold = true + Readline.completion_case_fold.should == true + Readline.completion_case_fold = false + Readline.completion_case_fold.should == false + end + end +end diff --git a/spec/rubyspec/library/readline/completion_proc_spec.rb b/spec/rubyspec/library/readline/completion_proc_spec.rb new file mode 100644 index 0000000000..e525fbd191 --- /dev/null +++ b/spec/rubyspec/library/readline/completion_proc_spec.rb @@ -0,0 +1,22 @@ +require File.expand_path('../spec_helper', __FILE__) + +with_feature :readline do + describe "Readline.completion_proc" do + it "returns nil" do + Readline.completion_proc.should be_nil + end + end + + describe "Readline.completion_proc=" do + it "returns the passed Proc" do + proc = Proc.new do |e| + end + Readline.completion_proc = proc + Readline.completion_proc.should == proc + end + + it "returns an ArgumentError if not given an Proc or #call" do + lambda { Readline.completion_proc = "test" }.should raise_error(ArgumentError) + end + end +end diff --git a/spec/rubyspec/library/readline/constants_spec.rb b/spec/rubyspec/library/readline/constants_spec.rb new file mode 100644 index 0000000000..226a3509b9 --- /dev/null +++ b/spec/rubyspec/library/readline/constants_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path('../spec_helper', __FILE__) + +with_feature :readline do + # Note: additional specs for HISTORY are in 'history' subdir. + describe "Readline::HISTORY" do + it "is defined" do + Readline.const_defined?(:HISTORY).should == true + end + end + + describe "Readline::VERSION" do + it "is defined and is a non-empty String" do + Readline.const_defined?(:VERSION).should == true + Readline::VERSION.should be_kind_of(String) + Readline::VERSION.should_not be_empty + end + end +end diff --git a/spec/rubyspec/library/readline/emacs_editing_mode_spec.rb b/spec/rubyspec/library/readline/emacs_editing_mode_spec.rb new file mode 100644 index 0000000000..6c2e84b08f --- /dev/null +++ b/spec/rubyspec/library/readline/emacs_editing_mode_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path('../spec_helper', __FILE__) + +platform_is_not :darwin do + with_feature :readline do + describe "Readline.emacs_editing_mode" do + it "returns nil" do + Readline.emacs_editing_mode.should be_nil + end + end + end +end diff --git a/spec/rubyspec/library/readline/filename_quote_characters_spec.rb b/spec/rubyspec/library/readline/filename_quote_characters_spec.rb new file mode 100644 index 0000000000..abee5e9700 --- /dev/null +++ b/spec/rubyspec/library/readline/filename_quote_characters_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path('../spec_helper', __FILE__) + +platform_is_not :darwin do + with_feature :readline do + describe "Readline.filename_quote_characters" do + it "returns nil" do + Readline.filename_quote_characters.should be_nil + end + end + + describe "Readline.filename_quote_characters=" do + it "returns the passed string" do + Readline.filename_quote_characters = "test" + Readline.filename_quote_characters.should == "test" + end + end + end +end 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 diff --git a/spec/rubyspec/library/readline/readline_spec.rb b/spec/rubyspec/library/readline/readline_spec.rb new file mode 100644 index 0000000000..599f84dffd --- /dev/null +++ b/spec/rubyspec/library/readline/readline_spec.rb @@ -0,0 +1,31 @@ +require File.expand_path('../spec_helper', __FILE__) + +with_feature :readline do + describe "Readline.readline" do + before :each do + @file = tmp('readline') + @out = tmp('out.txt') + touch(@file) { |f| + f.puts "test" + } + @options = { options: "-rreadline", args: [@out, "< #{@file}"] } + end + + after :each do + rm_r @file, @out + end + + # Somehow those specs block on Windows + platform_is_not :windows do + it "returns the input string" do + ruby_exe('File.write ARGV[0], Readline.readline', @options) + File.read(@out).should == "test" + end + + it "taints the returned strings" do + ruby_exe('File.write ARGV[0], Readline.readline.tainted?', @options) + File.read(@out).should == "true" + end + end + end +end diff --git a/spec/rubyspec/library/readline/spec_helper.rb b/spec/rubyspec/library/readline/spec_helper.rb new file mode 100644 index 0000000000..b5ac16d22a --- /dev/null +++ b/spec/rubyspec/library/readline/spec_helper.rb @@ -0,0 +1,13 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +unless MSpec.retrieve(:features).key?(:readline) + begin + require 'readline' + rescue LoadError + else + # rb-readline behaves quite differently + if $".grep(/\brbreadline\.rb$/).empty? + MSpec.enable_feature :readline + end + end +end diff --git a/spec/rubyspec/library/readline/vi_editing_mode_spec.rb b/spec/rubyspec/library/readline/vi_editing_mode_spec.rb new file mode 100644 index 0000000000..db6d4387f8 --- /dev/null +++ b/spec/rubyspec/library/readline/vi_editing_mode_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path('../spec_helper', __FILE__) + +platform_is_not :darwin do + with_feature :readline do + describe "Readline.vi_editing_mode" do + it "returns nil" do + Readline.vi_editing_mode.should be_nil + end + end + end +end |