Skip to content

Commit bb33fa0

Browse files
authored
[test] move regression specs into ruby/spec (jruby#9342)
All specs verified against CRuby 3.4.8
1 parent 0d25672 commit bb33fa0

13 files changed

Lines changed: 83 additions & 164 deletions

spec/regression/bignum_coerce_relop_spec.rb

Lines changed: 0 additions & 42 deletions
This file was deleted.

spec/regression/bignum_eql_type_check_spec.rb

Lines changed: 0 additions & 35 deletions
This file was deleted.

spec/regression/bignum_float_comparison_precision_spec.rb

Lines changed: 0 additions & 54 deletions
This file was deleted.

spec/regression/matchdata_deconstruct_keys_nil_capture_spec.rb

Lines changed: 0 additions & 33 deletions
This file was deleted.

spec/ruby/core/integer/comparison_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@
157157
end
158158
end
159159

160+
describe "with a Float" do
161+
it "does not lose precision for values that don't fit in a double" do
162+
(bignum_value(1) <=> bignum_value.to_f).should == 1
163+
(bignum_value <=> bignum_value.to_f).should == 0
164+
((bignum_value - 1) <=> bignum_value.to_f).should == -1
165+
end
166+
end
167+
160168
# The tests below are taken from matz's revision 23730 for Ruby trunk
161169
it "returns 1 when self is Infinity and other is a Bignum" do
162170
(infinity_value <=> Float::MAX.to_i*2).should == 1

spec/ruby/core/integer/eql_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require_relative '../../spec_helper'
2+
3+
describe "Integer#eql?" do
4+
context "bignum" do
5+
it "returns true for the same value" do
6+
bignum_value.eql?(bignum_value).should == true
7+
end
8+
9+
it "returns false for a different Integer value" do
10+
bignum_value.eql?(bignum_value(1)).should == false
11+
end
12+
13+
it "returns false for a Float with the same numeric value" do
14+
bignum_value.eql?(bignum_value.to_f).should == false
15+
end
16+
17+
it "returns false for a Rational with the same numeric value" do
18+
bignum_value.eql?(Rational(bignum_value)).should == false
19+
end
20+
21+
it "returns false for a Fixnum-range Integer" do
22+
bignum_value.eql?(42).should == false
23+
end
24+
end
25+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
module IntegerSpecs
22
class CoerceError < StandardError
33
end
4+
5+
class CoercibleNumeric
6+
def initialize(v) @v = v end
7+
def coerce(other) [self.class.new(other), self] end
8+
def >(other) @v.to_i > other.to_i end
9+
def >=(other) @v.to_i >= other.to_i end
10+
def <(other) @v.to_i < other.to_i end
11+
def <=(other) @v.to_i <= other.to_i end
12+
def to_i() @v.to_i end
13+
end
414
end

spec/ruby/core/integer/gt_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@
3939
-> { @bignum > "4" }.should raise_error(ArgumentError)
4040
-> { @bignum > mock('str') }.should raise_error(ArgumentError)
4141
end
42+
43+
it "dispatches the correct operator after coercion" do
44+
(bignum_value > IntegerSpecs::CoercibleNumeric.new(1)).should == true
45+
(bignum_value > IntegerSpecs::CoercibleNumeric.new(bignum_value * 2)).should == false
46+
end
4247
end
4348
end

spec/ruby/core/integer/gte_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@
3939
-> { @bignum >= "4" }.should raise_error(ArgumentError)
4040
-> { @bignum >= mock('str') }.should raise_error(ArgumentError)
4141
end
42+
43+
it "dispatches the correct operator after coercion" do
44+
(bignum_value >= IntegerSpecs::CoercibleNumeric.new(1)).should == true
45+
(bignum_value >= IntegerSpecs::CoercibleNumeric.new(bignum_value * 2)).should == false
46+
end
4247
end
4348
end

spec/ruby/core/integer/lt_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,10 @@
4141
-> { @bignum < "4" }.should raise_error(ArgumentError)
4242
-> { @bignum < mock('str') }.should raise_error(ArgumentError)
4343
end
44+
45+
it "dispatches the correct operator after coercion" do
46+
(bignum_value < IntegerSpecs::CoercibleNumeric.new(bignum_value * 2)).should == true
47+
(bignum_value < IntegerSpecs::CoercibleNumeric.new(1)).should == false
48+
end
4449
end
4550
end

0 commit comments

Comments
 (0)