From 42921458ff7eacd1ef614c3e67596c75ccd0a1d4 Mon Sep 17 00:00:00 2001 From: eregon Date: Sun, 27 Jan 2019 13:12:39 +0000 Subject: Update to ruby/spec@e57f49c git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/ruby/core/exception/exception_spec.rb | 16 ++++++++++++++++ spec/ruby/core/proc/shared/to_s.rb | 14 ++++++++++++-- spec/ruby/core/string/chomp_spec.rb | 4 ++++ spec/ruby/core/string/shared/each_line.rb | 13 +++++++++++++ spec/ruby/core/symbol/to_proc_spec.rb | 18 +++++++++--------- 5 files changed, 54 insertions(+), 11 deletions(-) (limited to 'spec/ruby/core') diff --git a/spec/ruby/core/exception/exception_spec.rb b/spec/ruby/core/exception/exception_spec.rb index 750c0ae452..3a01366920 100644 --- a/spec/ruby/core/exception/exception_spec.rb +++ b/spec/ruby/core/exception/exception_spec.rb @@ -66,6 +66,22 @@ describe "Exception#exception" do e2.message.should == "message" end + it "when raised will be rescued as the new exception" do + begin + begin + raised_first = StandardError.new('first') + raise raised_first + rescue => caught_first + raised_second = raised_first.exception('second') + raise raised_second + end + rescue => caught_second + end + + raised_first.should == caught_first + raised_second.should == caught_second + end + class CustomArgumentError < StandardError attr_reader :val def initialize(val) diff --git a/spec/ruby/core/proc/shared/to_s.rb b/spec/ruby/core/proc/shared/to_s.rb index 530eaff3a0..46b21dd083 100644 --- a/spec/ruby/core/proc/shared/to_s.rb +++ b/spec/ruby/core/proc/shared/to_s.rb @@ -32,14 +32,24 @@ describe :proc_to_s, shared: true do describe "for a proc created with UnboundMethod#to_proc" do it "returns a description including '(lambda)' and optionally including file and line number" do def hello; end - method("hello").to_proc.send(@method).should =~ /^#$/ end it "has an ASCII-8BIT encoding" do def hello; end - method("hello").to_proc.send(@method).encoding.should == Encoding::ASCII_8BIT end end + + describe "for a proc created with Symbol#to_proc" do + it "returns a description including '(&:symbol)'" do + proc = :foobar.to_proc + proc.send(@method).should =~ /^#$/ + end + + it "has an ASCII-8BIT encoding" do + proc = :foobar.to_proc + proc.send(@method).encoding.should == Encoding::ASCII_8BIT + end + end end diff --git a/spec/ruby/core/string/chomp_spec.rb b/spec/ruby/core/string/chomp_spec.rb index 6fa8d7c6c5..3c20141ee7 100644 --- a/spec/ruby/core/string/chomp_spec.rb +++ b/spec/ruby/core/string/chomp_spec.rb @@ -158,6 +158,10 @@ describe "String#chomp" do it "does not taint the result when the argument is tainted" do "abc".chomp("abc".taint).tainted?.should be_false end + + it "returns an empty String when the argument equals self" do + "abc".chomp("abc").should == "" + end end end diff --git a/spec/ruby/core/string/shared/each_line.rb b/spec/ruby/core/string/shared/each_line.rb index 19cf5e6d78..066b0c1040 100644 --- a/spec/ruby/core/string/shared/each_line.rb +++ b/spec/ruby/core/string/shared/each_line.rb @@ -27,6 +27,19 @@ describe :string_each_line, shared: true do c.should == ["hello\n", "\n", "\n", "world"] end + it "splits strings containing multibyte characters" do + s = <<~EOS + foo + 🤡🤡🤡🤡🤡🤡🤡 + bar + baz + EOS + + b = [] + s.send(@method) { |part| b << part } + b.should == ["foo\n", "🤡🤡🤡🤡🤡🤡🤡\n", "bar\n", "baz\n"] + end + it "taints substrings that are passed to the block if self is tainted" do "one\ntwo\r\nthree".taint.send(@method) { |s| s.tainted?.should == true } diff --git a/spec/ruby/core/symbol/to_proc_spec.rb b/spec/ruby/core/symbol/to_proc_spec.rb index 8cf00b085f..65f6e27be4 100644 --- a/spec/ruby/core/symbol/to_proc_spec.rb +++ b/spec/ruby/core/symbol/to_proc_spec.rb @@ -12,19 +12,22 @@ describe "Symbol#to_proc" do :to_s.to_proc.call(obj).should == "Received #to_s" end + it "produces a proc with arity -1" do + pr = :to_s.to_proc + pr.arity.should == -1 + end + it "raises an ArgumentError when calling #call on the Proc without receiver" do - lambda { :object_id.to_proc.call }.should raise_error(ArgumentError) + lambda { :object_id.to_proc.call }.should raise_error(ArgumentError, "no receiver given") end it "produces a proc that always returns [[:rest]] for #parameters" do pr = :to_s.to_proc pr.parameters.should == [[:rest]] end -end -describe "Symbol#to_proc" do - before :all do - @klass = Class.new do + it "passes along the block passed to Proc#call" do + klass = Class.new do def m yield end @@ -33,9 +36,6 @@ describe "Symbol#to_proc" do :m.to_proc.call(self) { :value } end end - end - - it "passes along the block passed to Proc#call" do - @klass.new.to_proc.should == :value + klass.new.to_proc.should == :value end end -- cgit v1.2.3