Skip to content

Commit

Permalink
Update to ruby/spec@902ab83
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jan 28, 2022
1 parent bb5f710 commit e0c5488
Show file tree
Hide file tree
Showing 56 changed files with 531 additions and 137 deletions.
1 change: 1 addition & 0 deletions spec/ruby/core/dir/fixtures/common.rb
Expand Up @@ -94,6 +94,7 @@ def self.mock_dir_files
special/こんにちは.txt
special/\a
]
@mock_dir_files << "special/_\u{1f60e}.erb"
end
end

Expand Down
33 changes: 33 additions & 0 deletions spec/ruby/core/dir/read_spec.rb
Expand Up @@ -39,5 +39,38 @@
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
1 change: 0 additions & 1 deletion spec/ruby/core/enumerable/all_spec.rb
Expand Up @@ -131,7 +131,6 @@
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
Expand Down
1 change: 0 additions & 1 deletion spec/ruby/core/enumerable/any_spec.rb
Expand Up @@ -145,7 +145,6 @@
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
Expand Down
1 change: 0 additions & 1 deletion spec/ruby/core/enumerable/none_spec.rb
Expand Up @@ -100,7 +100,6 @@
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
Expand Down
1 change: 0 additions & 1 deletion spec/ruby/core/enumerable/one_spec.rb
Expand Up @@ -91,7 +91,6 @@
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
Expand Down
4 changes: 2 additions & 2 deletions spec/ruby/core/float/coerce_spec.rb
Expand Up @@ -9,10 +9,10 @@
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
2 changes: 1 addition & 1 deletion spec/ruby/core/float/divmod_spec.rb
Expand Up @@ -10,7 +10,7 @@
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)
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/float/minus_spec.rb
Expand Up @@ -6,7 +6,7 @@

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
2 changes: 1 addition & 1 deletion spec/ruby/core/float/multiply_spec.rb
Expand Up @@ -7,7 +7,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/float/plus_spec.rb
Expand Up @@ -6,7 +6,7 @@

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
1 change: 0 additions & 1 deletion spec/ruby/core/hash/transform_keys_spec.rb
Expand Up @@ -73,7 +73,6 @@
@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 }
Expand Down
14 changes: 7 additions & 7 deletions spec/ruby/core/integer/bit_and_spec.rb
Expand Up @@ -55,24 +55,24 @@
@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
Expand Down
33 changes: 27 additions & 6 deletions spec/ruby/core/integer/bit_or_spec.rb
Expand Up @@ -7,13 +7,34 @@
(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
Expand All @@ -32,20 +53,20 @@
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

Expand Down
35 changes: 28 additions & 7 deletions spec/ruby/core/integer/bit_xor_spec.rb
Expand Up @@ -5,13 +5,34 @@
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
Expand All @@ -30,21 +51,21 @@
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
Expand Down
8 changes: 6 additions & 2 deletions spec/ruby/core/integer/chr_spec.rb
Expand Up @@ -11,7 +11,11 @@

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
Expand Down Expand Up @@ -162,7 +166,7 @@
# 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
Expand Down
6 changes: 3 additions & 3 deletions spec/ruby/core/integer/complement_spec.rb
Expand Up @@ -12,9 +12,9 @@

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
10 changes: 5 additions & 5 deletions spec/ruby/core/integer/div_spec.rb
Expand Up @@ -70,8 +70,8 @@
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
Expand Down Expand Up @@ -124,11 +124,11 @@
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

Expand Down
12 changes: 6 additions & 6 deletions spec/ruby/core/integer/divide_spec.rb
Expand Up @@ -47,7 +47,7 @@
end

it "returns self divided by other" do
(@bignum / 4).should == 2305843009213693974
(@bignum / 4).should == 4611686018427387926

(@bignum / bignum_value(2)).should == 1

Expand All @@ -60,15 +60,15 @@

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
Expand Down

0 comments on commit e0c5488

Please sign in to comment.