mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@902ab83
This commit is contained in:
parent
bb5f710887
commit
e0c5488ff9
56 changed files with 531 additions and 137 deletions
|
@ -94,6 +94,7 @@ module DirSpecs
|
|||
special/こんにちは.txt
|
||||
special/\a
|
||||
]
|
||||
@mock_dir_files << "special/_\u{1f60e}.erb"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -39,5 +39,38 @@ describe "Dir#read" do
|
|||
entries.sort.should == DirSpecs.expected_paths
|
||||
end
|
||||
|
||||
platform_is_not :windows do
|
||||
it "returns all directory entries even when encoding conversion will fail" do
|
||||
dir = Dir.open(File.join(DirSpecs.mock_dir, 'special'))
|
||||
utf8_entries = []
|
||||
begin
|
||||
while entry = dir.read
|
||||
utf8_entries << entry
|
||||
end
|
||||
ensure
|
||||
dir.close
|
||||
end
|
||||
old_internal_encoding = Encoding::default_internal
|
||||
old_external_encoding = Encoding::default_external
|
||||
Encoding.default_internal = Encoding::UTF_8
|
||||
Encoding.default_external = Encoding::SHIFT_JIS
|
||||
dir = Dir.open(File.join(DirSpecs.mock_dir, 'special'))
|
||||
shift_jis_entries = []
|
||||
begin
|
||||
-> {
|
||||
while entry = dir.read
|
||||
shift_jis_entries << entry
|
||||
end
|
||||
}.should_not raise_error
|
||||
ensure
|
||||
dir.close
|
||||
Encoding.default_internal = old_internal_encoding
|
||||
Encoding.default_external = old_external_encoding
|
||||
end
|
||||
shift_jis_entries.size.should == utf8_entries.size
|
||||
shift_jis_entries.filter { |f| f.encoding == Encoding::SHIFT_JIS }.size.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like :dir_closed, :read
|
||||
end
|
||||
|
|
|
@ -131,7 +131,6 @@ describe "Enumerable#all?" do
|
|||
pattern.yielded.should == [[0], [1], [2], [-1]]
|
||||
end
|
||||
|
||||
# may raise an exception in future versions
|
||||
it "always returns true on empty enumeration" do
|
||||
@empty.all?(Integer).should == true
|
||||
[].all?(Integer).should == true
|
||||
|
|
|
@ -145,7 +145,6 @@ describe "Enumerable#any?" do
|
|||
pattern.yielded.should == [[0], [1], [2]]
|
||||
end
|
||||
|
||||
# may raise an exception in future versions
|
||||
it "always returns false on empty enumeration" do
|
||||
@empty.any?(Integer).should == false
|
||||
[].any?(Integer).should == false
|
||||
|
|
|
@ -100,7 +100,6 @@ describe "Enumerable#none?" do
|
|||
pattern.yielded.should == [[0], [1], [2], [-1]]
|
||||
end
|
||||
|
||||
# may raise an exception in future versions
|
||||
it "always returns true on empty enumeration" do
|
||||
@empty.none?(Integer).should == true
|
||||
[].none?(Integer).should == true
|
||||
|
|
|
@ -91,7 +91,6 @@ describe "Enumerable#one?" do
|
|||
pattern.yielded.should == [[0], [1], [2], [-1]]
|
||||
end
|
||||
|
||||
# may raise an exception in future versions
|
||||
it "always returns false on empty enumeration" do
|
||||
@empty.one?(Integer).should == false
|
||||
[].one?(Integer).should == false
|
||||
|
|
|
@ -9,10 +9,10 @@ describe "Float#coerce" do
|
|||
1.0.coerce(3.14).should == [3.14, 1.0]
|
||||
|
||||
a, b = -0.0.coerce(bignum_value)
|
||||
a.should be_close(9223372036854775808.0, TOLERANCE)
|
||||
a.should be_close(18446744073709551616.0, TOLERANCE)
|
||||
b.should be_close(-0.0, TOLERANCE)
|
||||
a, b = 1.0.coerce(bignum_value)
|
||||
a.should be_close(9223372036854775808.0, TOLERANCE)
|
||||
a.should be_close(18446744073709551616.0, TOLERANCE)
|
||||
b.should be_close(1.0, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ describe "Float#divmod" do
|
|||
values[1].should be_close(2.8284, TOLERANCE)
|
||||
values = -1.0.divmod(bignum_value)
|
||||
values[0].should eql(-1)
|
||||
values[1].should be_close(9223372036854775808.000, TOLERANCE)
|
||||
values[1].should be_close(18446744073709551616.0, TOLERANCE)
|
||||
values = -1.0.divmod(1)
|
||||
values[0].should eql(-1)
|
||||
values[1].should eql(0.0)
|
||||
|
|
|
@ -6,7 +6,7 @@ describe "Float#-" do
|
|||
|
||||
it "returns self minus other" do
|
||||
(9_237_212.5280 - 5_280).should be_close(9231932.528, TOLERANCE)
|
||||
(2_560_496.1691 - bignum_value).should be_close(-9223372036852215808.000, TOLERANCE)
|
||||
(2_560_496.1691 - bignum_value).should be_close(-18446744073706991616.0, TOLERANCE)
|
||||
(5.5 - 5.5).should be_close(0.0,TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ describe "Float#*" do
|
|||
it "returns self multiplied by other" do
|
||||
(4923.98221 * 2).should be_close(9847.96442, TOLERANCE)
|
||||
(6712.5 * 0.25).should be_close(1678.125, TOLERANCE)
|
||||
(256.4096 * bignum_value).should be_close(2364961134621118431232.000, TOLERANCE)
|
||||
(256.4096 * bignum_value).should be_close(4729922269242236862464.0, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises a TypeError when given a non-Numeric" do
|
||||
|
|
|
@ -6,7 +6,7 @@ describe "Float#+" do
|
|||
|
||||
it "returns self plus other" do
|
||||
(491.213 + 2).should be_close(493.213, TOLERANCE)
|
||||
(9.99 + bignum_value).should be_close(9223372036854775808.000, TOLERANCE)
|
||||
(9.99 + bignum_value).should be_close(18446744073709551616.0, TOLERANCE)
|
||||
(1001.99 + 5.219).should be_close(1007.209, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -73,7 +73,6 @@ describe "Hash#transform_keys!" do
|
|||
@hash.should == { 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4 }
|
||||
end
|
||||
|
||||
# https://bugs.ruby-lang.org/issues/14380
|
||||
it "prevents conflicts between new keys and old ones" do
|
||||
@hash.transform_keys!(&:succ)
|
||||
@hash.should == { b: 1, c: 2, d: 3, e: 4 }
|
||||
|
|
|
@ -55,24 +55,24 @@ describe "Integer#&" do
|
|||
@bignum = bignum_value(5)
|
||||
(@bignum & 3).should == 1
|
||||
(@bignum & 52).should == 4
|
||||
(@bignum & bignum_value(9921)).should == 9223372036854775809
|
||||
(@bignum & bignum_value(9921)).should == 18446744073709551617
|
||||
|
||||
((2*bignum_value) & 1).should == 0
|
||||
((2*bignum_value) & (2*bignum_value)).should == 18446744073709551616
|
||||
((2*bignum_value) & (2*bignum_value)).should == 36893488147419103232
|
||||
end
|
||||
|
||||
it "returns self bitwise AND other when one operand is negative" do
|
||||
((2*bignum_value) & -1).should == (2*bignum_value)
|
||||
((4*bignum_value) & -1).should == (4*bignum_value)
|
||||
(@bignum & -0xffffffffffffff5).should == 9223372036854775809
|
||||
(@bignum & -0xffffffffffffff5).should == 18446744073709551617
|
||||
(@bignum & -@bignum).should == 1
|
||||
(@bignum & -0x8000000000000000).should == 9223372036854775808
|
||||
(@bignum & -0x8000000000000000).should == 18446744073709551616
|
||||
end
|
||||
|
||||
it "returns self bitwise AND other when both operands are negative" do
|
||||
(-@bignum & -0x4000000000000005).should == -13835058055282163717
|
||||
(-@bignum & -@bignum).should == -9223372036854775813
|
||||
(-@bignum & -0x4000000000000000).should == -13835058055282163712
|
||||
(-@bignum & -0x4000000000000005).should == -23058430092136939525
|
||||
(-@bignum & -@bignum).should == -18446744073709551621
|
||||
(-@bignum & -0x4000000000000000).should == -23058430092136939520
|
||||
end
|
||||
|
||||
it "returns self bitwise AND other when both are negative and a multiple in bitsize of Fixnum::MIN" do
|
||||
|
|
|
@ -7,13 +7,34 @@ describe "Integer#|" do
|
|||
(5 | 4).should == 5
|
||||
(5 | 6).should == 7
|
||||
(248 | 4096).should == 4344
|
||||
(0xffff | bignum_value + 0xf0f0).should == 0x8000_0000_0000_ffff
|
||||
(0xffff | bignum_value + 0xf0f0).should == 0x1_0000_0000_0000_ffff
|
||||
end
|
||||
|
||||
it "returns self bitwise OR other when one operand is negative" do
|
||||
((1 << 33) | -1).should == -1
|
||||
(-1 | (1 << 33)).should == -1
|
||||
|
||||
((-(1<<33)-1) | 5).should == -8589934593
|
||||
(5 | (-(1<<33)-1)).should == -8589934593
|
||||
end
|
||||
|
||||
it "returns self bitwise OR other when both operands are negative" do
|
||||
(-5 | -1).should == -1
|
||||
(-3 | -4).should == -3
|
||||
(-12 | -13).should == -9
|
||||
(-13 | -12).should == -9
|
||||
end
|
||||
|
||||
it "returns self bitwise OR a bignum" do
|
||||
(-1 | 2**64).should == -1
|
||||
end
|
||||
|
||||
it "coerces the rhs and calls #coerce" do
|
||||
obj = mock("fixnum bit and")
|
||||
obj.should_receive(:coerce).with(6).and_return([3, 6])
|
||||
(6 & obj).should == 2
|
||||
end
|
||||
|
||||
it "raises a TypeError when passed a Float" do
|
||||
-> { (3 | 3.4) }.should raise_error(TypeError)
|
||||
end
|
||||
|
@ -32,20 +53,20 @@ describe "Integer#|" do
|
|||
end
|
||||
|
||||
it "returns self bitwise OR other" do
|
||||
(@bignum | 2).should == 9223372036854775819
|
||||
(@bignum | 9).should == 9223372036854775819
|
||||
(@bignum | bignum_value).should == 9223372036854775819
|
||||
(@bignum | 2).should == 18446744073709551627
|
||||
(@bignum | 9).should == 18446744073709551627
|
||||
(@bignum | bignum_value).should == 18446744073709551627
|
||||
end
|
||||
|
||||
it "returns self bitwise OR other when one operand is negative" do
|
||||
(@bignum | -0x40000000000000000).should == -64563604257983430645
|
||||
(@bignum | -0x40000000000000000).should == -55340232221128654837
|
||||
(@bignum | -@bignum).should == -1
|
||||
(@bignum | -0x8000000000000000).should == -9223372036854775797
|
||||
end
|
||||
|
||||
it "returns self bitwise OR other when both operands are negative" do
|
||||
(-@bignum | -0x4000000000000005).should == -1
|
||||
(-@bignum | -@bignum).should == -9223372036854775819
|
||||
(-@bignum | -@bignum).should == -18446744073709551627
|
||||
(-@bignum | -0x4000000000000000).should == -11
|
||||
end
|
||||
|
||||
|
|
|
@ -5,13 +5,34 @@ describe "Integer#^" do
|
|||
it "returns self bitwise EXCLUSIVE OR other" do
|
||||
(3 ^ 5).should == 6
|
||||
(-2 ^ -255).should == 255
|
||||
(5 ^ bignum_value + 0xffff_ffff).should == 0x8000_0000_ffff_fffa
|
||||
(5 ^ bignum_value + 0xffff_ffff).should == 0x1_0000_0000_ffff_fffa
|
||||
end
|
||||
|
||||
it "returns self bitwise XOR other when one operand is negative" do
|
||||
((1 << 33) ^ -1).should == -8589934593
|
||||
(-1 ^ (1 << 33)).should == -8589934593
|
||||
|
||||
((-(1<<33)-1) ^ 5).should == -8589934598
|
||||
(5 ^ (-(1<<33)-1)).should == -8589934598
|
||||
end
|
||||
|
||||
it "returns self bitwise XOR other when both operands are negative" do
|
||||
(-5 ^ -1).should == 4
|
||||
(-3 ^ -4).should == 1
|
||||
(-12 ^ -13).should == 7
|
||||
(-13 ^ -12).should == 7
|
||||
end
|
||||
|
||||
it "returns self bitwise EXCLUSIVE OR a bignum" do
|
||||
(-1 ^ 2**64).should == -18446744073709551617
|
||||
end
|
||||
|
||||
it "coerces the rhs and calls #coerce" do
|
||||
obj = mock("fixnum bit and")
|
||||
obj.should_receive(:coerce).with(6).and_return([3, 6])
|
||||
(6 ^ obj).should == 5
|
||||
end
|
||||
|
||||
it "raises a TypeError when passed a Float" do
|
||||
-> { (3 ^ 3.4) }.should raise_error(TypeError)
|
||||
end
|
||||
|
@ -30,21 +51,21 @@ describe "Integer#^" do
|
|||
end
|
||||
|
||||
it "returns self bitwise EXCLUSIVE OR other" do
|
||||
(@bignum ^ 2).should == 9223372036854775824
|
||||
(@bignum ^ 2).should == 18446744073709551632
|
||||
(@bignum ^ @bignum).should == 0
|
||||
(@bignum ^ 14).should == 9223372036854775836
|
||||
(@bignum ^ 14).should == 18446744073709551644
|
||||
end
|
||||
|
||||
it "returns self bitwise EXCLUSIVE OR other when one operand is negative" do
|
||||
(@bignum ^ -0x40000000000000000).should == -64563604257983430638
|
||||
(@bignum ^ -0x40000000000000000).should == -55340232221128654830
|
||||
(@bignum ^ -@bignum).should == -4
|
||||
(@bignum ^ -0x8000000000000000).should == -18446744073709551598
|
||||
(@bignum ^ -0x8000000000000000).should == -27670116110564327406
|
||||
end
|
||||
|
||||
it "returns self bitwise EXCLUSIVE OR other when both operands are negative" do
|
||||
(-@bignum ^ -0x40000000000000000).should == 64563604257983430638
|
||||
(-@bignum ^ -0x40000000000000000).should == 55340232221128654830
|
||||
(-@bignum ^ -@bignum).should == 0
|
||||
(-@bignum ^ -0x4000000000000000).should == 13835058055282163694
|
||||
(-@bignum ^ -0x4000000000000000).should == 23058430092136939502
|
||||
end
|
||||
|
||||
it "returns self bitwise EXCLUSIVE OR other when all bits are 1 and other value is negative" do
|
||||
|
|
|
@ -11,7 +11,11 @@ describe "Integer#chr without argument" do
|
|||
|
||||
it "raises a RangeError is self is less than 0" do
|
||||
-> { -1.chr }.should raise_error(RangeError)
|
||||
-> { -bignum_value.chr }.should raise_error(RangeError)
|
||||
-> { (-bignum_value).chr }.should raise_error(RangeError)
|
||||
end
|
||||
|
||||
it "raises a RangeError if self is too large" do
|
||||
-> { 2206368128.chr(Encoding::UTF_8) }.should raise_error(RangeError)
|
||||
end
|
||||
|
||||
describe "when Encoding.default_internal is nil" do
|
||||
|
@ -162,7 +166,7 @@ describe "Integer#chr with an encoding argument" do
|
|||
# http://redmine.ruby-lang.org/issues/4869
|
||||
it "raises a RangeError is self is less than 0" do
|
||||
-> { -1.chr(Encoding::UTF_8) }.should raise_error(RangeError)
|
||||
-> { -bignum_value.chr(Encoding::EUC_JP) }.should raise_error(RangeError)
|
||||
-> { (-bignum_value).chr(Encoding::EUC_JP) }.should raise_error(RangeError)
|
||||
end
|
||||
|
||||
it "raises a RangeError if self is too large" do
|
||||
|
|
|
@ -12,9 +12,9 @@ describe "Integer#~" do
|
|||
|
||||
context "bignum" do
|
||||
it "returns self with each bit flipped" do
|
||||
(~bignum_value(48)).should == -9223372036854775857
|
||||
(~(-bignum_value(21))).should == 9223372036854775828
|
||||
(~bignum_value(1)).should == -9223372036854775810
|
||||
(~bignum_value(48)).should == -18446744073709551665
|
||||
(~(-bignum_value(21))).should == 18446744073709551636
|
||||
(~bignum_value(1)).should == -18446744073709551618
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -70,8 +70,8 @@ describe "Integer#div" do
|
|||
end
|
||||
|
||||
it "returns self divided by other" do
|
||||
@bignum.div(4).should == 2305843009213693974
|
||||
@bignum.div(Rational(4, 1)).should == 2305843009213693974
|
||||
@bignum.div(4).should == 4611686018427387926
|
||||
@bignum.div(Rational(4, 1)).should == 4611686018427387926
|
||||
@bignum.div(bignum_value(2)).should == 1
|
||||
|
||||
(-(10**50)).div(-(10**40 + 1)).should == 9999999999
|
||||
|
@ -124,11 +124,11 @@ describe "Integer#div" do
|
|||
end
|
||||
|
||||
it "returns a result of integer division of self by a float argument" do
|
||||
@bignum.div(4294967295.5).should eql(2147483648)
|
||||
@bignum.div(4294967295.5).should eql(4294967296)
|
||||
not_supported_on :opal do
|
||||
@bignum.div(4294967295.0).should eql(2147483648)
|
||||
@bignum.div(4294967295.0).should eql(4294967297)
|
||||
@bignum.div(bignum_value(88).to_f).should eql(1)
|
||||
@bignum.div(-bignum_value(88).to_f).should eql(-1)
|
||||
@bignum.div((-bignum_value(88)).to_f).should eql(-1)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ describe "Integer#/" do
|
|||
end
|
||||
|
||||
it "returns self divided by other" do
|
||||
(@bignum / 4).should == 2305843009213693974
|
||||
(@bignum / 4).should == 4611686018427387926
|
||||
|
||||
(@bignum / bignum_value(2)).should == 1
|
||||
|
||||
|
@ -60,15 +60,15 @@ describe "Integer#/" do
|
|||
|
||||
it "returns self divided by Float" do
|
||||
not_supported_on :opal do
|
||||
(bignum_value(88) / 4294967295.0).should be_close(2147483648.5, TOLERANCE)
|
||||
(bignum_value(88) / 4294967295.0).should be_close(4294967297.0, TOLERANCE)
|
||||
end
|
||||
(bignum_value(88) / 4294967295.5).should be_close(2147483648.25, TOLERANCE)
|
||||
(bignum_value(88) / 4294967295.5).should be_close(4294967296.5, TOLERANCE)
|
||||
end
|
||||
|
||||
it "returns result the same class as the argument" do
|
||||
(@bignum / 4).should == 2305843009213693974
|
||||
(@bignum / 4.0).should be_close(2305843009213693974, TOLERANCE)
|
||||
(@bignum / Rational(4, 1)).should == Rational(2305843009213693974, 1)
|
||||
(@bignum / 4).should == 4611686018427387926
|
||||
(@bignum / 4.0).should be_close(4611686018427387926, TOLERANCE)
|
||||
(@bignum / Rational(4, 1)).should == Rational(4611686018427387926, 1)
|
||||
end
|
||||
|
||||
it "does NOT raise ZeroDivisionError if other is zero and is a Float" do
|
||||
|
|
|
@ -46,16 +46,16 @@ describe "Integer#divmod" do
|
|||
# assert(0 < b ? (0 <= r && r < b) : (b < r && r <= 0))
|
||||
# So, r is always between 0 and b.
|
||||
it "returns an Array containing quotient and modulus obtained from dividing self by the given argument" do
|
||||
@bignum.divmod(4).should == [2305843009213693965, 3]
|
||||
@bignum.divmod(13).should == [709490156681136604, 11]
|
||||
@bignum.divmod(4).should == [4611686018427387917, 3]
|
||||
@bignum.divmod(13).should == [1418980313362273205, 6]
|
||||
|
||||
@bignum.divmod(4.5).should == [2049638230412172288, 3.5]
|
||||
@bignum.divmod(4.5).should == [4099276460824344576, 2.5]
|
||||
|
||||
not_supported_on :opal do
|
||||
@bignum.divmod(4.0).should == [2305843009213693952, 0.0]
|
||||
@bignum.divmod(13.0).should == [709490156681136640, 8.0]
|
||||
@bignum.divmod(4.0).should == [4611686018427387904, 0.0]
|
||||
@bignum.divmod(13.0).should == [1418980313362273280, 3.0]
|
||||
|
||||
@bignum.divmod(2.0).should == [4611686018427387904, 0.0]
|
||||
@bignum.divmod(2.0).should == [9223372036854775808, 0.0]
|
||||
end
|
||||
|
||||
@bignum.divmod(bignum_value).should == [1, 55]
|
||||
|
|
|
@ -96,7 +96,7 @@ describe "Integer#<< (with n << m)" do
|
|||
|
||||
context "bignum" do
|
||||
before :each do
|
||||
@bignum = bignum_value * 16
|
||||
@bignum = bignum_value * 8 # 2 ** 67
|
||||
end
|
||||
|
||||
it "returns n shifted left m bits when n > 0, m > 0" do
|
||||
|
@ -127,10 +127,6 @@ describe "Integer#<< (with n << m)" do
|
|||
(@bignum << -68).should == 0
|
||||
end
|
||||
|
||||
it "returns 0 when m < 0 and m is a Bignum" do
|
||||
(@bignum << -bignum_value).should == 0
|
||||
end
|
||||
|
||||
it "returns a Fixnum == fixnum_max when (fixnum_max * 2) << -1 and n > 0" do
|
||||
result = (fixnum_max * 2) << -1
|
||||
result.should be_an_instance_of(Integer)
|
||||
|
@ -165,4 +161,51 @@ describe "Integer#<< (with n << m)" do
|
|||
-> { @bignum << "4" }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
context "when m is a bignum or larger than int" do
|
||||
it "returns -1 when m < 0 and n < 0" do
|
||||
(-1 << -bignum_value).should == -1
|
||||
(-1 << -(2**40)).should == -1
|
||||
|
||||
(-bignum_value << -bignum_value).should == -1
|
||||
(-bignum_value << -(2**40)).should == -1
|
||||
end
|
||||
|
||||
it "returns 0 when m < 0 and n >= 0" do
|
||||
(0 << -bignum_value).should == 0
|
||||
(1 << -bignum_value).should == 0
|
||||
(bignum_value << -bignum_value).should == 0
|
||||
|
||||
(0 << -(2**40)).should == 0
|
||||
(1 << -(2**40)).should == 0
|
||||
(bignum_value << -(2**40)).should == 0
|
||||
end
|
||||
|
||||
ruby_bug "#18517", ""..."3.2" do
|
||||
it "returns 0 when m > 0 long and n == 0" do
|
||||
(0 << (2**40)).should == 0
|
||||
end
|
||||
end
|
||||
|
||||
it "returns 0 when m > 0 bignum and n == 0" do
|
||||
(0 << bignum_value).should == 0
|
||||
end
|
||||
|
||||
ruby_bug "#18518", ""..."3.3" do
|
||||
it "raises NoMemoryError when m > 0 and n != 0" do
|
||||
coerce_long = mock("long")
|
||||
coerce_long.stub!(:to_int).and_return(2**40)
|
||||
coerce_bignum = mock("bignum")
|
||||
coerce_bignum.stub!(:to_int).and_return(bignum_value)
|
||||
exps = [2**40, bignum_value, coerce_long, coerce_bignum]
|
||||
|
||||
exps.each { |exp|
|
||||
-> { (1 << exp) }.should raise_error(NoMemoryError)
|
||||
-> { (-1 << exp) }.should raise_error(NoMemoryError)
|
||||
-> { (bignum_value << exp) }.should raise_error(NoMemoryError)
|
||||
-> { (-bignum_value << exp) }.should raise_error(NoMemoryError)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ describe "Integer#-" do
|
|||
(9237212 - 5_280).should == 9231932
|
||||
|
||||
(781 - 0.5).should == 780.5
|
||||
(2_560_496 - bignum_value).should == -9223372036852215312
|
||||
(2_560_496 - bignum_value).should == -18446744073706991120
|
||||
end
|
||||
|
||||
it "raises a TypeError when given a non-Integer" do
|
||||
|
@ -29,8 +29,8 @@ describe "Integer#-" do
|
|||
end
|
||||
|
||||
it "returns self minus the given Integer" do
|
||||
(@bignum - 9).should == 9223372036854776113
|
||||
(@bignum - 12.57).should be_close(9223372036854776109.43, TOLERANCE)
|
||||
(@bignum - 9).should == 18446744073709551921
|
||||
(@bignum - 12.57).should be_close(18446744073709551917.43, TOLERANCE)
|
||||
(@bignum - bignum_value(42)).should == 272
|
||||
end
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ describe "Integer#*" do
|
|||
(1342177 * 800).should == 1073741600
|
||||
(65536 * 65536).should == 4294967296
|
||||
|
||||
(256 * bignum_value).should == 2361183241434822606848
|
||||
(256 * bignum_value).should == 4722366482869645213696
|
||||
(6712 * 0.25).should == 1678.0
|
||||
end
|
||||
|
||||
|
@ -32,8 +32,8 @@ describe "Integer#*" do
|
|||
it "returns self multiplied by the given Integer" do
|
||||
(@bignum * (1/bignum_value(0xffff).to_f)).should be_close(1.0, TOLERANCE)
|
||||
(@bignum * (1/bignum_value(0xffff).to_f)).should be_close(1.0, TOLERANCE)
|
||||
(@bignum * 10).should == 92233720368547765800
|
||||
(@bignum * (@bignum - 40)).should == 85070591730234629737795195287525433200
|
||||
(@bignum * 10).should == 184467440737095523880
|
||||
(@bignum * (@bignum - 40)).should == 340282366920938491207277694290934407024
|
||||
end
|
||||
|
||||
it "raises a TypeError when given a non-Integer" do
|
||||
|
|
|
@ -9,7 +9,7 @@ describe "Integer#+" do
|
|||
(491 + 2).should == 493
|
||||
(90210 + 10).should == 90220
|
||||
|
||||
(9 + bignum_value).should == 9223372036854775817
|
||||
(9 + bignum_value).should == 18446744073709551625
|
||||
(1001 + 5.219).should == 1006.219
|
||||
end
|
||||
|
||||
|
@ -29,9 +29,9 @@ describe "Integer#+" do
|
|||
end
|
||||
|
||||
it "returns self plus the given Integer" do
|
||||
(@bignum + 4).should == 9223372036854775888
|
||||
(@bignum + 4.2).should be_close(9223372036854775888.2, TOLERANCE)
|
||||
(@bignum + bignum_value(3)).should == 18446744073709551695
|
||||
(@bignum + 4).should == 18446744073709551696
|
||||
(@bignum + 4.2).should be_close(18446744073709551696.2, TOLERANCE)
|
||||
(@bignum + bignum_value(3)).should == 36893488147419103311
|
||||
end
|
||||
|
||||
it "raises a TypeError when given a non-Integer" do
|
||||
|
|
|
@ -33,7 +33,7 @@ describe "Integer#remainder" do
|
|||
it "returns the remainder of dividing self by other" do
|
||||
a = bignum_value(79)
|
||||
a.remainder(2).should == 1
|
||||
a.remainder(97.345).should be_close(46.5674996147722, TOLERANCE)
|
||||
a.remainder(97.345).should be_close(93.1349992295444, TOLERANCE)
|
||||
a.remainder(bignum_value).should == 79
|
||||
end
|
||||
|
||||
|
|
|
@ -52,10 +52,6 @@ describe "Integer#>> (with n >> m)" do
|
|||
(-7 >> 64).should == -1
|
||||
end
|
||||
|
||||
it "returns 0 when m is a bignum" do
|
||||
(3 >> bignum_value).should == 0
|
||||
end
|
||||
|
||||
it "returns a Bignum == fixnum_max * 2 when fixnum_max >> -1 and n > 0" do
|
||||
result = fixnum_max >> -1
|
||||
result.should be_an_instance_of(Integer)
|
||||
|
@ -96,7 +92,7 @@ describe "Integer#>> (with n >> m)" do
|
|||
|
||||
context "bignum" do
|
||||
before :each do
|
||||
@bignum = bignum_value * 16
|
||||
@bignum = bignum_value * 8 # 2 ** 67
|
||||
end
|
||||
|
||||
it "returns n shifted right m bits when n > 0, m > 0" do
|
||||
|
@ -153,10 +149,6 @@ describe "Integer#>> (with n >> m)" do
|
|||
(@bignum >> 68).should == 0
|
||||
end
|
||||
|
||||
it "returns 0 when m is a Bignum" do
|
||||
(@bignum >> bignum_value).should == 0
|
||||
end
|
||||
|
||||
it "returns a Fixnum == fixnum_max when (fixnum_max * 2) >> 1 and n > 0" do
|
||||
result = (fixnum_max * 2) >> 1
|
||||
result.should be_an_instance_of(Integer)
|
||||
|
@ -191,4 +183,51 @@ describe "Integer#>> (with n >> m)" do
|
|||
-> { @bignum >> "4" }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
context "when m is a bignum or larger than int" do
|
||||
it "returns -1 when m > 0 and n < 0" do
|
||||
(-1 >> bignum_value).should == -1
|
||||
(-1 >> (2**40)).should == -1
|
||||
|
||||
(-bignum_value >> bignum_value).should == -1
|
||||
(-bignum_value >> (2**40)).should == -1
|
||||
end
|
||||
|
||||
it "returns 0 when m > 0 and n >= 0" do
|
||||
(0 >> bignum_value).should == 0
|
||||
(1 >> bignum_value).should == 0
|
||||
(bignum_value >> bignum_value).should == 0
|
||||
|
||||
(0 >> (2**40)).should == 0
|
||||
(1 >> (2**40)).should == 0
|
||||
(bignum_value >> (2**40)).should == 0
|
||||
end
|
||||
|
||||
ruby_bug "#18517", ""..."3.2" do
|
||||
it "returns 0 when m < 0 long and n == 0" do
|
||||
(0 >> -(2**40)).should == 0
|
||||
end
|
||||
end
|
||||
|
||||
it "returns 0 when m < 0 bignum and n == 0" do
|
||||
(0 >> -bignum_value).should == 0
|
||||
end
|
||||
|
||||
ruby_bug "#18518", ""..."3.3" do
|
||||
it "raises NoMemoryError when m < 0 and n != 0" do
|
||||
coerce_long = mock("long")
|
||||
coerce_long.stub!(:to_int).and_return(-(2**40))
|
||||
coerce_bignum = mock("bignum")
|
||||
coerce_bignum.stub!(:to_int).and_return(-bignum_value)
|
||||
exps = [-(2**40), -bignum_value, coerce_long, coerce_bignum]
|
||||
|
||||
exps.each { |exp|
|
||||
-> { (1 >> exp) }.should raise_error(NoMemoryError)
|
||||
-> { (-1 >> exp) }.should raise_error(NoMemoryError)
|
||||
-> { (bignum_value >> exp) }.should raise_error(NoMemoryError)
|
||||
-> { (-bignum_value >> exp) }.should raise_error(NoMemoryError)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,8 +11,8 @@ describe :integer_abs, shared: true do
|
|||
|
||||
context "bignum" do
|
||||
it "returns the absolute bignum value" do
|
||||
bignum_value(39).send(@method).should == 9223372036854775847
|
||||
(-bignum_value(18)).send(@method).should == 9223372036854775826
|
||||
bignum_value(39).send(@method).should == 18446744073709551655
|
||||
(-bignum_value(18)).send(@method).should == 18446744073709551634
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,11 +30,13 @@ describe :integer_exponent, shared: true do
|
|||
(-2).send(@method, 30).should eql(1073741824)
|
||||
(-2).send(@method, 31).should eql(-2147483648)
|
||||
(-2).send(@method, 32).should eql(4294967296)
|
||||
(-2).send(@method, 33).should eql(-8589934592)
|
||||
|
||||
(-2).send(@method, 61).should eql(-2305843009213693952)
|
||||
(-2).send(@method, 62).should eql(4611686018427387904)
|
||||
(-2).send(@method, 63).should eql(-9223372036854775808)
|
||||
(-2).send(@method, 64).should eql(18446744073709551616)
|
||||
(-2).send(@method, 65).should eql(-36893488147419103232)
|
||||
end
|
||||
|
||||
it "can raise 1 to a bignum safely" do
|
||||
|
@ -96,8 +98,8 @@ describe :integer_exponent, shared: true do
|
|||
end
|
||||
|
||||
it "returns self raised to other power" do
|
||||
(@bignum.send(@method, 4)).should == 7237005577332262361485077344629993318496048279512298547155833600056910050625
|
||||
(@bignum.send(@method, 1.2)).should be_close(57262152889751597425762.57804, TOLERANCE)
|
||||
(@bignum.send(@method, 4)).should == 115792089237316196603666111261383895964500887398800252671052694326794607293761
|
||||
(@bignum.send(@method, 1.3)).should be_close(11109528802438156839288832.0, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises a TypeError when given a non-Integer" do
|
||||
|
@ -116,8 +118,9 @@ describe :integer_exponent, shared: true do
|
|||
end
|
||||
|
||||
it "returns a complex number when negative and raised to a fractional power" do
|
||||
((-@bignum).send(@method, (1.0/3))) .should be_close(Complex(1048576,1816186.907597341), TOLERANCE)
|
||||
((-@bignum).send(@method, Rational(1,3))).should be_close(Complex(1048576,1816186.907597341), TOLERANCE)
|
||||
(-bignum_value).send(@method, (1.0/2)).should be_close(Complex(0.0, 4294967296.0), TOLERANCE)
|
||||
(-@bignum).send(@method, (1.0/3)) .should be_close(Complex(1321122.9748145656, 2288252.1154253655), TOLERANCE)
|
||||
(-@bignum).send(@method, Rational(1,3)).should be_close(Complex(1321122.9748145656, 2288252.1154253655), TOLERANCE)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -48,11 +48,11 @@ describe :integer_modulo, shared: true do
|
|||
end
|
||||
|
||||
it "returns the modulus obtained from dividing self by the given argument" do
|
||||
@bignum.send(@method, 5).should == 3
|
||||
@bignum.send(@method, -5).should == -2
|
||||
@bignum.send(@method, -100).should == -92
|
||||
@bignum.send(@method, 2.22).should be_close(0.780180180180252, TOLERANCE)
|
||||
@bignum.send(@method, bignum_value(10)).should == 9223372036854775808
|
||||
@bignum.send(@method, 5).should == 1
|
||||
@bignum.send(@method, -5).should == -4
|
||||
@bignum.send(@method, -100).should == -84
|
||||
@bignum.send(@method, 2.22).should be_close(1.5603603603605034, TOLERANCE)
|
||||
@bignum.send(@method, bignum_value(10)).should == 18446744073709551616
|
||||
end
|
||||
|
||||
it "raises a ZeroDivisionError when the given argument is 0" do
|
||||
|
|
|
@ -11,9 +11,9 @@ describe "Integer#to_f" do
|
|||
|
||||
context "bignum" do
|
||||
it "returns self converted to a Float" do
|
||||
bignum_value(0x4000_0aa0_0bb0_0000).to_f.should eql(13_835_069_737_789_292_544.00)
|
||||
bignum_value(0x8000_0000_0000_0ccc).to_f.should eql(18_446_744_073_709_555_712.00)
|
||||
(-bignum_value(99)).to_f.should eql(-9_223_372_036_854_775_808.00)
|
||||
bignum_value(0x4000_0aa0_0bb0_0000).to_f.should eql(23_058_441_774_644_068_352.0)
|
||||
bignum_value(0x8000_0000_0000_0ccc).to_f.should eql(27_670_116_110_564_330_700.0)
|
||||
(-bignum_value(99)).to_f.should eql(-18_446_744_073_709_551_715.0)
|
||||
end
|
||||
|
||||
it "converts number close to Float::MAX without exceeding MAX or producing NaN" do
|
||||
|
|
|
@ -68,9 +68,9 @@ describe "Integer#to_s" do
|
|||
|
||||
describe "when given no base" do
|
||||
it "returns self converted to a String using base 10" do
|
||||
bignum_value(9).to_s.should == "9223372036854775817"
|
||||
bignum_value.to_s.should == "9223372036854775808"
|
||||
(-bignum_value(675)).to_s.should == "-9223372036854776483"
|
||||
bignum_value(9).to_s.should == "18446744073709551625"
|
||||
bignum_value.to_s.should == "18446744073709551616"
|
||||
(-bignum_value(675)).to_s.should == "-18446744073709552291"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -20,11 +20,11 @@ describe "Integer#-@" do
|
|||
|
||||
context "bignum" do
|
||||
it "returns self as a negative value" do
|
||||
bignum_value.send(:-@).should == -9223372036854775808
|
||||
(-bignum_value).send(:-@).should == 9223372036854775808
|
||||
bignum_value.send(:-@).should == -18446744073709551616
|
||||
(-bignum_value).send(:-@).should == 18446744073709551616
|
||||
|
||||
bignum_value(921).send(:-@).should == -9223372036854776729
|
||||
(-bignum_value(921).send(:-@)).should == 9223372036854776729
|
||||
bignum_value(921).send(:-@).should == -18446744073709552537
|
||||
(-bignum_value(921).send(:-@)).should == 18446744073709552537
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -168,3 +168,27 @@ platform_is :windows do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
describe "IO#write on STDOUT" do
|
||||
# https://bugs.ruby-lang.org/issues/14413
|
||||
platform_is_not :windows do
|
||||
it "raises SignalException SIGPIPE if the stream is closed instead of Errno::EPIPE like other IOs" do
|
||||
stderr_file = tmp("stderr")
|
||||
begin
|
||||
IO.popen([*ruby_exe, "-e", "loop { puts :ok }"], "r", err: stderr_file) do |io|
|
||||
io.gets.should == "ok\n"
|
||||
io.close
|
||||
end
|
||||
status = $?
|
||||
status.should_not.success?
|
||||
status.should.signaled?
|
||||
Signal.signame(status.termsig).should == 'PIPE'
|
||||
File.read(stderr_file).should.empty?
|
||||
ensure
|
||||
rm_r stderr_file
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -89,5 +89,11 @@ describe "Kernel#instance_variable_set" do
|
|||
it "raises a FrozenError when passed replacement is different from stored object" do
|
||||
-> { @frozen.instance_variable_set(:@ivar, :replacement) }.should raise_error(FrozenError)
|
||||
end
|
||||
|
||||
it "accepts unicode instance variable names" do
|
||||
o = Object.new
|
||||
o.instance_variable_set(:@💙, 42)
|
||||
o.instance_variable_get(:@💙).should == 42
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,6 +15,32 @@ ruby_version_is "2.7" do
|
|||
Hash.ruby2_keywords_hash?(last).should == true
|
||||
end
|
||||
|
||||
it "applies to the underlying method and applies across aliasing" do
|
||||
obj = Object.new
|
||||
|
||||
obj.singleton_class.class_exec do
|
||||
def foo(*a) a.last end
|
||||
alias_method :bar, :foo
|
||||
ruby2_keywords :foo
|
||||
|
||||
def baz(*a) a.last end
|
||||
ruby2_keywords :baz
|
||||
alias_method :bob, :baz
|
||||
end
|
||||
|
||||
last = obj.foo(1, 2, a: "a")
|
||||
Hash.ruby2_keywords_hash?(last).should == true
|
||||
|
||||
last = obj.bar(1, 2, a: "a")
|
||||
Hash.ruby2_keywords_hash?(last).should == true
|
||||
|
||||
last = obj.baz(1, 2, a: "a")
|
||||
Hash.ruby2_keywords_hash?(last).should == true
|
||||
|
||||
last = obj.bob(1, 2, a: "a")
|
||||
Hash.ruby2_keywords_hash?(last).should == true
|
||||
end
|
||||
|
||||
ruby_version_is "2.7" ... "3.0" do
|
||||
it "fixes delegation warnings when calling a method accepting keywords" do
|
||||
obj = Object.new
|
||||
|
|
|
@ -20,7 +20,7 @@ describe "Numeric#quo" do
|
|||
-> { 10.quo(0) }.should raise_error(ZeroDivisionError)
|
||||
-> { -10.quo(0) }.should raise_error(ZeroDivisionError)
|
||||
-> { bignum_value.quo(0) }.should raise_error(ZeroDivisionError)
|
||||
-> { -bignum_value.quo(0) }.should raise_error(ZeroDivisionError)
|
||||
-> { (-bignum_value).quo(0) }.should raise_error(ZeroDivisionError)
|
||||
end
|
||||
|
||||
it "calls #to_r to convert the object to a Rational" do
|
||||
|
|
|
@ -10,6 +10,22 @@ ruby_version_is "2.7" do
|
|||
Hash.ruby2_keywords_hash?(last).should == true
|
||||
end
|
||||
|
||||
it "applies to the underlying method and applies across duplication" do
|
||||
f1 = -> *a { a.last }
|
||||
f1.ruby2_keywords
|
||||
f2 = f1.dup
|
||||
|
||||
Hash.ruby2_keywords_hash?(f1.call(1, 2, a: "a")).should == true
|
||||
Hash.ruby2_keywords_hash?(f2.call(1, 2, a: "a")).should == true
|
||||
|
||||
f3 = -> *a { a.last }
|
||||
f4 = f3.dup
|
||||
f3.ruby2_keywords
|
||||
|
||||
Hash.ruby2_keywords_hash?(f3.call(1, 2, a: "a")).should == true
|
||||
Hash.ruby2_keywords_hash?(f4.call(1, 2, a: "a")).should == true
|
||||
end
|
||||
|
||||
ruby_version_is "2.7" ... "3.0" do
|
||||
it "fixes delegation warnings when calling a method accepting keywords" do
|
||||
obj = Object.new
|
||||
|
|
|
@ -18,7 +18,7 @@ describe "Random#bytes" do
|
|||
end
|
||||
|
||||
it "returns the same numeric output for a given huge seed across all implementations and platforms" do
|
||||
rnd = Random.new(bignum_value ** 4)
|
||||
rnd = Random.new(2 ** (63 * 4))
|
||||
rnd.bytes(2).should == "_\x91"
|
||||
rnd.bytes(1000) # skip some
|
||||
rnd.bytes(2).should == "\x17\x12"
|
||||
|
|
|
@ -12,4 +12,10 @@ describe "Range#dup" do
|
|||
copy.end.should == "z"
|
||||
copy.should.exclude_end?
|
||||
end
|
||||
|
||||
it "creates an unfrozen range" do
|
||||
(1..2).dup.should_not.frozen?
|
||||
(1..).dup.should_not.frozen?
|
||||
Range.new(1, 2).dup.should_not.frozen?
|
||||
end
|
||||
end
|
||||
|
|
27
spec/ruby/core/range/frozen_spec.rb
Normal file
27
spec/ruby/core/range/frozen_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
# There is no Range#frozen? method but this feels like the best place for these specs
|
||||
describe "Range#frozen?" do
|
||||
ruby_version_is "3.0" do
|
||||
it "is true for literal ranges" do
|
||||
(1..2).should.frozen?
|
||||
(1..).should.frozen?
|
||||
eval("(..1)").should.frozen?
|
||||
end
|
||||
|
||||
it "is true for Range.new" do
|
||||
Range.new(1, 2).should.frozen?
|
||||
Range.new(1, nil).should.frozen?
|
||||
Range.new(nil, 1).should.frozen?
|
||||
end
|
||||
|
||||
it "is false for instances of a subclass of Range" do
|
||||
sub_range = Class.new(Range).new(1, 2)
|
||||
sub_range.should_not.frozen?
|
||||
end
|
||||
|
||||
it "is false for Range.allocate" do
|
||||
Range.allocate.should_not.frozen?
|
||||
end
|
||||
end
|
||||
end
|
|
@ -224,6 +224,17 @@ describe "String#split with String" do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "returns an empty array when whitespace is split on whitespace" do
|
||||
" ".split(" ").should == []
|
||||
" \n ".split(" ").should == []
|
||||
" ".split(" ").should == []
|
||||
" \t ".split(" ").should == []
|
||||
end
|
||||
|
||||
it "doesn't split on non-ascii whitespace" do
|
||||
"a\u{2008}b".split(" ").should == ["a\u{2008}b"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "String#split with Regexp" do
|
||||
|
|
|
@ -74,6 +74,50 @@ ruby_version_is "2.7" do
|
|||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "can be nested" do
|
||||
eval(<<~RUBY).should == [[0, [2, 4, 6]], [[4, 16, 64]], 27]
|
||||
case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]]
|
||||
in [*pre, [*, 9, a], *post]
|
||||
[pre, post, a]
|
||||
else
|
||||
false
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "can be nested with an array pattern" do
|
||||
eval(<<~RUBY).should == [[4, 16, 64]]
|
||||
case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]]
|
||||
in [_, _, [*, 9, *], *post]
|
||||
post
|
||||
else
|
||||
false
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "can be nested within a hash pattern" do
|
||||
eval(<<~RUBY).should == [27]
|
||||
case {a: [3, 9, 27]}
|
||||
in {a: [*, 9, *post]}
|
||||
post
|
||||
else
|
||||
false
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "can nest hash and array patterns" do
|
||||
eval(<<~RUBY).should == [42, 2]
|
||||
case [0, {a: 42, b: [0, 1]}, {a: 42, b: [1, 2]}]
|
||||
in [*, {a:, b: [1, c]}, *]
|
||||
[a, c]
|
||||
else
|
||||
false
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -15,12 +15,6 @@ describe "Literal Ranges" do
|
|||
(1...).should == Range.new(1, nil, true)
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "is frozen" do
|
||||
(42..).should.frozen?
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "2.7" do
|
||||
it "creates beginless ranges" do
|
||||
eval("(..1)").should == Range.new(nil, 1)
|
||||
|
|
|
@ -115,6 +115,18 @@ describe "The rescue keyword" do
|
|||
end
|
||||
end
|
||||
|
||||
it "converts the splatted list of exceptions using #to_a" do
|
||||
exceptions = mock("to_a")
|
||||
exceptions.should_receive(:to_a).and_return(exception_list)
|
||||
caught_it = false
|
||||
begin
|
||||
raise SpecificExampleException, "not important"
|
||||
rescue *exceptions
|
||||
caught_it = true
|
||||
end
|
||||
caught_it.should be_true
|
||||
end
|
||||
|
||||
it "can combine a splatted list of exceptions with a literal list of exceptions" do
|
||||
caught_it = false
|
||||
begin
|
||||
|
|
|
@ -24,8 +24,8 @@ ruby_version_is ""..."3.1" do
|
|||
|
||||
it "returns the result of multiplying the elements of self and a Bignum" do
|
||||
(@a * bignum_value).should == Matrix[
|
||||
[9223372036854775808, 18446744073709551616],
|
||||
[27670116110564327424, 36893488147419103232]
|
||||
[18446744073709551616, 36893488147419103232],
|
||||
[55340232221128654848, 73786976294838206464]
|
||||
]
|
||||
end
|
||||
|
||||
|
|
16
spec/ruby/library/pathname/birthtime_spec.rb
Normal file
16
spec/ruby/library/pathname/birthtime_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
require_relative '../../spec_helper'
|
||||
require 'pathname'
|
||||
|
||||
describe "Pathname#birthtime" do
|
||||
platform_is :windows, :darwin, :freebsd, :netbsd do
|
||||
it "returns the birth time for self" do
|
||||
Pathname.new(__FILE__).birthtime.should be_kind_of(Time)
|
||||
end
|
||||
end
|
||||
|
||||
platform_is :openbsd do
|
||||
it "raises an NotImplementedError" do
|
||||
-> { Pathname.new(__FILE__).birthtime }.should raise_error(NotImplementedError)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -55,3 +55,40 @@ describe 'Pathname.glob' do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'Pathname#glob' do
|
||||
before :all do
|
||||
@dir = tmp('pathname_glob') + '/'
|
||||
@file_1 = @dir + 'lib/ipaddr.rb'
|
||||
@file_2 = @dir + 'lib/irb.rb'
|
||||
@file_3 = @dir + 'lib/.hidden.rb'
|
||||
|
||||
touch @file_1
|
||||
touch @file_2
|
||||
touch @file_3
|
||||
end
|
||||
|
||||
after :all do
|
||||
rm_r @dir[0...-1]
|
||||
end
|
||||
|
||||
it 'returns [] for no match' do
|
||||
Pathname.new(@dir).glob('lib/*.js').should == []
|
||||
end
|
||||
|
||||
it 'returns matching file paths' do
|
||||
Pathname.new(@dir).glob('lib/*i*.rb').sort.should == [Pathname.new(@file_1), Pathname.new(@file_2)].sort
|
||||
end
|
||||
|
||||
it 'yields matching file paths to block' do
|
||||
ary = []
|
||||
Pathname.new(@dir).glob('lib/*i*.rb') { |p| ary << p }.should be_nil
|
||||
ary.sort.should == [Pathname.new(@file_1), Pathname.new(@file_2)].sort
|
||||
end
|
||||
|
||||
it 'returns matching file paths when a flag is provided' do
|
||||
expected = [Pathname.new(@file_1), Pathname.new(@file_2), Pathname.new(@file_3)].sort
|
||||
Pathname.new(@dir).glob('lib/*i*.rb', File::FNM_DOTMATCH).sort.should == expected
|
||||
end
|
||||
end
|
||||
|
|
|
@ -87,6 +87,10 @@ VALUE string_spec_rb_str_tmp_new_klass(VALUE self, VALUE len) {
|
|||
return RBASIC_CLASS(rb_str_tmp_new(NUM2LONG(len)));
|
||||
}
|
||||
|
||||
VALUE string_spec_rb_str_buf_append(VALUE self, VALUE str, VALUE two) {
|
||||
return rb_str_buf_append(str, two);
|
||||
}
|
||||
|
||||
VALUE string_spec_rb_str_buf_cat(VALUE self, VALUE str) {
|
||||
const char *question_mark = "?";
|
||||
rb_str_buf_cat(str, question_mark, strlen(question_mark));
|
||||
|
@ -599,6 +603,7 @@ void Init_string_spec(void) {
|
|||
rb_define_method(cls, "rb_str_buf_new2", string_spec_rb_str_buf_new2, 0);
|
||||
rb_define_method(cls, "rb_str_tmp_new", string_spec_rb_str_tmp_new, 1);
|
||||
rb_define_method(cls, "rb_str_tmp_new_klass", string_spec_rb_str_tmp_new_klass, 1);
|
||||
rb_define_method(cls, "rb_str_buf_append", string_spec_rb_str_buf_append, 2);
|
||||
rb_define_method(cls, "rb_str_buf_cat", string_spec_rb_str_buf_cat, 1);
|
||||
rb_define_method(cls, "rb_enc_str_buf_cat", string_spec_rb_enc_str_buf_cat, 3);
|
||||
rb_define_method(cls, "rb_str_cat", string_spec_rb_str_cat, 1);
|
||||
|
|
|
@ -378,6 +378,14 @@ describe "C-API String function" do
|
|||
it_behaves_like :string_times, :rb_str_times, -> str, times { @s.rb_str_times(str, times) }
|
||||
end
|
||||
|
||||
describe "rb_str_buf_append" do
|
||||
it "concatenates a string to another string" do
|
||||
str = "Your house "
|
||||
@s.rb_str_buf_append(str, "is on fire?").should.equal?(str)
|
||||
str.should == "Your house is on fire?"
|
||||
end
|
||||
end
|
||||
|
||||
describe "rb_str_buf_cat" do
|
||||
it "concatenates a C string to a ruby string" do
|
||||
@s.rb_str_buf_cat("Your house is on fire").should == "Your house is on fire?"
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
require 'rubygems'
|
||||
require 'rubygems/user_interaction'
|
||||
guard_not -> { platform_is :darwin and ENV['GITHUB_ACTIONS'] } do # frequent timeout/hang on macOS in GitHub Actions
|
||||
require 'rubygems'
|
||||
require 'rubygems/user_interaction'
|
||||
|
||||
describe "CVE-2019-8321 is resisted by" do
|
||||
describe "CVE-2019-8321 is resisted by" do
|
||||
it "sanitising verbose messages" do
|
||||
ui = Class.new {
|
||||
include Gem::UserInteraction
|
||||
|
@ -17,4 +18,5 @@ describe "CVE-2019-8321 is resisted by" do
|
|||
Gem.configuration.verbose = verbose_before
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
require 'yaml'
|
||||
require 'rubygems'
|
||||
require 'rubygems/safe_yaml'
|
||||
require 'rubygems/commands/owner_command'
|
||||
guard_not -> { platform_is :darwin and ENV['GITHUB_ACTIONS'] } do # frequent timeout/hang on macOS in GitHub Actions
|
||||
require 'yaml'
|
||||
require 'rubygems'
|
||||
require 'rubygems/safe_yaml'
|
||||
require 'rubygems/commands/owner_command'
|
||||
|
||||
platform_is_not :darwin do # frequent timeout/hang on macOS
|
||||
describe "CVE-2019-8322 is resisted by" do
|
||||
it "sanitising owner names" do
|
||||
command = Gem::Commands::OwnerCommand.new
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
platform_is_not :darwin do # frequent timeout/hang on macOS
|
||||
guard_not -> { platform_is :darwin and ENV['GITHUB_ACTIONS'] } do # frequent timeout/hang on macOS in GitHub Actions
|
||||
require 'optparse'
|
||||
|
||||
require 'rubygems'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
platform_is_not :darwin do # frequent timeout/hang on macOS
|
||||
guard_not -> { platform_is :darwin and ENV['GITHUB_ACTIONS'] } do # frequent timeout/hang on macOS in GitHub Actions
|
||||
require 'rubygems'
|
||||
require 'rubygems/command_manager'
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ guard -> {
|
|||
JSON.const_defined?(:Pure) or
|
||||
version_is(JSON::VERSION, '2.3.0')
|
||||
} do
|
||||
platform_is_not :darwin do # frequent timeout/hang on macOS
|
||||
guard_not -> { platform_is :darwin and ENV['GITHUB_ACTIONS'] } do # frequent timeout/hang on macOS in GitHub Actions
|
||||
describe "CVE-2020-10663 is resisted by" do
|
||||
it "only creating custom objects if passed create_additions: true or using JSON.load" do
|
||||
obj = JSONSpecs::MyClass.new("bar")
|
||||
|
|
|
@ -6,7 +6,7 @@ describe :rational_divmod_rat, shared: true do
|
|||
Rational(7, 4).divmod(Rational(-1, 2)).should eql([-4, Rational(-1, 4)])
|
||||
Rational(0, 4).divmod(Rational(4, 3)).should eql([0, Rational(0, 1)])
|
||||
|
||||
Rational(bignum_value, 4).divmod(Rational(4, 3)).should eql([1729382256910270464, Rational(0, 1)])
|
||||
Rational(bignum_value, 4).divmod(Rational(4, 3)).should eql([3458764513820540928, Rational(0, 1)])
|
||||
end
|
||||
|
||||
it "raises a ZeroDivisionError when passed a Rational with a numerator of 0" do
|
||||
|
@ -19,7 +19,7 @@ describe :rational_divmod_int, shared: true do
|
|||
Rational(7, 4).divmod(2).should eql([0, Rational(7, 4)])
|
||||
Rational(7, 4).divmod(-2).should eql([-1, Rational(-1, 4)])
|
||||
|
||||
Rational(bignum_value, 4).divmod(3).should == [768614336404564650, Rational(2, 1)]
|
||||
Rational(bignum_value, 4).divmod(3).should eql([1537228672809129301, Rational(1, 1)])
|
||||
end
|
||||
|
||||
it "raises a ZeroDivisionError when passed 0" do
|
||||
|
|
|
@ -40,10 +40,10 @@ describe :rational_exponent, shared: true do
|
|||
(Rational(-3, 4) ** -4).should == Rational(256, 81)
|
||||
(Rational(3, -4) ** -4).should == Rational(256, 81)
|
||||
|
||||
(Rational(bignum_value, 4) ** 4).should == Rational(28269553036454149273332760011886696253239742350009903329945699220681916416, 1)
|
||||
(Rational(3, bignum_value) ** -4).should == Rational(7237005577332262213973186563042994240829374041602535252466099000494570602496, 81)
|
||||
(Rational(-bignum_value, 4) ** -4).should == Rational(1, 28269553036454149273332760011886696253239742350009903329945699220681916416)
|
||||
(Rational(3, -bignum_value) ** -4).should == Rational(7237005577332262213973186563042994240829374041602535252466099000494570602496, 81)
|
||||
(Rational(bignum_value, 4) ** 4).should == Rational(452312848583266388373324160190187140051835877600158453279131187530910662656, 1)
|
||||
(Rational(3, bignum_value) ** -4).should == Rational(115792089237316195423570985008687907853269984665640564039457584007913129639936, 81)
|
||||
(Rational(-bignum_value, 4) ** -4).should == Rational(1, 452312848583266388373324160190187140051835877600158453279131187530910662656)
|
||||
(Rational(3, -bignum_value) ** -4).should == Rational(115792089237316195423570985008687907853269984665640564039457584007913129639936, 81)
|
||||
end
|
||||
|
||||
# Guard against the Mathn library
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue