Update to ruby/spec@9e278f5
This commit is contained in:
parent
e20f1e443f
commit
dc54574ade
@ -14,6 +14,10 @@ describe "Encoding::Converter#primitive_convert" do
|
|||||||
-> { @ec.primitive_convert("","") }.should_not raise_error
|
-> { @ec.primitive_convert("","") }.should_not raise_error
|
||||||
end
|
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
|
it "accepts nil for the destination byte offset" do
|
||||||
-> { @ec.primitive_convert("","", nil) }.should_not raise_error
|
-> { @ec.primitive_convert("","", nil) }.should_not raise_error
|
||||||
end
|
end
|
||||||
|
@ -26,13 +26,11 @@ describe "SystemCallError.===" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "returns true if receiver is generic and arg is kind of SystemCallError" do
|
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)
|
e = SystemCallError.new('foo', @example_errno)
|
||||||
SystemCallError.===(e).should == true
|
SystemCallError.===(e).should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false if receiver is generic and arg is not kind of SystemCallError" do
|
it "returns false if receiver is generic and arg is not kind of SystemCallError" do
|
||||||
unknown_error_number = Errno.constants.size
|
|
||||||
e = Object.new
|
e = Object.new
|
||||||
SystemCallError.===(e).should == false
|
SystemCallError.===(e).should == false
|
||||||
end
|
end
|
||||||
|
@ -105,7 +105,7 @@ describe "Module#const_get" do
|
|||||||
-> { ConstantSpecs.const_get("CS_CONST1", false) }.should raise_error(NameError)
|
-> { ConstantSpecs.const_get("CS_CONST1", false) }.should raise_error(NameError)
|
||||||
end
|
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
|
ConstantSpecs.const_get("ConstantSpecsTwo::Foo").should == :cs_two_foo
|
||||||
ConstantSpecsThree.const_get("ConstantSpecsTwo::Foo").should == :cs_three_foo
|
ConstantSpecsThree.const_get("ConstantSpecsTwo::Foo").should == :cs_three_foo
|
||||||
end
|
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)
|
klass.should have_public_instance_method(:baz)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
describe "passed a block" do
|
describe "passed a block" do
|
||||||
|
@ -155,15 +155,62 @@ describe "Module#module_function with specific method names" do
|
|||||||
|
|
||||||
m.foo.should == ["m", "super_m"]
|
m.foo.should == ["m", "super_m"]
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "Module#module_function as a toggle (no arguments) in a Module body" do
|
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
|
it "makes any subsequently defined methods module functions with the normal semantics" do
|
||||||
m = Module.new {
|
m = Module.new do
|
||||||
module_function
|
module_function
|
||||||
def test1() end
|
def test1() end
|
||||||
def test2() end
|
def test2() end
|
||||||
}
|
end
|
||||||
|
|
||||||
m.respond_to?(:test1).should == true
|
m.respond_to?(:test1).should == true
|
||||||
m.respond_to?(:test2).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 " \
|
it "stops creating module functions if the body encounters another toggle " \
|
||||||
"like public/protected/private without arguments" do
|
"like public/protected/private without arguments" do
|
||||||
m = Module.new {
|
m = Module.new do
|
||||||
module_function
|
module_function
|
||||||
def test1() end
|
def test1() end
|
||||||
def test2() end
|
def test2() end
|
||||||
public
|
public
|
||||||
def test3() end
|
def test3() end
|
||||||
}
|
end
|
||||||
|
|
||||||
m.respond_to?(:test1).should == true
|
m.respond_to?(:test1).should == true
|
||||||
m.respond_to?(:test2).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 " \
|
it "does not stop creating module functions if the body encounters " \
|
||||||
"public/protected/private WITH arguments" do
|
"public/protected/private WITH arguments" do
|
||||||
m = Module.new {
|
m = Module.new do
|
||||||
def foo() end
|
def foo() end
|
||||||
module_function
|
module_function
|
||||||
def test1() end
|
def test1() end
|
||||||
def test2() end
|
def test2() end
|
||||||
public :foo
|
public :foo
|
||||||
def test3() end
|
def test3() end
|
||||||
}
|
end
|
||||||
|
|
||||||
m.respond_to?(:test1).should == true
|
m.respond_to?(:test1).should == true
|
||||||
m.respond_to?(:test2).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
|
end
|
||||||
|
|
||||||
it "does not affect module_evaled method definitions also if outside the eval itself" do
|
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_function
|
||||||
module_eval { def test1() end }
|
module_eval { def test1() end }
|
||||||
module_eval " def test2() end "
|
module_eval " def test2() end "
|
||||||
}
|
end
|
||||||
|
|
||||||
m.respond_to?(:test1).should == false
|
m.respond_to?(:test1).should == false
|
||||||
m.respond_to?(:test2).should == false
|
m.respond_to?(:test2).should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "has no effect if inside a module_eval if the definitions are outside of it" do
|
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 }
|
module_eval { module_function }
|
||||||
def test1() end
|
def test1() end
|
||||||
def test2() end
|
def test2() end
|
||||||
}
|
end
|
||||||
|
|
||||||
m.respond_to?(:test1).should == false
|
m.respond_to?(:test1).should == false
|
||||||
m.respond_to?(:test2).should == false
|
m.respond_to?(:test2).should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "functions normally if both toggle and definitions inside a module_eval" do
|
it "functions normally if both toggle and definitions inside a module_eval" do
|
||||||
m = Module.new {
|
m = Module.new do
|
||||||
module_eval {
|
module_eval do
|
||||||
module_function
|
module_function
|
||||||
def test1() end
|
def test1() end
|
||||||
def test2() end
|
def test2() end
|
||||||
}
|
end
|
||||||
}
|
end
|
||||||
|
|
||||||
m.respond_to?(:test1).should == true
|
m.respond_to?(:test1).should == true
|
||||||
m.respond_to?(:test2).should == true
|
m.respond_to?(:test2).should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "affects evaled method definitions also even when outside the eval itself" do
|
it "affects eval'ed method definitions also even when outside the eval itself" do
|
||||||
m = Module.new {
|
m = Module.new do
|
||||||
module_function
|
module_function
|
||||||
eval "def test1() end"
|
eval "def test1() end"
|
||||||
}
|
end
|
||||||
|
|
||||||
m.respond_to?(:test1).should == true
|
m.respond_to?(:test1).should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't affect definitions when inside an eval even if the definitions are outside of it" do
|
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"
|
eval "module_function"
|
||||||
def test1() end
|
def test1() end
|
||||||
}
|
end
|
||||||
|
|
||||||
m.respond_to?(:test1).should == false
|
m.respond_to?(:test1).should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "functions normally if both toggle and definitions inside a eval" do
|
it "functions normally if both toggle and definitions inside a eval" do
|
||||||
m = Module.new {
|
m = Module.new do
|
||||||
eval <<-CODE
|
eval <<-CODE
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def test1() end
|
def test1() end
|
||||||
def test2() end
|
def test2() end
|
||||||
CODE
|
CODE
|
||||||
}
|
end
|
||||||
|
|
||||||
m.respond_to?(:test1).should == true
|
m.respond_to?(:test1).should == true
|
||||||
m.respond_to?(:test2).should == true
|
m.respond_to?(:test2).should == true
|
||||||
end
|
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
|
end
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
require_relative '../../shared/queue/enque'
|
require_relative '../../shared/queue/enque'
|
||||||
require_relative '../../shared/sizedqueue/enque'
|
require_relative '../../shared/sizedqueue/enque'
|
||||||
|
require_relative '../../shared/types/rb_num2dbl_fails'
|
||||||
|
|
||||||
describe "SizedQueue#<<" do
|
describe "SizedQueue#<<" do
|
||||||
it_behaves_like :queue_enq, :<<, -> { SizedQueue.new(10) }
|
it_behaves_like :queue_enq, :<<, -> { SizedQueue.new(10) }
|
||||||
@ -9,3 +10,9 @@ end
|
|||||||
describe "SizedQueue#<<" do
|
describe "SizedQueue#<<" do
|
||||||
it_behaves_like :sizedqueue_enq, :<<, -> n { SizedQueue.new(n) }
|
it_behaves_like :sizedqueue_enq, :<<, -> n { SizedQueue.new(n) }
|
||||||
end
|
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 '../../spec_helper'
|
||||||
require_relative '../../shared/queue/enque'
|
require_relative '../../shared/queue/enque'
|
||||||
require_relative '../../shared/sizedqueue/enque'
|
require_relative '../../shared/sizedqueue/enque'
|
||||||
|
require_relative '../../shared/types/rb_num2dbl_fails'
|
||||||
|
|
||||||
describe "SizedQueue#enq" do
|
describe "SizedQueue#enq" do
|
||||||
it_behaves_like :queue_enq, :enq, -> { SizedQueue.new(10) }
|
it_behaves_like :queue_enq, :enq, -> { SizedQueue.new(10) }
|
||||||
@ -9,3 +10,9 @@ end
|
|||||||
describe "SizedQueue#enq" do
|
describe "SizedQueue#enq" do
|
||||||
it_behaves_like :sizedqueue_enq, :enq, -> n { SizedQueue.new(n) }
|
it_behaves_like :sizedqueue_enq, :enq, -> n { SizedQueue.new(n) }
|
||||||
end
|
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 '../../spec_helper'
|
||||||
require_relative '../../shared/queue/enque'
|
require_relative '../../shared/queue/enque'
|
||||||
require_relative '../../shared/sizedqueue/enque'
|
require_relative '../../shared/sizedqueue/enque'
|
||||||
|
require_relative '../../shared/types/rb_num2dbl_fails'
|
||||||
|
|
||||||
describe "SizedQueue#push" do
|
describe "SizedQueue#push" do
|
||||||
it_behaves_like :queue_enq, :push, -> { SizedQueue.new(10) }
|
it_behaves_like :queue_enq, :push, -> { SizedQueue.new(10) }
|
||||||
@ -9,3 +10,9 @@ end
|
|||||||
describe "SizedQueue#push" do
|
describe "SizedQueue#push" do
|
||||||
it_behaves_like :sizedqueue_enq, :push, -> n { SizedQueue.new(n) }
|
it_behaves_like :sizedqueue_enq, :push, -> n { SizedQueue.new(n) }
|
||||||
end
|
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"
|
encoded.encode("UTF-8").should == "ちfoofoo"
|
||||||
end
|
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
|
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 = "ち\xE3\x81\xFF".encode("UTF-16LE", invalid: :replace, replace: "foo", fallback: -> c { "bar" })
|
||||||
encoded.should == "\u3061foofoo".encode("UTF-16LE")
|
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
|
it "handles a substring in a subset encoding" do
|
||||||
'été'.index('t'.force_encoding(Encoding::US_ASCII)).should == 1
|
'été'.index('t'.force_encoding(Encoding::US_ASCII)).should == 1
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "String#index with Regexp" do
|
describe "String#index with Regexp" do
|
||||||
@ -312,6 +319,17 @@ describe "String#index with Regexp" do
|
|||||||
"われわわれ".index(/わ/, 3).should == 3
|
"われわわれ".index(/わ/, 3).should == 3
|
||||||
end
|
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
|
it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
|
||||||
re = Regexp.new "れ".encode(Encoding::EUC_JP)
|
re = Regexp.new "れ".encode(Encoding::EUC_JP)
|
||||||
-> do
|
-> do
|
||||||
|
@ -204,6 +204,13 @@ describe "String#rindex with String" do
|
|||||||
it "handles a substring in a subset encoding" do
|
it "handles a substring in a subset encoding" do
|
||||||
'été'.rindex('t'.force_encoding(Encoding::US_ASCII)).should == 1
|
'été'.rindex('t'.force_encoding(Encoding::US_ASCII)).should == 1
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "String#rindex with Regexp" do
|
describe "String#rindex with Regexp" do
|
||||||
@ -373,6 +380,6 @@ describe "String#rindex with Regexp" do
|
|||||||
re = Regexp.new "れ".encode(Encoding::EUC_JP)
|
re = Regexp.new "れ".encode(Encoding::EUC_JP)
|
||||||
-> do
|
-> do
|
||||||
"あれ".rindex re
|
"あれ".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
|
||||||
end
|
end
|
||||||
|
@ -80,6 +80,12 @@ describe "String#upto" do
|
|||||||
a.should == ["Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω"]
|
a.should == ["Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω"]
|
||||||
end
|
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
|
describe "on sequence of numbers" do
|
||||||
it "calls the block as Integer#upto" do
|
it "calls the block as Integer#upto" do
|
||||||
"8".upto("11").to_a.should == 8.upto(11).map(&:to_s)
|
"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
|
@obj.a.should == 5
|
||||||
end
|
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
|
it "works with a simple symbol on the right-hand side" do
|
||||||
@meta.class_eval do
|
@meta.class_eval do
|
||||||
alias a :value
|
alias a :value
|
||||||
@ -80,6 +89,15 @@ describe "The alias keyword" do
|
|||||||
@obj.a.should == 5
|
@obj.a.should == 5
|
||||||
end
|
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
|
it "adds the new method to the list of methods" do
|
||||||
original_methods = @obj.methods
|
original_methods = @obj.methods
|
||||||
@meta.class_eval do
|
@meta.class_eval do
|
||||||
|
@ -434,6 +434,15 @@ describe "The 'case'-construct with no target expression" do
|
|||||||
end.should == :called
|
end.should == :called
|
||||||
end
|
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.
|
# Homogeneous cases are often optimized to avoid === using a jump table, and should be tested separately.
|
||||||
# See https://github.com/jruby/jruby/issues/6440
|
# See https://github.com/jruby/jruby/issues/6440
|
||||||
it "handles homogeneous cases" do
|
it "handles homogeneous cases" do
|
||||||
|
@ -8,7 +8,8 @@ describe "Pattern matching" do
|
|||||||
ScratchPad.record []
|
ScratchPad.record []
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can be standalone assoc operator that deconstructs value" do
|
describe "can be standalone assoc operator that" do
|
||||||
|
it "deconstructs value" do
|
||||||
suppress_warning do
|
suppress_warning do
|
||||||
eval(<<-RUBY).should == [0, 1]
|
eval(<<-RUBY).should == [0, 1]
|
||||||
[0, 1] => [a, b]
|
[0, 1] => [a, b]
|
||||||
@ -17,6 +18,19 @@ describe "Pattern matching" do
|
|||||||
end
|
end
|
||||||
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
|
||||||
|
|
||||||
describe "find pattern" do
|
describe "find pattern" do
|
||||||
it "captures preceding elements to the pattern" do
|
it "captures preceding elements to the pattern" do
|
||||||
eval(<<~RUBY).should == [0, 1]
|
eval(<<~RUBY).should == [0, 1]
|
||||||
|
@ -203,6 +203,25 @@ describe "The super keyword" do
|
|||||||
-> { klass.new.a(:a_called) }.should raise_error(RuntimeError)
|
-> { klass.new.a(:a_called) }.should raise_error(RuntimeError)
|
||||||
end
|
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
|
# Rubinius ticket github#157
|
||||||
it "calls method_missing when a superclass method is not found" do
|
it "calls method_missing when a superclass method is not found" do
|
||||||
SuperSpecs::MM_B.new.is_a?(Hash).should == false
|
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)
|
-> { @obj.meth(5) }.should raise_error(NoMethodError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "with a interpolated symbol" do
|
it "with an interpolated symbol" do
|
||||||
@undef_class.class_eval do
|
@undef_class.class_eval do
|
||||||
undef :"#{'meth'}"
|
undef :"#{'meth'}"
|
||||||
end
|
end
|
||||||
-> { @obj.meth(5) }.should raise_error(NoMethodError)
|
-> { @obj.meth(5) }.should raise_error(NoMethodError)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
it "allows undefining multiple methods at a time" do
|
it "allows undefining multiple methods at a time" do
|
||||||
|
@ -54,7 +54,7 @@ describe "BigDecimal#remainder" do
|
|||||||
@nan.remainder(@infinity).should.nan?
|
@nan.remainder(@infinity).should.nan?
|
||||||
end
|
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
|
it "returns NaN if Infinity is involved" do
|
||||||
@infinity.remainder(@infinity).should.nan?
|
@infinity.remainder(@infinity).should.nan?
|
||||||
@infinity.remainder(@one).should.nan?
|
@infinity.remainder(@one).should.nan?
|
||||||
|
@ -228,13 +228,13 @@ describe "BigDecimal#round" do
|
|||||||
-> { BigDecimal('-Infinity').round(2) }.should_not raise_error(FloatDomainError)
|
-> { BigDecimal('-Infinity').round(2) }.should_not raise_error(FloatDomainError)
|
||||||
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
|
it 'raise for a non-existent round mode' do
|
||||||
-> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode")
|
-> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode")
|
||||||
end
|
end
|
||||||
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
|
it 'raise for a non-existent round mode' do
|
||||||
-> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode (nonsense)")
|
-> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode (nonsense)")
|
||||||
end
|
end
|
||||||
|
@ -40,14 +40,13 @@ describe "BigDecimal#to_s" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
ruby_version_is ""..."3.3" do
|
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 =\
|
re =\
|
||||||
/\A0\.314 159 265 358 979 323 846 264 338 327 950 288 419 716 939 937E1\z/i
|
/\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
|
@bigdec.to_s(3).should =~ re
|
||||||
|
|
||||||
str1 = '-123.45678 90123 45678 9'
|
str1 = '-123.45678 90123 45678 9'
|
||||||
BigDecimal("-123.45678901234567890").to_s('5F').should == str1
|
BigDecimal("-123.45678901234567890").to_s('5F').should == str1
|
||||||
BigDecimal('1000010').to_s('5F').should == "10000 10.0"
|
|
||||||
# trailing zeroes removed
|
# trailing zeroes removed
|
||||||
BigDecimal("1.00000000000").to_s('1F').should == "1.0"
|
BigDecimal("1.00000000000").to_s('1F').should == "1.0"
|
||||||
# 0 is treated as no spaces
|
# 0 is treated as no spaces
|
||||||
@ -55,6 +54,12 @@ describe "BigDecimal#to_s" do
|
|||||||
end
|
end
|
||||||
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
|
it "can return a leading space for values > 0" do
|
||||||
@bigdec.to_s(" F").should =~ /\ .*/
|
@bigdec.to_s(" F").should =~ /\ .*/
|
||||||
@bigneg.to_s(" F").should_not =~ /\ .*/
|
@bigneg.to_s(" F").should_not =~ /\ .*/
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
require 'date'
|
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
|
describe "Date#deconstruct_keys" do
|
||||||
it "returns whole hash for nil as an argument" do
|
it "returns whole hash for nil as an argument" do
|
||||||
d = Date.new(2022, 10, 5)
|
d = Date.new(2022, 10, 5)
|
||||||
|
@ -23,14 +23,14 @@ describe "Date#strftime" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
# %v is %e-%b-%Y for Date/DateTime
|
# %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
|
it "should be able to show the commercial week" do
|
||||||
@date.strftime("%v").should == " 9-Apr-2000"
|
@date.strftime("%v").should == " 9-Apr-2000"
|
||||||
@date.strftime("%v").should == @date.strftime('%e-%b-%Y')
|
@date.strftime("%v").should == @date.strftime('%e-%b-%Y')
|
||||||
end
|
end
|
||||||
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
|
it "should be able to show the commercial week" do
|
||||||
@date.strftime("%v").should == " 9-APR-2000"
|
@date.strftime("%v").should == " 9-APR-2000"
|
||||||
@date.strftime("%v").should != @date.strftime('%e-%b-%Y')
|
@date.strftime("%v").should != @date.strftime('%e-%b-%Y')
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
require 'date'
|
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
|
describe "DateTime#deconstruct_keys" do
|
||||||
it "returns whole hash for nil as an argument" do
|
it "returns whole hash for nil as an argument" do
|
||||||
d = DateTime.new(2022, 10, 5, 13, 30)
|
d = DateTime.new(2022, 10, 5, 13, 30)
|
||||||
|
@ -33,14 +33,14 @@ describe "DateTime#strftime" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
# %v is %e-%b-%Y for Date/DateTime
|
# %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
|
it "should be able to show the commercial week" do
|
||||||
@time.strftime("%v").should == " 3-Feb-2001"
|
@time.strftime("%v").should == " 3-Feb-2001"
|
||||||
@time.strftime("%v").should == @time.strftime('%e-%b-%Y')
|
@time.strftime("%v").should == @time.strftime('%e-%b-%Y')
|
||||||
end
|
end
|
||||||
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
|
it "should be able to show the commercial week" do
|
||||||
@time.strftime("%v").should == " 3-FEB-2001"
|
@time.strftime("%v").should == " 3-FEB-2001"
|
||||||
@time.strftime("%v").should != @time.strftime('%e-%b-%Y')
|
@time.strftime("%v").should != @time.strftime('%e-%b-%Y')
|
||||||
|
@ -18,8 +18,7 @@ describe "DateTime#to_time" do
|
|||||||
time.sec.should == 59
|
time.sec.should == 59
|
||||||
end
|
end
|
||||||
|
|
||||||
date_version = defined?(Date::VERSION) ? Date::VERSION : '0.0.0'
|
version_is(Date::VERSION, '3.2.3') do #ruby_version_is "3.2" do
|
||||||
version_is(date_version, '3.2.3') do
|
|
||||||
it "returns a Time representing the same instant before Gregorian" do
|
it "returns a Time representing the same instant before Gregorian" do
|
||||||
datetime = DateTime.civil(1582, 10, 4, 23, 58, 59)
|
datetime = DateTime.civil(1582, 10, 4, 23, 58, 59)
|
||||||
time = datetime.to_time.utc
|
time = datetime.to_time.utc
|
||||||
|
@ -140,7 +140,7 @@ END
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "warning about arguments" do
|
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
|
it "warns when passed safe_level and later arguments" do
|
||||||
-> {
|
-> {
|
||||||
ERB.new(@eruby_str, nil, '%')
|
ERB.new(@eruby_str, nil, '%')
|
||||||
|
@ -77,7 +77,13 @@ describe "IPAddr#new" do
|
|||||||
a.family.should == Socket::AF_INET6
|
a.family.should == Socket::AF_INET6
|
||||||
end
|
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
|
it "raises on incorrect IPAddr strings" do
|
||||||
[
|
[
|
||||||
["fe80::1%fxp0"],
|
["fe80::1%fxp0"],
|
||||||
@ -93,7 +99,7 @@ describe "IPAddr#new" do
|
|||||||
end
|
end
|
||||||
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
|
it "raises on incorrect IPAddr strings" do
|
||||||
[
|
[
|
||||||
["::1/255.255.255.0"],
|
["::1/255.255.255.0"],
|
||||||
|
@ -15,17 +15,8 @@ describe "Logger::LogDevice#close" do
|
|||||||
rm_r @file_path
|
rm_r @file_path
|
||||||
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 writing failed\./)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
version_is Logger::VERSION, "1.4.0" do
|
|
||||||
it "closes the LogDevice's stream" do
|
it "closes the LogDevice's stream" do
|
||||||
@device.close
|
@device.close
|
||||||
-> { @device.write("Test") }.should complain(/\Alog shifting failed\./)
|
-> { @device.write("Test") }.should complain(/\Alog shifting failed\./)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
@ -35,17 +35,8 @@ describe "Logger::LogDevice#write" do
|
|||||||
rm_r path
|
rm_r path
|
||||||
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 writing failed\./)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
version_is Logger::VERSION, "1.4.0" do
|
|
||||||
it "fails if the device is already closed" do
|
it "fails if the device is already closed" do
|
||||||
@device.close
|
@device.close
|
||||||
-> { @device.write "foo" }.should complain(/\Alog shifting failed\./)
|
-> { @device.write "foo" }.should complain(/\Alog shifting failed\./)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
@ -14,11 +14,9 @@ ruby_version_is ""..."3.1" do
|
|||||||
Matrix[[0, Complex(0, 1)], [Complex(0, 1), 0]].should.unitary?
|
Matrix[[0, Complex(0, 1)], [Complex(0, 1), 0]].should.unitary?
|
||||||
end
|
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
|
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?
|
Matrix[[0, Complex(0, 1)], [Complex(0, -1), 0]].should.unitary?
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "raises an error for rectangular matrices" do
|
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
|
io.string.encoding.should == Encoding::EUC_JP
|
||||||
end
|
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
|
it "the #external_encoding to the encoding of the String when passed a String" do
|
||||||
s = ''.force_encoding(Encoding::EUC_JP)
|
s = ''.force_encoding(Encoding::EUC_JP)
|
||||||
io = StringIO.new(s)
|
io = StringIO.new(s)
|
||||||
io.external_encoding.should == Encoding::EUC_JP
|
io.external_encoding.should == Encoding::EUC_JP
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
@ -36,7 +36,7 @@ describe :stringio_each_separator, shared: true do
|
|||||||
seen.should == ["2 1 2 1 2"]
|
seen.should == ["2 1 2 1 2"]
|
||||||
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 two separation characters when passed an empty String as separator" do
|
it "yields each paragraph with two separation characters when passed an empty String as separator" do
|
||||||
seen = []
|
seen = []
|
||||||
io = StringIO.new("para1\n\npara2\n\n\npara3")
|
io = StringIO.new("para1\n\npara2\n\n\npara3")
|
||||||
@ -45,7 +45,7 @@ describe :stringio_each_separator, shared: true do
|
|||||||
end
|
end
|
||||||
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
|
it "yields each paragraph with all separation characters when passed an empty String as separator" do
|
||||||
seen = []
|
seen = []
|
||||||
io = StringIO.new("para1\n\npara2\n\n\npara3")
|
io = StringIO.new("para1\n\npara2\n\n\npara3")
|
||||||
|
@ -13,8 +13,7 @@ describe "Time#to_datetime" do
|
|||||||
datetime.sec.should == 59
|
datetime.sec.should == 59
|
||||||
end
|
end
|
||||||
|
|
||||||
date_version = defined?(Date::VERSION) ? Date::VERSION : '0.0.0'
|
version_is(Date::VERSION, '3.2.3') do #ruby_version_is '3.2' do
|
||||||
version_is(date_version, '3.2.3') do
|
|
||||||
it "returns a DateTime representing the same instant before Gregorian" do
|
it "returns a DateTime representing the same instant before Gregorian" do
|
||||||
time = Time.utc(1582, 10, 14, 23, 58, 59)
|
time = Time.utc(1582, 10, 14, 23, 58, 59)
|
||||||
datetime = time.to_datetime
|
datetime = time.to_datetime
|
||||||
|
@ -2,7 +2,7 @@ require_relative '../../../spec_helper'
|
|||||||
require 'uri'
|
require 'uri'
|
||||||
|
|
||||||
describe "URI::Generic#host" do
|
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
|
# https://hackerone.com/reports/156615
|
||||||
it "returns empty string when host is empty" do
|
it "returns empty string when host is empty" do
|
||||||
URI.parse('http:////foo.com').host.should == ''
|
URI.parse('http:////foo.com').host.should == ''
|
||||||
|
@ -2,7 +2,7 @@ require_relative '../../../spec_helper'
|
|||||||
require 'uri'
|
require 'uri'
|
||||||
|
|
||||||
describe "URI::Generic#to_s" do
|
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
|
# https://hackerone.com/reports/156615
|
||||||
it "preserves / characters when host is empty" do
|
it "preserves / characters when host is empty" do
|
||||||
URI('http:///foo.com').to_s.should == 'http:///foo.com'
|
URI('http:///foo.com').to_s.should == 'http:///foo.com'
|
||||||
|
@ -100,6 +100,40 @@ describe "C-API Exception function" do
|
|||||||
end
|
end
|
||||||
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
|
describe "rb_make_exception" do
|
||||||
it "returns a RuntimeError when given a String argument" do
|
it "returns a RuntimeError when given a String argument" do
|
||||||
e = @s.rb_make_exception(["Message"])
|
e = @s.rb_make_exception(["Message"])
|
||||||
|
@ -36,6 +36,21 @@ VALUE exception_spec_rb_set_errinfo(VALUE self, VALUE exc) {
|
|||||||
return Qnil;
|
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) {
|
VALUE exception_spec_rb_make_exception(VALUE self, VALUE ary) {
|
||||||
int argc = RARRAY_LENINT(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_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_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_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);
|
rb_define_method(cls, "rb_make_exception", exception_spec_rb_make_exception, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +105,12 @@ VALUE hash_spec_rb_hash_new(VALUE self) {
|
|||||||
return rb_hash_new();
|
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 rb_ident_hash_new(void); /* internal.h, used in ripper */
|
||||||
|
|
||||||
VALUE hash_spec_rb_ident_hash_new(VALUE self) {
|
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", 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_lookup2_default_undef", hash_spec_rb_hash_lookup2_default_undef, 2);
|
||||||
rb_define_method(cls, "rb_hash_new", hash_spec_rb_hash_new, 0);
|
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_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_size", hash_spec_rb_hash_size, 1);
|
||||||
rb_define_method(cls, "rb_hash_set_ifnone", hash_spec_rb_hash_set_ifnone, 2);
|
rb_define_method(cls, "rb_hash_set_ifnone", hash_spec_rb_hash_set_ifnone, 2);
|
||||||
|
@ -6,8 +6,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static VALUE integer_spec_rb_integer_pack(VALUE self, VALUE value,
|
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),
|
int result = rb_integer_pack(value, (void*)RSTRING_PTR(words), FIX2INT(numwords),
|
||||||
FIX2INT(wordsize), FIX2INT(nails), FIX2INT(flags));
|
FIX2INT(wordsize), FIX2INT(nails), FIX2INT(flags));
|
||||||
return INT2FIX(result);
|
return INT2FIX(result);
|
||||||
|
@ -139,8 +139,7 @@ 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 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* from_enc;
|
||||||
rb_encoding* to_enc;
|
rb_encoding* to_enc;
|
||||||
|
|
||||||
|
@ -15,13 +15,11 @@ static VALUE struct_spec_rb_struct_getmember(VALUE self, VALUE st, VALUE key) {
|
|||||||
return rb_struct_getmember(st, SYM2ID(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));
|
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));
|
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,
|
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);
|
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);
|
return rb_struct_size(st);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,22 @@ describe "C-API Hash function" do
|
|||||||
end
|
end
|
||||||
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
|
describe "rb_ident_hash_new" do
|
||||||
it "returns a new compare by identity hash" do
|
it "returns a new compare by identity hash" do
|
||||||
result = @s.rb_ident_hash_new
|
result = @s.rb_ident_hash_new
|
||||||
|
@ -37,7 +37,7 @@ describe :sizedqueue_enq, shared: true do
|
|||||||
q << 1
|
q << 1
|
||||||
|
|
||||||
t = Thread.new {
|
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
|
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",
|
"can't set a timeout if non_block is enabled",
|
||||||
)
|
)
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user