mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@e57f49c
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a53ee2136f
commit
42921458ff
11 changed files with 127 additions and 15 deletions
|
@ -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)
|
||||
|
|
|
@ -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 =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:22)? \(lambda\)>$/
|
||||
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 =~ /^#<Proc:0x\h+\(&:foobar\)>$/
|
||||
end
|
||||
|
||||
it "has an ASCII-8BIT encoding" do
|
||||
proc = :foobar.to_proc
|
||||
proc.send(@method).encoding.should == Encoding::ASCII_8BIT
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 }
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -38,14 +38,14 @@ describe "The alias keyword" do
|
|||
@obj.a.should == 5
|
||||
end
|
||||
|
||||
it "works with a doubule quoted symbol on the left-hand side" do
|
||||
it "works with a double quoted symbol on the left-hand side" do
|
||||
@meta.class_eval do
|
||||
alias :"a" value
|
||||
end
|
||||
@obj.a.should == 5
|
||||
end
|
||||
|
||||
it "works with an interoplated symbol on the left-hand side" do
|
||||
it "works with an interpolated symbol on the left-hand side" do
|
||||
@meta.class_eval do
|
||||
alias :"#{'a'}" value
|
||||
end
|
||||
|
@ -66,14 +66,14 @@ describe "The alias keyword" do
|
|||
@obj.a.should == 5
|
||||
end
|
||||
|
||||
it "works with a doubule quoted symbol on the right-hand side" do
|
||||
it "works with a double quoted symbol on the right-hand side" do
|
||||
@meta.class_eval do
|
||||
alias a :"value"
|
||||
end
|
||||
@obj.a.should == 5
|
||||
end
|
||||
|
||||
it "works with an interoplated symbol on the right-hand side" do
|
||||
it "works with an interpolated symbol on the right-hand side" do
|
||||
@meta.class_eval do
|
||||
alias a :"#{'value'}"
|
||||
end
|
||||
|
|
|
@ -183,3 +183,27 @@ describe "StringIO#initialize when passed no arguments" do
|
|||
@io.string.should == ""
|
||||
end
|
||||
end
|
||||
|
||||
describe "StringIO#initialize sets the encoding to" do
|
||||
before :each do
|
||||
@external = Encoding.default_external
|
||||
Encoding.default_external = Encoding::ISO_8859_2
|
||||
end
|
||||
|
||||
after :each do
|
||||
Encoding.default_external = @external
|
||||
end
|
||||
|
||||
it "Encoding.default_external when passed no arguments" do
|
||||
io = StringIO.new
|
||||
io.external_encoding.should == Encoding::ISO_8859_2
|
||||
io.string.encoding.should == Encoding::ISO_8859_2
|
||||
end
|
||||
|
||||
it "the same as the encoding of the String when passed a String" do
|
||||
s = ''.force_encoding(Encoding::EUC_JP)
|
||||
io = StringIO.new(s)
|
||||
io.external_encoding.should == Encoding::EUC_JP
|
||||
io.string.encoding.should == Encoding::EUC_JP
|
||||
end
|
||||
end
|
||||
|
|
|
@ -97,6 +97,16 @@ describe "CApiBignumSpecs" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "RBIGNUM_SIGN" do
|
||||
it "returns 1 for a positive Bignum" do
|
||||
@s.RBIGNUM_SIGN(bignum_value(1)).should == 1
|
||||
end
|
||||
|
||||
it "returns 0 for a negative Bignum" do
|
||||
@s.RBIGNUM_SIGN(-bignum_value(1)).should == 0
|
||||
end
|
||||
end
|
||||
|
||||
describe "rb_big_cmp" do
|
||||
it "compares a Bignum with a Bignum" do
|
||||
@s.rb_big_cmp(bignum_value, bignum_value(1)).should == -1
|
||||
|
|
|
@ -31,6 +31,10 @@ static VALUE bignum_spec_rb_big2ulong(VALUE self, VALUE num) {
|
|||
return ULONG2NUM(rb_big2ulong(num));
|
||||
}
|
||||
|
||||
static VALUE bignum_spec_RBIGNUM_SIGN(VALUE self, VALUE val) {
|
||||
return INT2FIX(RBIGNUM_SIGN(val));
|
||||
}
|
||||
|
||||
static VALUE bignum_spec_rb_big_cmp(VALUE self, VALUE x, VALUE y) {
|
||||
return rb_big_cmp(x, y);
|
||||
}
|
||||
|
@ -90,6 +94,7 @@ void Init_bignum_spec(void) {
|
|||
rb_define_method(cls, "rb_big2long", bignum_spec_rb_big2long, 1);
|
||||
rb_define_method(cls, "rb_big2str", bignum_spec_rb_big2str, 2);
|
||||
rb_define_method(cls, "rb_big2ulong", bignum_spec_rb_big2ulong, 1);
|
||||
rb_define_method(cls, "RBIGNUM_SIGN", bignum_spec_RBIGNUM_SIGN, 1);
|
||||
rb_define_method(cls, "rb_big_cmp", bignum_spec_rb_big_cmp, 2);
|
||||
rb_define_method(cls, "rb_big_pack", bignum_spec_rb_big_pack, 1);
|
||||
rb_define_method(cls, "rb_big_pack_array", bignum_spec_rb_big_pack_array, 2);
|
||||
|
|
|
@ -26,6 +26,9 @@ VALUE kernel_spec_rb_block_proc(VALUE self) {
|
|||
return rb_block_proc();
|
||||
}
|
||||
|
||||
VALUE kernel_spec_rb_block_lambda(VALUE self) {
|
||||
return rb_block_lambda();
|
||||
}
|
||||
|
||||
VALUE block_call_inject(VALUE yield_value, VALUE data2) {
|
||||
/* yield_value yields the first block argument */
|
||||
|
@ -286,6 +289,7 @@ void Init_kernel_spec(void) {
|
|||
rb_define_method(cls, "rb_block_call_multi_arg", kernel_spec_rb_block_call_multi_arg, 1);
|
||||
rb_define_method(cls, "rb_block_call_no_func", kernel_spec_rb_block_call_no_func, 1);
|
||||
rb_define_method(cls, "rb_block_proc", kernel_spec_rb_block_proc, 0);
|
||||
rb_define_method(cls, "rb_block_lambda", kernel_spec_rb_block_lambda, 0);
|
||||
rb_define_method(cls, "rb_frame_this_func_test", kernel_spec_rb_frame_this_func, 0);
|
||||
rb_define_method(cls, "rb_frame_this_func_test_again", kernel_spec_rb_frame_this_func, 0);
|
||||
rb_define_method(cls, "rb_ensure", kernel_spec_rb_ensure, 4);
|
||||
|
|
|
@ -440,6 +440,32 @@ describe "C-API Kernel function" do
|
|||
proc = @s.rb_block_proc() { 1+1 }
|
||||
proc.should be_kind_of(Proc)
|
||||
proc.call.should == 2
|
||||
proc.lambda?.should == false
|
||||
end
|
||||
|
||||
it "passes through an existing lambda and does not convert to a proc" do
|
||||
b = -> { 1+1 }
|
||||
proc = @s.rb_block_proc(&b)
|
||||
proc.should equal(b)
|
||||
proc.call.should == 2
|
||||
proc.lambda?.should == true
|
||||
end
|
||||
end
|
||||
|
||||
describe "rb_block_lambda" do
|
||||
it "converts the implicit block into a Proc but does not convert it to a lambda" do
|
||||
proc = @s.rb_block_proc { 1+1 }
|
||||
proc.should be_kind_of(Proc)
|
||||
proc.call.should == 2
|
||||
proc.lambda?.should == false
|
||||
end
|
||||
|
||||
it "passes through an existing Proc and does not convert to a lambda" do
|
||||
b = proc { 1+1 }
|
||||
proc = @s.rb_block_proc(&b)
|
||||
proc.should equal(b)
|
||||
proc.call.should == 2
|
||||
proc.lambda?.should == false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue