зеркало из https://github.com/github/ruby.git
Update to ruby/spec@9e278f5
This commit is contained in:
Родитель
e20f1e443f
Коммит
dc54574ade
|
@ -14,6 +14,10 @@ describe "Encoding::Converter#primitive_convert" do
|
|||
-> { @ec.primitive_convert("","") }.should_not raise_error
|
||||
end
|
||||
|
||||
it "raises FrozenError when the destination buffer is a frozen String" do
|
||||
-> { @ec.primitive_convert("", "".freeze) }.should raise_error(FrozenError)
|
||||
end
|
||||
|
||||
it "accepts nil for the destination byte offset" do
|
||||
-> { @ec.primitive_convert("","", nil) }.should_not raise_error
|
||||
end
|
||||
|
|
|
@ -26,13 +26,11 @@ describe "SystemCallError.===" do
|
|||
end
|
||||
|
||||
it "returns true if receiver is generic and arg is kind of SystemCallError" do
|
||||
unknown_error_number = Errno.constants.size
|
||||
e = SystemCallError.new('foo', @example_errno)
|
||||
SystemCallError.===(e).should == true
|
||||
end
|
||||
|
||||
it "returns false if receiver is generic and arg is not kind of SystemCallError" do
|
||||
unknown_error_number = Errno.constants.size
|
||||
e = Object.new
|
||||
SystemCallError.===(e).should == false
|
||||
end
|
||||
|
|
|
@ -105,7 +105,7 @@ describe "Module#const_get" do
|
|||
-> { ConstantSpecs.const_get("CS_CONST1", false) }.should raise_error(NameError)
|
||||
end
|
||||
|
||||
it "returns a constant whose module is defined the the toplevel" do
|
||||
it "returns a constant whose module is defined the toplevel" do
|
||||
ConstantSpecs.const_get("ConstantSpecsTwo::Foo").should == :cs_two_foo
|
||||
ConstantSpecsThree.const_get("ConstantSpecsTwo::Foo").should == :cs_three_foo
|
||||
end
|
||||
|
|
|
@ -133,6 +133,17 @@ describe "Module#define_method when name is not a special private name" do
|
|||
klass.should have_public_instance_method(:baz)
|
||||
end
|
||||
end
|
||||
|
||||
it "sets the method owner for a dynamically added method with a different original owner" do
|
||||
mixin_module = Module.new do
|
||||
def bar; end
|
||||
end
|
||||
|
||||
foo = Object.new
|
||||
foo.singleton_class.define_method(:bar, mixin_module.instance_method(:bar))
|
||||
|
||||
foo.method(:bar).owner.should == foo.singleton_class
|
||||
end
|
||||
end
|
||||
|
||||
describe "passed a block" do
|
||||
|
|
|
@ -155,15 +155,62 @@ describe "Module#module_function with specific method names" do
|
|||
|
||||
m.foo.should == ["m", "super_m"]
|
||||
end
|
||||
|
||||
context "methods created with define_method" do
|
||||
context "passed a block" do
|
||||
it "creates duplicates of the given instance methods" do
|
||||
m = Module.new do
|
||||
define_method :test1 do; end
|
||||
module_function :test1
|
||||
end
|
||||
|
||||
m.respond_to?(:test1).should == true
|
||||
end
|
||||
end
|
||||
|
||||
context "passed a method" do
|
||||
it "creates duplicates of the given instance methods" do
|
||||
module_with_method = Module.new do
|
||||
def test1; end
|
||||
end
|
||||
|
||||
c = Class.new do
|
||||
extend module_with_method
|
||||
end
|
||||
|
||||
m = Module.new do
|
||||
define_method :test2, c.method(:test1)
|
||||
module_function :test2
|
||||
end
|
||||
|
||||
m.respond_to?(:test2).should == true
|
||||
end
|
||||
end
|
||||
|
||||
context "passed an unbound method" do
|
||||
it "creates duplicates of the given instance methods" do
|
||||
module_with_method = Module.new do
|
||||
def test1; end
|
||||
end
|
||||
|
||||
m = Module.new do
|
||||
define_method :test2, module_with_method.instance_method(:test1)
|
||||
module_function :test2
|
||||
end
|
||||
|
||||
m.respond_to?(:test2).should == true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Module#module_function as a toggle (no arguments) in a Module body" do
|
||||
it "makes any subsequently defined methods module functions with the normal semantics" do
|
||||
m = Module.new {
|
||||
m = Module.new do
|
||||
module_function
|
||||
def test1() end
|
||||
def test2() end
|
||||
}
|
||||
end
|
||||
|
||||
m.respond_to?(:test1).should == true
|
||||
m.respond_to?(:test2).should == true
|
||||
|
@ -187,13 +234,13 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
|
|||
|
||||
it "stops creating module functions if the body encounters another toggle " \
|
||||
"like public/protected/private without arguments" do
|
||||
m = Module.new {
|
||||
m = Module.new do
|
||||
module_function
|
||||
def test1() end
|
||||
def test2() end
|
||||
public
|
||||
def test3() end
|
||||
}
|
||||
end
|
||||
|
||||
m.respond_to?(:test1).should == true
|
||||
m.respond_to?(:test2).should == true
|
||||
|
@ -202,14 +249,14 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
|
|||
|
||||
it "does not stop creating module functions if the body encounters " \
|
||||
"public/protected/private WITH arguments" do
|
||||
m = Module.new {
|
||||
m = Module.new do
|
||||
def foo() end
|
||||
module_function
|
||||
def test1() end
|
||||
def test2() end
|
||||
public :foo
|
||||
def test3() end
|
||||
}
|
||||
end
|
||||
|
||||
m.respond_to?(:test1).should == true
|
||||
m.respond_to?(:test2).should == true
|
||||
|
@ -217,69 +264,116 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
|
|||
end
|
||||
|
||||
it "does not affect module_evaled method definitions also if outside the eval itself" do
|
||||
m = Module.new {
|
||||
m = Module.new do
|
||||
module_function
|
||||
module_eval { def test1() end }
|
||||
module_eval " def test2() end "
|
||||
}
|
||||
end
|
||||
|
||||
m.respond_to?(:test1).should == false
|
||||
m.respond_to?(:test2).should == false
|
||||
end
|
||||
|
||||
it "has no effect if inside a module_eval if the definitions are outside of it" do
|
||||
m = Module.new {
|
||||
m = Module.new do
|
||||
module_eval { module_function }
|
||||
def test1() end
|
||||
def test2() end
|
||||
}
|
||||
end
|
||||
|
||||
m.respond_to?(:test1).should == false
|
||||
m.respond_to?(:test2).should == false
|
||||
end
|
||||
|
||||
it "functions normally if both toggle and definitions inside a module_eval" do
|
||||
m = Module.new {
|
||||
module_eval {
|
||||
m = Module.new do
|
||||
module_eval do
|
||||
module_function
|
||||
def test1() end
|
||||
def test2() end
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
m.respond_to?(:test1).should == true
|
||||
m.respond_to?(:test2).should == true
|
||||
end
|
||||
|
||||
it "affects evaled method definitions also even when outside the eval itself" do
|
||||
m = Module.new {
|
||||
it "affects eval'ed method definitions also even when outside the eval itself" do
|
||||
m = Module.new do
|
||||
module_function
|
||||
eval "def test1() end"
|
||||
}
|
||||
end
|
||||
|
||||
m.respond_to?(:test1).should == true
|
||||
end
|
||||
|
||||
it "doesn't affect definitions when inside an eval even if the definitions are outside of it" do
|
||||
m = Module.new {
|
||||
m = Module.new do
|
||||
eval "module_function"
|
||||
def test1() end
|
||||
}
|
||||
end
|
||||
|
||||
m.respond_to?(:test1).should == false
|
||||
end
|
||||
|
||||
it "functions normally if both toggle and definitions inside a eval" do
|
||||
m = Module.new {
|
||||
m = Module.new do
|
||||
eval <<-CODE
|
||||
module_function
|
||||
|
||||
def test1() end
|
||||
def test2() end
|
||||
CODE
|
||||
}
|
||||
end
|
||||
|
||||
m.respond_to?(:test1).should == true
|
||||
m.respond_to?(:test2).should == true
|
||||
end
|
||||
|
||||
context "methods are defined with define_method" do
|
||||
context "passed a block" do
|
||||
it "makes any subsequently defined methods module functions with the normal semantics" do
|
||||
m = Module.new do
|
||||
module_function
|
||||
define_method :test1 do; end
|
||||
end
|
||||
|
||||
m.respond_to?(:test1).should == true
|
||||
end
|
||||
end
|
||||
|
||||
context "passed a method" do
|
||||
it "makes any subsequently defined methods module functions with the normal semantics" do
|
||||
module_with_method = Module.new do
|
||||
def test1; end
|
||||
end
|
||||
|
||||
c = Class.new do
|
||||
extend module_with_method
|
||||
end
|
||||
|
||||
m = Module.new do
|
||||
module_function
|
||||
define_method :test2, c.method(:test1)
|
||||
end
|
||||
|
||||
m.respond_to?(:test2).should == true
|
||||
end
|
||||
end
|
||||
|
||||
context "passed an unbound method" do
|
||||
it "makes any subsequently defined methods module functions with the normal semantics" do
|
||||
module_with_method = Module.new do
|
||||
def test1; end
|
||||
end
|
||||
|
||||
m = Module.new do
|
||||
module_function
|
||||
define_method :test2, module_with_method.instance_method(:test1)
|
||||
end
|
||||
|
||||
m.respond_to?(:test2).should == true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require_relative '../../spec_helper'
|
||||
require_relative '../../shared/queue/enque'
|
||||
require_relative '../../shared/sizedqueue/enque'
|
||||
require_relative '../../shared/types/rb_num2dbl_fails'
|
||||
|
||||
describe "SizedQueue#<<" do
|
||||
it_behaves_like :queue_enq, :<<, -> { SizedQueue.new(10) }
|
||||
|
@ -9,3 +10,9 @@ end
|
|||
describe "SizedQueue#<<" do
|
||||
it_behaves_like :sizedqueue_enq, :<<, -> n { SizedQueue.new(n) }
|
||||
end
|
||||
|
||||
describe "SizedQueue operations with timeout" do
|
||||
ruby_version_is "3.2" do
|
||||
it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(1); q.send(:<<, 1, timeout: v) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require_relative '../../spec_helper'
|
||||
require_relative '../../shared/queue/enque'
|
||||
require_relative '../../shared/sizedqueue/enque'
|
||||
require_relative '../../shared/types/rb_num2dbl_fails'
|
||||
|
||||
describe "SizedQueue#enq" do
|
||||
it_behaves_like :queue_enq, :enq, -> { SizedQueue.new(10) }
|
||||
|
@ -9,3 +10,9 @@ end
|
|||
describe "SizedQueue#enq" do
|
||||
it_behaves_like :sizedqueue_enq, :enq, -> n { SizedQueue.new(n) }
|
||||
end
|
||||
|
||||
describe "SizedQueue operations with timeout" do
|
||||
ruby_version_is "3.2" do
|
||||
it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(1); q.enq(1, timeout: v) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require_relative '../../spec_helper'
|
||||
require_relative '../../shared/queue/enque'
|
||||
require_relative '../../shared/sizedqueue/enque'
|
||||
require_relative '../../shared/types/rb_num2dbl_fails'
|
||||
|
||||
describe "SizedQueue#push" do
|
||||
it_behaves_like :queue_enq, :push, -> { SizedQueue.new(10) }
|
||||
|
@ -9,3 +10,9 @@ end
|
|||
describe "SizedQueue#push" do
|
||||
it_behaves_like :sizedqueue_enq, :push, -> n { SizedQueue.new(n) }
|
||||
end
|
||||
|
||||
describe "SizedQueue operations with timeout" do
|
||||
ruby_version_is "3.2" do
|
||||
it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(1); q.push(1, timeout: v) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -79,6 +79,10 @@ describe "String#encode" do
|
|||
encoded.encode("UTF-8").should == "ちfoofoo"
|
||||
end
|
||||
|
||||
it "replace multiple invalid bytes at the end with a single replacement character" do
|
||||
"\xE3\x81\x93\xE3\x81".encode("UTF-8", invalid: :replace).should == "\u3053\ufffd"
|
||||
end
|
||||
|
||||
it "replaces invalid encoding in source using a specified replacement even when a fallback is given" do
|
||||
encoded = "ち\xE3\x81\xFF".encode("UTF-16LE", invalid: :replace, replace: "foo", fallback: -> c { "bar" })
|
||||
encoded.should == "\u3061foofoo".encode("UTF-16LE")
|
||||
|
|
|
@ -167,6 +167,13 @@ describe "String#index with String" do
|
|||
it "handles a substring in a subset encoding" do
|
||||
'été'.index('t'.force_encoding(Encoding::US_ASCII)).should == 1
|
||||
end
|
||||
|
||||
it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
|
||||
str = 'abc'.force_encoding("ISO-2022-JP")
|
||||
pattern = 'b'.force_encoding("EUC-JP")
|
||||
|
||||
-> { str.index(pattern) }.should raise_error(Encoding::CompatibilityError, "incompatible character encodings: ISO-2022-JP and EUC-JP")
|
||||
end
|
||||
end
|
||||
|
||||
describe "String#index with Regexp" do
|
||||
|
@ -312,6 +319,17 @@ describe "String#index with Regexp" do
|
|||
"われわわれ".index(/わ/, 3).should == 3
|
||||
end
|
||||
|
||||
ruby_bug "#19763", ""..."3.3.0" do
|
||||
it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
|
||||
re = Regexp.new "れ".encode(Encoding::EUC_JP)
|
||||
-> do
|
||||
"あれ".index re
|
||||
end.should raise_error(Encoding::CompatibilityError, "incompatible encoding regexp match (EUC-JP regexp with UTF-8 string)")
|
||||
end
|
||||
end
|
||||
|
||||
# The exception message was incorrectly "incompatible character encodings: UTF-8 and EUC-JP" before 3.3.0
|
||||
# Still test that the right exception class is used before that.
|
||||
it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
|
||||
re = Regexp.new "れ".encode(Encoding::EUC_JP)
|
||||
-> do
|
||||
|
|
|
@ -204,6 +204,13 @@ describe "String#rindex with String" do
|
|||
it "handles a substring in a subset encoding" do
|
||||
'été'.rindex('t'.force_encoding(Encoding::US_ASCII)).should == 1
|
||||
end
|
||||
|
||||
it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
|
||||
str = 'abc'.force_encoding("ISO-2022-JP")
|
||||
pattern = 'b'.force_encoding("EUC-JP")
|
||||
|
||||
-> { str.rindex(pattern) }.should raise_error(Encoding::CompatibilityError, "incompatible character encodings: ISO-2022-JP and EUC-JP")
|
||||
end
|
||||
end
|
||||
|
||||
describe "String#rindex with Regexp" do
|
||||
|
@ -373,6 +380,6 @@ describe "String#rindex with Regexp" do
|
|||
re = Regexp.new "れ".encode(Encoding::EUC_JP)
|
||||
-> do
|
||||
"あれ".rindex re
|
||||
end.should raise_error(Encoding::CompatibilityError)
|
||||
end.should raise_error(Encoding::CompatibilityError, "incompatible encoding regexp match (EUC-JP regexp with UTF-8 string)")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -80,6 +80,12 @@ describe "String#upto" do
|
|||
a.should == ["Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω"]
|
||||
end
|
||||
|
||||
it "raises Encoding::CompatibilityError when incompatible characters are given" do
|
||||
char1 = 'a'.force_encoding("EUC-JP")
|
||||
char2 = 'b'.force_encoding("ISO-2022-JP")
|
||||
-> { char1.upto(char2) {} }.should raise_error(Encoding::CompatibilityError, "incompatible character encodings: EUC-JP and ISO-2022-JP")
|
||||
end
|
||||
|
||||
describe "on sequence of numbers" do
|
||||
it "calls the block as Integer#upto" do
|
||||
"8".upto("11").to_a.should == 8.upto(11).map(&:to_s)
|
||||
|
|
|
@ -52,6 +52,15 @@ describe "The alias keyword" do
|
|||
@obj.a.should == 5
|
||||
end
|
||||
|
||||
it "works with an interpolated symbol with non-literal embedded expression on the left-hand side" do
|
||||
@meta.class_eval do
|
||||
eval %Q{
|
||||
alias :"#{'a' + ''.to_s}" value
|
||||
}
|
||||
end
|
||||
@obj.a.should == 5
|
||||
end
|
||||
|
||||
it "works with a simple symbol on the right-hand side" do
|
||||
@meta.class_eval do
|
||||
alias a :value
|
||||
|
@ -80,6 +89,15 @@ describe "The alias keyword" do
|
|||
@obj.a.should == 5
|
||||
end
|
||||
|
||||
it "works with an interpolated symbol with non-literal embedded expression on the right-hand side" do
|
||||
@meta.class_eval do
|
||||
eval %Q{
|
||||
alias a :"#{'value' + ''.to_s}"
|
||||
}
|
||||
end
|
||||
@obj.a.should == 5
|
||||
end
|
||||
|
||||
it "adds the new method to the list of methods" do
|
||||
original_methods = @obj.methods
|
||||
@meta.class_eval do
|
||||
|
|
|
@ -434,6 +434,15 @@ describe "The 'case'-construct with no target expression" do
|
|||
end.should == :called
|
||||
end
|
||||
|
||||
it "only matches last value in complex expressions within ()" do
|
||||
case 'a'
|
||||
when ('a'; 'b')
|
||||
:wrong_called
|
||||
when ('b'; 'a')
|
||||
:called
|
||||
end.should == :called
|
||||
end
|
||||
|
||||
# Homogeneous cases are often optimized to avoid === using a jump table, and should be tested separately.
|
||||
# See https://github.com/jruby/jruby/issues/6440
|
||||
it "handles homogeneous cases" do
|
||||
|
|
|
@ -8,12 +8,26 @@ describe "Pattern matching" do
|
|||
ScratchPad.record []
|
||||
end
|
||||
|
||||
it "can be standalone assoc operator that deconstructs value" do
|
||||
suppress_warning do
|
||||
eval(<<-RUBY).should == [0, 1]
|
||||
[0, 1] => [a, b]
|
||||
[a, b]
|
||||
RUBY
|
||||
describe "can be standalone assoc operator that" do
|
||||
it "deconstructs value" do
|
||||
suppress_warning do
|
||||
eval(<<-RUBY).should == [0, 1]
|
||||
[0, 1] => [a, b]
|
||||
[a, b]
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
it "deconstructs value and properly scopes variables" do
|
||||
suppress_warning do
|
||||
eval(<<-RUBY).should == [0, nil]
|
||||
a = nil
|
||||
eval(<<-PATTERN)
|
||||
[0, 1] => [a, b]
|
||||
PATTERN
|
||||
[a, defined?(b)]
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -203,6 +203,25 @@ describe "The super keyword" do
|
|||
-> { klass.new.a(:a_called) }.should raise_error(RuntimeError)
|
||||
end
|
||||
|
||||
it "is able to navigate to super, when a method is defined dynamically on the singleton class" do
|
||||
foo_class = Class.new do
|
||||
def bar
|
||||
"bar"
|
||||
end
|
||||
end
|
||||
|
||||
mixin_module = Module.new do
|
||||
def bar
|
||||
"super_" + super
|
||||
end
|
||||
end
|
||||
|
||||
foo = foo_class.new
|
||||
foo.singleton_class.define_method(:bar, mixin_module.instance_method(:bar))
|
||||
|
||||
foo.bar.should == "super_bar"
|
||||
end
|
||||
|
||||
# Rubinius ticket github#157
|
||||
it "calls method_missing when a superclass method is not found" do
|
||||
SuperSpecs::MM_B.new.is_a?(Hash).should == false
|
||||
|
|
|
@ -38,12 +38,19 @@ describe "The undef keyword" do
|
|||
-> { @obj.meth(5) }.should raise_error(NoMethodError)
|
||||
end
|
||||
|
||||
it "with a interpolated symbol" do
|
||||
it "with an interpolated symbol" do
|
||||
@undef_class.class_eval do
|
||||
undef :"#{'meth'}"
|
||||
end
|
||||
-> { @obj.meth(5) }.should raise_error(NoMethodError)
|
||||
end
|
||||
|
||||
it "with an interpolated symbol when interpolated expression is not a String literal" do
|
||||
@undef_class.class_eval do
|
||||
undef :"#{'meth'.to_sym}"
|
||||
end
|
||||
-> { @obj.meth(5) }.should raise_error(NoMethodError)
|
||||
end
|
||||
end
|
||||
|
||||
it "allows undefining multiple methods at a time" do
|
||||
|
|
|
@ -54,7 +54,7 @@ describe "BigDecimal#remainder" do
|
|||
@nan.remainder(@infinity).should.nan?
|
||||
end
|
||||
|
||||
version_is BigDecimal::VERSION, ""..."3.1.4" do
|
||||
version_is BigDecimal::VERSION, ""..."3.1.4" do #ruby_version_is ""..."3.3" do
|
||||
it "returns NaN if Infinity is involved" do
|
||||
@infinity.remainder(@infinity).should.nan?
|
||||
@infinity.remainder(@one).should.nan?
|
||||
|
|
|
@ -228,13 +228,13 @@ describe "BigDecimal#round" do
|
|||
-> { BigDecimal('-Infinity').round(2) }.should_not raise_error(FloatDomainError)
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.2' do
|
||||
version_is BigDecimal::VERSION, ''...'3.1.3' do #ruby_version_is ''...'3.2' do
|
||||
it 'raise for a non-existent round mode' do
|
||||
-> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode")
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is '3.2' do
|
||||
version_is BigDecimal::VERSION, '3.1.3' do #ruby_version_is '3.2' do
|
||||
it 'raise for a non-existent round mode' do
|
||||
-> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode (nonsense)")
|
||||
end
|
||||
|
|
|
@ -40,14 +40,13 @@ describe "BigDecimal#to_s" do
|
|||
end
|
||||
|
||||
ruby_version_is ""..."3.3" do
|
||||
it "inserts a space every n chars, if integer n is supplied" do
|
||||
it "inserts a space every n chars to fraction part, if integer n is supplied" do
|
||||
re =\
|
||||
/\A0\.314 159 265 358 979 323 846 264 338 327 950 288 419 716 939 937E1\z/i
|
||||
@bigdec.to_s(3).should =~ re
|
||||
|
||||
str1 = '-123.45678 90123 45678 9'
|
||||
BigDecimal("-123.45678901234567890").to_s('5F').should == str1
|
||||
BigDecimal('1000010').to_s('5F').should == "10000 10.0"
|
||||
# trailing zeroes removed
|
||||
BigDecimal("1.00000000000").to_s('1F').should == "1.0"
|
||||
# 0 is treated as no spaces
|
||||
|
@ -55,6 +54,12 @@ describe "BigDecimal#to_s" do
|
|||
end
|
||||
end
|
||||
|
||||
version_is BigDecimal::VERSION, "3.1.5" do #ruby_version_is '3.3' do
|
||||
it "inserts a space every n chars to integer part, if integer n is supplied" do
|
||||
BigDecimal('1000010').to_s('5F').should == "10 00010.0"
|
||||
end
|
||||
end
|
||||
|
||||
it "can return a leading space for values > 0" do
|
||||
@bigdec.to_s(" F").should =~ /\ .*/
|
||||
@bigneg.to_s(" F").should_not =~ /\ .*/
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require_relative '../../spec_helper'
|
||||
require 'date'
|
||||
|
||||
ruby_version_is "3.2" do
|
||||
version_is Date::VERSION, "3.3" do #ruby_version_is "3.2" do
|
||||
describe "Date#deconstruct_keys" do
|
||||
it "returns whole hash for nil as an argument" do
|
||||
d = Date.new(2022, 10, 5)
|
||||
|
|
|
@ -23,14 +23,14 @@ describe "Date#strftime" do
|
|||
end
|
||||
|
||||
# %v is %e-%b-%Y for Date/DateTime
|
||||
ruby_version_is ""..."3.1" do
|
||||
version_is Date::VERSION, ""..."3.2" do #ruby_version_is ""..."3.1" do
|
||||
it "should be able to show the commercial week" do
|
||||
@date.strftime("%v").should == " 9-Apr-2000"
|
||||
@date.strftime("%v").should == @date.strftime('%e-%b-%Y')
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.1" do
|
||||
version_is Date::VERSION, "3.2" do #ruby_version_is "3.1" do
|
||||
it "should be able to show the commercial week" do
|
||||
@date.strftime("%v").should == " 9-APR-2000"
|
||||
@date.strftime("%v").should != @date.strftime('%e-%b-%Y')
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require_relative '../../spec_helper'
|
||||
require 'date'
|
||||
|
||||
ruby_version_is "3.2" do
|
||||
version_is Date::VERSION, "3.3" do #ruby_version_is "3.2" do
|
||||
describe "DateTime#deconstruct_keys" do
|
||||
it "returns whole hash for nil as an argument" do
|
||||
d = DateTime.new(2022, 10, 5, 13, 30)
|
||||
|
|
|
@ -33,14 +33,14 @@ describe "DateTime#strftime" do
|
|||
end
|
||||
|
||||
# %v is %e-%b-%Y for Date/DateTime
|
||||
ruby_version_is ""..."3.1" do
|
||||
version_is Date::VERSION, ""..."3.2" do #ruby_version_is ""..."3.1" do
|
||||
it "should be able to show the commercial week" do
|
||||
@time.strftime("%v").should == " 3-Feb-2001"
|
||||
@time.strftime("%v").should == @time.strftime('%e-%b-%Y')
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.1" do
|
||||
version_is Date::VERSION, "3.2" do #ruby_version_is "3.1" do
|
||||
it "should be able to show the commercial week" do
|
||||
@time.strftime("%v").should == " 3-FEB-2001"
|
||||
@time.strftime("%v").should != @time.strftime('%e-%b-%Y')
|
||||
|
|
|
@ -18,8 +18,7 @@ describe "DateTime#to_time" do
|
|||
time.sec.should == 59
|
||||
end
|
||||
|
||||
date_version = defined?(Date::VERSION) ? Date::VERSION : '0.0.0'
|
||||
version_is(date_version, '3.2.3') do
|
||||
version_is(Date::VERSION, '3.2.3') do #ruby_version_is "3.2" do
|
||||
it "returns a Time representing the same instant before Gregorian" do
|
||||
datetime = DateTime.civil(1582, 10, 4, 23, 58, 59)
|
||||
time = datetime.to_time.utc
|
||||
|
|
|
@ -140,7 +140,7 @@ END
|
|||
end
|
||||
|
||||
describe "warning about arguments" do
|
||||
ruby_version_is "3.1" do
|
||||
version_is ERB.version, "2.2.1" do #ruby_version_is "3.1" do
|
||||
it "warns when passed safe_level and later arguments" do
|
||||
-> {
|
||||
ERB.new(@eruby_str, nil, '%')
|
||||
|
|
|
@ -77,7 +77,13 @@ describe "IPAddr#new" do
|
|||
a.family.should == Socket::AF_INET6
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.1" do
|
||||
ipaddr_version = if defined?(IPAddr::VERSION) #ruby_version_is ""..."3.1" do
|
||||
IPAddr::VERSION
|
||||
else
|
||||
"1.2.2"
|
||||
end
|
||||
|
||||
version_is ipaddr_version, ""..."1.2.3" do #ruby_version_is ""..."3.1" do
|
||||
it "raises on incorrect IPAddr strings" do
|
||||
[
|
||||
["fe80::1%fxp0"],
|
||||
|
@ -93,7 +99,7 @@ describe "IPAddr#new" do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.1" do
|
||||
version_is ipaddr_version, "1.2.3" do #ruby_version_is "3.1" do
|
||||
it "raises on incorrect IPAddr strings" do
|
||||
[
|
||||
["::1/255.255.255.0"],
|
||||
|
|
|
@ -15,17 +15,8 @@ describe "Logger::LogDevice#close" do
|
|||
rm_r @file_path
|
||||
end
|
||||
|
||||
version_is Logger::VERSION, ""..."1.4.0" do
|
||||
it "closes the LogDevice's stream" do
|
||||
@device.close
|
||||
-> { @device.write("Test") }.should complain(/\Alog writing failed\./)
|
||||
end
|
||||
end
|
||||
|
||||
version_is Logger::VERSION, "1.4.0" do
|
||||
it "closes the LogDevice's stream" do
|
||||
@device.close
|
||||
-> { @device.write("Test") }.should complain(/\Alog shifting failed\./)
|
||||
end
|
||||
it "closes the LogDevice's stream" do
|
||||
@device.close
|
||||
-> { @device.write("Test") }.should complain(/\Alog shifting failed\./)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,17 +35,8 @@ describe "Logger::LogDevice#write" do
|
|||
rm_r path
|
||||
end
|
||||
|
||||
version_is Logger::VERSION, ""..."1.4.0" do
|
||||
it "fails if the device is already closed" do
|
||||
@device.close
|
||||
-> { @device.write "foo" }.should complain(/\Alog writing failed\./)
|
||||
end
|
||||
end
|
||||
|
||||
version_is Logger::VERSION, "1.4.0" do
|
||||
it "fails if the device is already closed" do
|
||||
@device.close
|
||||
-> { @device.write "foo" }.should complain(/\Alog shifting failed\./)
|
||||
end
|
||||
it "fails if the device is already closed" do
|
||||
@device.close
|
||||
-> { @device.write "foo" }.should complain(/\Alog shifting failed\./)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,10 +14,8 @@ ruby_version_is ""..."3.1" do
|
|||
Matrix[[0, Complex(0, 1)], [Complex(0, 1), 0]].should.unitary?
|
||||
end
|
||||
|
||||
version_is((Matrix::const_defined?(:VERSION) ? Matrix::VERSION : "0.1.0"), "0.3.0") do
|
||||
it "returns true for unitary matrices with a Complex and a negative #imag" do
|
||||
Matrix[[0, Complex(0, 1)], [Complex(0, -1), 0]].should.unitary?
|
||||
end
|
||||
it "returns true for unitary matrices with a Complex and a negative #imag" do
|
||||
Matrix[[0, Complex(0, 1)], [Complex(0, -1), 0]].should.unitary?
|
||||
end
|
||||
|
||||
it "raises an error for rectangular matrices" do
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../shared/constants'
|
||||
|
||||
require 'openssl'
|
||||
|
||||
version_is(OpenSSL::VERSION, ""..."2.2") do
|
||||
describe "OpenSSL::Config#freeze" do
|
||||
it "needs to be reviewed for completeness"
|
||||
|
||||
it "freezes" do
|
||||
c = OpenSSL::Config.new
|
||||
-> {
|
||||
c['foo'] = [ ['key', 'value'] ]
|
||||
}.should_not raise_error
|
||||
c.freeze
|
||||
c.frozen?.should be_true
|
||||
-> {
|
||||
c['foo'] = [ ['key', 'value'] ]
|
||||
}.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -294,14 +294,9 @@ describe "StringIO#initialize sets" do
|
|||
io.string.encoding.should == Encoding::EUC_JP
|
||||
end
|
||||
|
||||
guard_not -> { # [Bug #16497]
|
||||
stringio_version = StringIO.const_defined?(:VERSION) ? StringIO::VERSION : "0.0.2"
|
||||
version_is(stringio_version, "0.0.3"..."0.1.1")
|
||||
} do
|
||||
it "the #external_encoding to 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
|
||||
end
|
||||
it "the #external_encoding to 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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,7 +36,7 @@ describe :stringio_each_separator, shared: true do
|
|||
seen.should == ["2 1 2 1 2"]
|
||||
end
|
||||
|
||||
ruby_version_is ''..."3.2" do
|
||||
version_is StringIO::VERSION, ""..."3.0.4" do #ruby_version_is ""..."3.2" do
|
||||
it "yields each paragraph with two separation characters when passed an empty String as separator" do
|
||||
seen = []
|
||||
io = StringIO.new("para1\n\npara2\n\n\npara3")
|
||||
|
@ -45,7 +45,7 @@ describe :stringio_each_separator, shared: true do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.2" do
|
||||
version_is StringIO::VERSION, "3.0.4" do #ruby_version_is "3.2" do
|
||||
it "yields each paragraph with all separation characters when passed an empty String as separator" do
|
||||
seen = []
|
||||
io = StringIO.new("para1\n\npara2\n\n\npara3")
|
||||
|
|
|
@ -13,8 +13,7 @@ describe "Time#to_datetime" do
|
|||
datetime.sec.should == 59
|
||||
end
|
||||
|
||||
date_version = defined?(Date::VERSION) ? Date::VERSION : '0.0.0'
|
||||
version_is(date_version, '3.2.3') do
|
||||
version_is(Date::VERSION, '3.2.3') do #ruby_version_is '3.2' do
|
||||
it "returns a DateTime representing the same instant before Gregorian" do
|
||||
time = Time.utc(1582, 10, 14, 23, 58, 59)
|
||||
datetime = time.to_datetime
|
||||
|
|
|
@ -2,7 +2,7 @@ require_relative '../../../spec_helper'
|
|||
require 'uri'
|
||||
|
||||
describe "URI::Generic#host" do
|
||||
ruby_version_is "3.2" do
|
||||
version_is URI::VERSION, "0.12" do #ruby_version_is "3.2" do
|
||||
# https://hackerone.com/reports/156615
|
||||
it "returns empty string when host is empty" do
|
||||
URI.parse('http:////foo.com').host.should == ''
|
||||
|
|
|
@ -2,7 +2,7 @@ require_relative '../../../spec_helper'
|
|||
require 'uri'
|
||||
|
||||
describe "URI::Generic#to_s" do
|
||||
ruby_version_is "3.2" do
|
||||
version_is URI::VERSION, "0.12" do #ruby_version_is "3.2" do
|
||||
# https://hackerone.com/reports/156615
|
||||
it "preserves / characters when host is empty" do
|
||||
URI('http:///foo.com').to_s.should == 'http:///foo.com'
|
||||
|
|
|
@ -100,6 +100,40 @@ describe "C-API Exception function" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "rb_syserr_new" do
|
||||
it "returns system error with default message when passed message is NULL" do
|
||||
exception = @s.rb_syserr_new(Errno::ENOENT::Errno, nil)
|
||||
exception.class.should == Errno::ENOENT
|
||||
exception.message.should include("No such file or directory")
|
||||
exception.should.is_a?(SystemCallError)
|
||||
end
|
||||
|
||||
it "returns system error with custom message" do
|
||||
exception = @s.rb_syserr_new(Errno::ENOENT::Errno, "custom message")
|
||||
|
||||
exception.message.should include("custom message")
|
||||
exception.class.should == Errno::ENOENT
|
||||
exception.should.is_a?(SystemCallError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "rb_syserr_new_str" do
|
||||
it "returns system error with default message when passed message is nil" do
|
||||
exception = @s.rb_syserr_new_str(Errno::ENOENT::Errno, nil)
|
||||
|
||||
exception.message.should include("No such file or directory")
|
||||
exception.class.should == Errno::ENOENT
|
||||
exception.should.is_a?(SystemCallError)
|
||||
end
|
||||
|
||||
it "returns system error with custom message" do
|
||||
exception = @s.rb_syserr_new_str(Errno::ENOENT::Errno, "custom message")
|
||||
exception.message.should include("custom message")
|
||||
exception.class.should == Errno::ENOENT
|
||||
exception.should.is_a?(SystemCallError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "rb_make_exception" do
|
||||
it "returns a RuntimeError when given a String argument" do
|
||||
e = @s.rb_make_exception(["Message"])
|
||||
|
|
|
@ -72,7 +72,7 @@ static VALUE class_spec_rb_class_new_instance_kw(VALUE self, VALUE args, VALUE k
|
|||
#endif
|
||||
|
||||
static VALUE class_spec_rb_class_real(VALUE self, VALUE object) {
|
||||
if(rb_type_p(object, T_FIXNUM)) {
|
||||
if (rb_type_p(object, T_FIXNUM)) {
|
||||
return INT2FIX(rb_class_real(FIX2INT(object)));
|
||||
} else {
|
||||
return rb_class_real(CLASS_OF(object));
|
||||
|
@ -116,19 +116,19 @@ VALUE class_spec_define_attr(VALUE self, VALUE klass, VALUE sym, VALUE read, VAL
|
|||
}
|
||||
|
||||
static VALUE class_spec_rb_define_class(VALUE self, VALUE name, VALUE super) {
|
||||
if(NIL_P(super)) super = 0;
|
||||
if (NIL_P(super)) super = 0;
|
||||
return rb_define_class(RSTRING_PTR(name), super);
|
||||
}
|
||||
|
||||
static VALUE class_spec_rb_define_class_under(VALUE self, VALUE outer,
|
||||
VALUE name, VALUE super) {
|
||||
if(NIL_P(super)) super = 0;
|
||||
if (NIL_P(super)) super = 0;
|
||||
return rb_define_class_under(outer, RSTRING_PTR(name), super);
|
||||
}
|
||||
|
||||
static VALUE class_spec_rb_define_class_id_under(VALUE self, VALUE outer,
|
||||
VALUE name, VALUE super) {
|
||||
if(NIL_P(super)) super = 0;
|
||||
if (NIL_P(super)) super = 0;
|
||||
return rb_define_class_id_under(outer, SYM2ID(name), super);
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ static VALUE rb_debug_inspector_frame_iseq_get_callback(const rb_debug_inspector
|
|||
return rb_debug_inspector_frame_iseq_get(dc, NUM2LONG((VALUE) ptr));
|
||||
}
|
||||
|
||||
static VALUE debug_spec_callback_data(VALUE self){
|
||||
static VALUE debug_spec_callback_data(VALUE self) {
|
||||
return callback_data;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ static VALUE encoding_spec_MBCLEN_CHARFOUND_P(VALUE self, VALUE obj) {
|
|||
}
|
||||
|
||||
static VALUE encoding_spec_ENC_CODERANGE_ASCIIONLY(VALUE self, VALUE obj) {
|
||||
if(ENC_CODERANGE_ASCIIONLY(obj)) {
|
||||
if (ENC_CODERANGE_ASCIIONLY(obj)) {
|
||||
return Qtrue;
|
||||
} else {
|
||||
return Qfalse;
|
||||
|
@ -61,13 +61,13 @@ static VALUE encoding_spec_rb_filesystem_encindex(VALUE self) {
|
|||
|
||||
static VALUE encoding_spec_rb_default_internal_encoding(VALUE self) {
|
||||
rb_encoding* enc = rb_default_internal_encoding();
|
||||
if(enc == 0) return Qnil;
|
||||
if (enc == 0) return Qnil;
|
||||
return rb_str_new2(enc->name);
|
||||
}
|
||||
|
||||
static VALUE encoding_spec_rb_default_external_encoding(VALUE self) {
|
||||
rb_encoding* enc = rb_default_external_encoding();
|
||||
if(enc == 0) return Qnil;
|
||||
if (enc == 0) return Qnil;
|
||||
return rb_str_new2(enc->name);
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ static VALUE encoding_spec_rb_enc_associate_index(VALUE self, VALUE obj, VALUE i
|
|||
static VALUE encoding_spec_rb_enc_compatible(VALUE self, VALUE a, VALUE b) {
|
||||
rb_encoding* enc = rb_enc_compatible(a, b);
|
||||
|
||||
if(!enc) return INT2FIX(0);
|
||||
if (!enc) return INT2FIX(0);
|
||||
|
||||
return rb_enc_from_encoding(enc);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ VALUE exception_spec_rb_exc_new3(VALUE self, VALUE str) {
|
|||
}
|
||||
|
||||
VALUE exception_spec_rb_exc_raise(VALUE self, VALUE exc) {
|
||||
if (self != Qundef) rb_exc_raise(exc);
|
||||
if (self != Qundef) rb_exc_raise(exc);
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,21 @@ VALUE exception_spec_rb_set_errinfo(VALUE self, VALUE exc) {
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE exception_spec_rb_syserr_new(VALUE self, VALUE num, VALUE msg) {
|
||||
int n = NUM2INT(num);
|
||||
char *cstr = NULL;
|
||||
|
||||
if (msg != Qnil) {
|
||||
cstr = StringValuePtr(msg);
|
||||
}
|
||||
|
||||
return rb_syserr_new(n, cstr);
|
||||
}
|
||||
|
||||
VALUE exception_spec_rb_syserr_new_str(VALUE self, VALUE num, VALUE msg) {
|
||||
int n = NUM2INT(num);
|
||||
return rb_syserr_new_str(n, msg);
|
||||
}
|
||||
|
||||
VALUE exception_spec_rb_make_exception(VALUE self, VALUE ary) {
|
||||
int argc = RARRAY_LENINT(ary);
|
||||
|
@ -51,6 +66,8 @@ void Init_exception_spec(void) {
|
|||
rb_define_method(cls, "rb_exc_new3", exception_spec_rb_exc_new3, 1);
|
||||
rb_define_method(cls, "rb_exc_raise", exception_spec_rb_exc_raise, 1);
|
||||
rb_define_method(cls, "rb_set_errinfo", exception_spec_rb_set_errinfo, 1);
|
||||
rb_define_method(cls, "rb_syserr_new", exception_spec_rb_syserr_new, 2);
|
||||
rb_define_method(cls, "rb_syserr_new_str", exception_spec_rb_syserr_new_str, 2);
|
||||
rb_define_method(cls, "rb_make_exception", exception_spec_rb_make_exception, 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ static VALUE gc_spec_rb_gc(VALUE self) {
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE gc_spec_rb_gc_latest_gc_info(VALUE self, VALUE hash_or_key){
|
||||
static VALUE gc_spec_rb_gc_latest_gc_info(VALUE self, VALUE hash_or_key) {
|
||||
return rb_gc_latest_gc_info(hash_or_key);
|
||||
}
|
||||
|
||||
|
|
|
@ -105,6 +105,12 @@ VALUE hash_spec_rb_hash_new(VALUE self) {
|
|||
return rb_hash_new();
|
||||
}
|
||||
|
||||
#ifdef RUBY_VERSION_IS_3_2
|
||||
VALUE hash_spec_rb_hash_new_capa(VALUE self, VALUE capacity) {
|
||||
return rb_hash_new_capa(NUM2LONG(capacity));
|
||||
}
|
||||
#endif
|
||||
|
||||
VALUE rb_ident_hash_new(void); /* internal.h, used in ripper */
|
||||
|
||||
VALUE hash_spec_rb_ident_hash_new(VALUE self) {
|
||||
|
@ -149,6 +155,9 @@ void Init_hash_spec(void) {
|
|||
rb_define_method(cls, "rb_hash_lookup2", hash_spec_rb_hash_lookup2, 3);
|
||||
rb_define_method(cls, "rb_hash_lookup2_default_undef", hash_spec_rb_hash_lookup2_default_undef, 2);
|
||||
rb_define_method(cls, "rb_hash_new", hash_spec_rb_hash_new, 0);
|
||||
#ifdef RUBY_VERSION_IS_3_2
|
||||
rb_define_method(cls, "rb_hash_new_capa", hash_spec_rb_hash_new_capa, 1);
|
||||
#endif
|
||||
rb_define_method(cls, "rb_ident_hash_new", hash_spec_rb_ident_hash_new, 0);
|
||||
rb_define_method(cls, "rb_hash_size", hash_spec_rb_hash_size, 1);
|
||||
rb_define_method(cls, "rb_hash_set_ifnone", hash_spec_rb_hash_set_ifnone, 2);
|
||||
|
|
|
@ -6,8 +6,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
static VALUE integer_spec_rb_integer_pack(VALUE self, VALUE value,
|
||||
VALUE words, VALUE numwords, VALUE wordsize, VALUE nails, VALUE flags)
|
||||
{
|
||||
VALUE words, VALUE numwords, VALUE wordsize, VALUE nails, VALUE flags) {
|
||||
int result = rb_integer_pack(value, (void*)RSTRING_PTR(words), FIX2INT(numwords),
|
||||
FIX2INT(wordsize), FIX2INT(nails), FIX2INT(flags));
|
||||
return INT2FIX(result);
|
||||
|
@ -15,7 +14,7 @@ static VALUE integer_spec_rb_integer_pack(VALUE self, VALUE value,
|
|||
|
||||
RUBY_EXTERN VALUE rb_int_positive_pow(long x, unsigned long y); /* internal.h, used in ripper */
|
||||
|
||||
static VALUE integer_spec_rb_int_positive_pow(VALUE self, VALUE a, VALUE b){
|
||||
static VALUE integer_spec_rb_int_positive_pow(VALUE self, VALUE a, VALUE b) {
|
||||
return rb_int_positive_pow(FIX2INT(a), FIX2INT(b));
|
||||
}
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ VALUE io_spec_rb_io_wait_readable(VALUE self, VALUE io, VALUE read_p) {
|
|||
rb_sys_fail("set_non_blocking failed");
|
||||
|
||||
#ifndef SET_NON_BLOCKING_FAILS_ALWAYS
|
||||
if(RTEST(read_p)) {
|
||||
if (RTEST(read_p)) {
|
||||
if (read(fd, buf, RB_IO_WAIT_READABLE_BUF) != -1) {
|
||||
return Qnil;
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ VALUE io_spec_rb_io_wait_readable(VALUE self, VALUE io, VALUE read_p) {
|
|||
|
||||
ret = rb_io_wait_readable(fd);
|
||||
|
||||
if(RTEST(read_p)) {
|
||||
if (RTEST(read_p)) {
|
||||
ssize_t r = read(fd, buf, RB_IO_WAIT_READABLE_BUF);
|
||||
if (r != RB_IO_WAIT_READABLE_BUF) {
|
||||
perror("read");
|
||||
|
@ -185,7 +185,7 @@ VALUE io_spec_rb_io_maybe_wait_readable(VALUE self, VALUE error, VALUE io, VALUE
|
|||
rb_sys_fail("set_non_blocking failed");
|
||||
|
||||
#ifndef SET_NON_BLOCKING_FAILS_ALWAYS
|
||||
if(RTEST(read_p)) {
|
||||
if (RTEST(read_p)) {
|
||||
if (read(fd, buf, RB_IO_WAIT_READABLE_BUF) != -1) {
|
||||
return Qnil;
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ VALUE io_spec_rb_io_maybe_wait_readable(VALUE self, VALUE error, VALUE io, VALUE
|
|||
// main part
|
||||
ret = rb_io_maybe_wait_readable(NUM2INT(error), io, timeout);
|
||||
|
||||
if(RTEST(read_p)) {
|
||||
if (RTEST(read_p)) {
|
||||
ssize_t r = read(fd, buf, RB_IO_WAIT_READABLE_BUF);
|
||||
if (r != RB_IO_WAIT_READABLE_BUF) {
|
||||
perror("read");
|
||||
|
|
|
@ -220,7 +220,7 @@ static VALUE kernel_spec_rb_eval_string_protect(VALUE self, VALUE str, VALUE ary
|
|||
|
||||
VALUE kernel_spec_rb_sys_fail(VALUE self, VALUE msg) {
|
||||
errno = 1;
|
||||
if(msg == Qnil) {
|
||||
if (msg == Qnil) {
|
||||
rb_sys_fail(0);
|
||||
} else if (self != Qundef) {
|
||||
rb_sys_fail(StringValuePtr(msg));
|
||||
|
@ -229,7 +229,7 @@ VALUE kernel_spec_rb_sys_fail(VALUE self, VALUE msg) {
|
|||
}
|
||||
|
||||
VALUE kernel_spec_rb_syserr_fail(VALUE self, VALUE err, VALUE msg) {
|
||||
if(msg == Qnil) {
|
||||
if (msg == Qnil) {
|
||||
rb_syserr_fail(NUM2INT(err), NULL);
|
||||
} else if (self != Qundef) {
|
||||
rb_syserr_fail(NUM2INT(err), StringValuePtr(msg));
|
||||
|
@ -292,9 +292,9 @@ static VALUE kernel_spec_rb_yield_values2(VALUE self, VALUE ary) {
|
|||
}
|
||||
|
||||
static VALUE do_rec(VALUE obj, VALUE arg, int is_rec) {
|
||||
if(is_rec) {
|
||||
if (is_rec) {
|
||||
return obj;
|
||||
} else if(arg == Qtrue) {
|
||||
} else if (arg == Qtrue) {
|
||||
return rb_exec_recursive(do_rec, obj, Qnil);
|
||||
} else {
|
||||
return Qnil;
|
||||
|
|
|
@ -218,126 +218,126 @@ static VALUE so_check_type(VALUE self, VALUE obj, VALUE other) {
|
|||
}
|
||||
|
||||
static VALUE so_is_type_nil(VALUE self, VALUE obj) {
|
||||
if(TYPE(obj) == T_NIL) {
|
||||
if (TYPE(obj) == T_NIL) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_type_object(VALUE self, VALUE obj) {
|
||||
if(TYPE(obj) == T_OBJECT) {
|
||||
if (TYPE(obj) == T_OBJECT) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_type_array(VALUE self, VALUE obj) {
|
||||
if(TYPE(obj) == T_ARRAY) {
|
||||
if (TYPE(obj) == T_ARRAY) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_type_module(VALUE self, VALUE obj) {
|
||||
if(TYPE(obj) == T_MODULE) {
|
||||
if (TYPE(obj) == T_MODULE) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_type_class(VALUE self, VALUE obj) {
|
||||
if(TYPE(obj) == T_CLASS) {
|
||||
if (TYPE(obj) == T_CLASS) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_type_data(VALUE self, VALUE obj) {
|
||||
if(TYPE(obj) == T_DATA) {
|
||||
if (TYPE(obj) == T_DATA) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_rb_type_p_nil(VALUE self, VALUE obj) {
|
||||
if(rb_type_p(obj, T_NIL)) {
|
||||
if (rb_type_p(obj, T_NIL)) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_rb_type_p_object(VALUE self, VALUE obj) {
|
||||
if(rb_type_p(obj, T_OBJECT)) {
|
||||
if (rb_type_p(obj, T_OBJECT)) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_rb_type_p_array(VALUE self, VALUE obj) {
|
||||
if(rb_type_p(obj, T_ARRAY)) {
|
||||
if (rb_type_p(obj, T_ARRAY)) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_rb_type_p_module(VALUE self, VALUE obj) {
|
||||
if(rb_type_p(obj, T_MODULE)) {
|
||||
if (rb_type_p(obj, T_MODULE)) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_rb_type_p_class(VALUE self, VALUE obj) {
|
||||
if(rb_type_p(obj, T_CLASS)) {
|
||||
if (rb_type_p(obj, T_CLASS)) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_rb_type_p_data(VALUE self, VALUE obj) {
|
||||
if(rb_type_p(obj, T_DATA)) {
|
||||
if (rb_type_p(obj, T_DATA)) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_rb_type_p_file(VALUE self, VALUE obj) {
|
||||
if(rb_type_p(obj, T_FILE)) {
|
||||
if (rb_type_p(obj, T_FILE)) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_builtin_type_object(VALUE self, VALUE obj) {
|
||||
if(BUILTIN_TYPE(obj) == T_OBJECT) {
|
||||
if (BUILTIN_TYPE(obj) == T_OBJECT) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_builtin_type_array(VALUE self, VALUE obj) {
|
||||
if(BUILTIN_TYPE(obj) == T_ARRAY) {
|
||||
if (BUILTIN_TYPE(obj) == T_ARRAY) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_builtin_type_module(VALUE self, VALUE obj) {
|
||||
if(BUILTIN_TYPE(obj) == T_MODULE) {
|
||||
if (BUILTIN_TYPE(obj) == T_MODULE) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_builtin_type_class(VALUE self, VALUE obj) {
|
||||
if(BUILTIN_TYPE(obj) == T_CLASS) {
|
||||
if (BUILTIN_TYPE(obj) == T_CLASS) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE so_is_builtin_type_data(VALUE self, VALUE obj) {
|
||||
if(BUILTIN_TYPE(obj) == T_DATA) {
|
||||
if (BUILTIN_TYPE(obj) == T_DATA) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
|
|
|
@ -7,7 +7,7 @@ extern "C" {
|
|||
|
||||
VALUE range_spec_rb_range_new(int argc, VALUE* argv, VALUE self) {
|
||||
int exclude_end = 0;
|
||||
if(argc == 3) {
|
||||
if (argc == 3) {
|
||||
exclude_end = RTEST(argv[2]);
|
||||
}
|
||||
return rb_range_new(argv[0], argv[1], exclude_end);
|
||||
|
|
|
@ -62,7 +62,7 @@ VALUE string_spec_rb_str_buf_new(VALUE self, VALUE len, VALUE str) {
|
|||
|
||||
buf = rb_str_buf_new(NUM2LONG(len));
|
||||
|
||||
if(RTEST(str)) {
|
||||
if (RTEST(str)) {
|
||||
snprintf(RSTRING_PTR(buf), NUM2LONG(len), "%s", RSTRING_PTR(str));
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ VALUE string_spec_rb_str_conv_enc(VALUE self, VALUE str, VALUE from, VALUE to) {
|
|||
|
||||
from_enc = rb_to_encoding(from);
|
||||
|
||||
if(NIL_P(to)) {
|
||||
if (NIL_P(to)) {
|
||||
to_enc = 0;
|
||||
} else {
|
||||
to_enc = rb_to_encoding(to);
|
||||
|
@ -139,14 +139,13 @@ VALUE string_spec_rb_str_conv_enc(VALUE self, VALUE str, VALUE from, VALUE to) {
|
|||
}
|
||||
|
||||
VALUE string_spec_rb_str_conv_enc_opts(VALUE self, VALUE str, VALUE from, VALUE to,
|
||||
VALUE ecflags, VALUE ecopts)
|
||||
{
|
||||
VALUE ecflags, VALUE ecopts) {
|
||||
rb_encoding* from_enc;
|
||||
rb_encoding* to_enc;
|
||||
|
||||
from_enc = rb_to_encoding(from);
|
||||
|
||||
if(NIL_P(to)) {
|
||||
if (NIL_P(to)) {
|
||||
to_enc = 0;
|
||||
} else {
|
||||
to_enc = rb_to_encoding(to);
|
||||
|
@ -200,7 +199,7 @@ VALUE string_spec_rb_str_new_offset(VALUE self, VALUE str, VALUE offset, VALUE l
|
|||
}
|
||||
|
||||
VALUE string_spec_rb_str_new2(VALUE self, VALUE str) {
|
||||
if(NIL_P(str)) {
|
||||
if (NIL_P(str)) {
|
||||
return rb_str_new2("");
|
||||
} else {
|
||||
return rb_str_new2(RSTRING_PTR(str));
|
||||
|
@ -216,7 +215,7 @@ VALUE string_spec_rb_str_export_to_enc(VALUE self, VALUE str, VALUE enc) {
|
|||
}
|
||||
|
||||
VALUE string_spec_rb_str_new_cstr(VALUE self, VALUE str) {
|
||||
if(NIL_P(str)) {
|
||||
if (NIL_P(str)) {
|
||||
return rb_str_new_cstr("");
|
||||
} else {
|
||||
return rb_str_new_cstr(RSTRING_PTR(str));
|
||||
|
@ -390,7 +389,7 @@ VALUE string_spec_RSTRING_PTR_set(VALUE self, VALUE str, VALUE i, VALUE chr) {
|
|||
|
||||
VALUE string_spec_RSTRING_PTR_after_funcall(VALUE self, VALUE str, VALUE cb) {
|
||||
/* Silence gcc 4.3.2 warning about computed value not used */
|
||||
if(RSTRING_PTR(str)) { /* force it out */
|
||||
if (RSTRING_PTR(str)) { /* force it out */
|
||||
rb_funcall(cb, rb_intern("call"), 1, str);
|
||||
}
|
||||
|
||||
|
@ -573,7 +572,7 @@ static VALUE string_spec_rb_utf8_str_new_cstr(VALUE self) {
|
|||
}
|
||||
|
||||
PRINTF_ARGS(static VALUE call_rb_str_vcatf(VALUE mesg, const char *fmt, ...), 2, 3);
|
||||
static VALUE call_rb_str_vcatf(VALUE mesg, const char *fmt, ...){
|
||||
static VALUE call_rb_str_vcatf(VALUE mesg, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
VALUE result = rb_str_vcatf(mesg, fmt, ap);
|
||||
|
|
|
@ -15,13 +15,11 @@ static VALUE struct_spec_rb_struct_getmember(VALUE self, VALUE st, VALUE key) {
|
|||
return rb_struct_getmember(st, SYM2ID(key));
|
||||
}
|
||||
|
||||
static VALUE struct_spec_rb_struct_s_members(VALUE self, VALUE klass)
|
||||
{
|
||||
static VALUE struct_spec_rb_struct_s_members(VALUE self, VALUE klass) {
|
||||
return rb_ary_dup(rb_struct_s_members(klass));
|
||||
}
|
||||
|
||||
static VALUE struct_spec_rb_struct_members(VALUE self, VALUE st)
|
||||
{
|
||||
static VALUE struct_spec_rb_struct_members(VALUE self, VALUE st) {
|
||||
return rb_ary_dup(rb_struct_members(st));
|
||||
}
|
||||
|
||||
|
@ -56,14 +54,11 @@ static VALUE struct_spec_struct_define_under(VALUE self, VALUE outer,
|
|||
}
|
||||
|
||||
static VALUE struct_spec_rb_struct_new(VALUE self, VALUE klass,
|
||||
VALUE a, VALUE b, VALUE c)
|
||||
{
|
||||
|
||||
VALUE a, VALUE b, VALUE c) {
|
||||
return rb_struct_new(klass, a, b, c);
|
||||
}
|
||||
|
||||
static VALUE struct_spec_rb_struct_size(VALUE self, VALUE st)
|
||||
{
|
||||
static VALUE struct_spec_rb_struct_size(VALUE self, VALUE st) {
|
||||
return rb_struct_size(st);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ static VALUE tracepoint_spec_rb_tracepoint_new(VALUE self, VALUE data) {
|
|||
return rb_tracepoint_new(Qnil, RUBY_EVENT_LINE, callback, (void*) data);
|
||||
}
|
||||
|
||||
static VALUE tracepoint_spec_callback_called(VALUE self){
|
||||
static VALUE tracepoint_spec_callback_called(VALUE self) {
|
||||
return callback_called;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,22 @@ describe "C-API Hash function" do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is '3.2' do
|
||||
describe "rb_hash_new_capa" do
|
||||
it "returns a new hash" do
|
||||
@s.rb_hash_new_capa(3).should == {}
|
||||
end
|
||||
|
||||
it "creates a hash with no default proc" do
|
||||
@s.rb_hash_new_capa(3) {}.default_proc.should be_nil
|
||||
end
|
||||
|
||||
it "raises RuntimeError when negative index is provided" do
|
||||
-> { @s.rb_hash_new_capa(-1) }.should raise_error(RuntimeError, "st_table too big")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "rb_ident_hash_new" do
|
||||
it "returns a new compare by identity hash" do
|
||||
result = @s.rb_ident_hash_new
|
||||
|
|
|
@ -37,7 +37,7 @@ describe :sizedqueue_enq, shared: true do
|
|||
q << 1
|
||||
|
||||
t = Thread.new {
|
||||
-> { q.send(@method, 2) }.should raise_error(ClosedQueueError)
|
||||
-> { q.send(@method, 2) }.should raise_error(ClosedQueueError, "queue closed")
|
||||
}
|
||||
|
||||
Thread.pass until q.num_waiting == 1
|
||||
|
@ -108,6 +108,28 @@ describe :sizedqueue_enq, shared: true do
|
|||
"can't set a timeout if non_block is enabled",
|
||||
)
|
||||
end
|
||||
|
||||
it "raise ClosedQueueError when closed before enqueued" do
|
||||
q = @object.call(1)
|
||||
q.close
|
||||
-> { q.send(@method, 2, timeout: 1) }.should raise_error(ClosedQueueError, "queue closed")
|
||||
end
|
||||
|
||||
it "interrupts enqueuing threads with ClosedQueueError when the queue is closed" do
|
||||
q = @object.call(1)
|
||||
q << 1
|
||||
|
||||
t = Thread.new {
|
||||
-> { q.send(@method, 1, timeout: 0.1) }.should raise_error(ClosedQueueError, "queue closed")
|
||||
}
|
||||
|
||||
Thread.pass until q.num_waiting == 1
|
||||
|
||||
q.close
|
||||
|
||||
t.join
|
||||
q.pop.should == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче