Skip to content

Commit

Permalink
Use Integer instead of Fixnum/Bignum
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Dec 20, 2020
1 parent fb8f011 commit 9c73c75
Show file tree
Hide file tree
Showing 144 changed files with 391 additions and 389 deletions.
8 changes: 4 additions & 4 deletions spec/ruby/CONTRIBUTING.md
Expand Up @@ -8,7 +8,7 @@ Spec are grouped in 5 separate top-level groups:

* `command_line`: for the ruby executable command-line flags (`-v`, `-e`, etc)
* `language`: for the language keywords and syntax constructs (`if`, `def`, `A::B`, etc)
* `core`: for the core methods (`Fixnum#+`, `String#upcase`, no need to require anything)
* `core`: for the core methods (`Integer#+`, `String#upcase`, no need to require anything)
* `library`: for the standard libraries methods (`CSV.new`, `YAML.parse`, need to require the stdlib)
* `optional/capi`: for functions available to the Ruby C-extension API

Expand Down Expand Up @@ -89,7 +89,7 @@ File.should.equal?(File) # Calls #equal? (tests identity)
Numeric.should be_ancestor_of(Float) # Float.ancestors.include?(Numeric)

3.14.should.respond_to?(:to_i)
Fixnum.should have_instance_method(:+)
Integer.should have_instance_method(:+)
Array.should have_method(:new)
```

Expand Down Expand Up @@ -124,8 +124,8 @@ If an exception is raised, it will fail the example anyway.

```ruby
-> {
Fixnum
}.should complain(/constant ::Fixnum is deprecated/) # Expect a warning
Integer
}.should complain(/constant ::Integer is deprecated/) # Expect a warning
```

### Guards
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/command_line/dash_e_spec.rb
Expand Up @@ -23,7 +23,7 @@

#needs to test return => LocalJumpError

describe "with -n and a Fixnum range" do
describe "with -n and an Integer range" do
before :each do
@script = "-ne 'print if %s' #{fixture(__FILE__, "conditional_range.txt")}"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/argf/shared/fileno.rb
Expand Up @@ -11,7 +11,7 @@
# returns first current file even when not yet open
result << @argf.send(@method) while @argf.gets
# returns last current file even when closed
result.map { |d| d.class }.should == [Fixnum, Fixnum, Fixnum, Fixnum]
result.map { |d| d.class }.should == [Integer, Integer, Integer, Integer]
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/array/bsearch_index_spec.rb
Expand Up @@ -77,7 +77,7 @@
@array.bsearch_index { |x| (-1) * (2**100) }.should be_nil
end

it "handles values from Bignum#coerce" do
it "handles values from Integer#coerce" do
[1, 2].should include(@array.bsearch_index { |x| (2**100).coerce((1 - x / 4) * (2**100)).first })
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/array/first_spec.rb
Expand Up @@ -33,7 +33,7 @@
-> { [1, 2].first(-1) }.should raise_error(ArgumentError)
end

it "raises a RangeError when count is a Bignum" do
it "raises a RangeError when count is an Integer" do
-> { [].first(bignum_value) }.should raise_error(RangeError)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/array/fixtures/classes.rb
Expand Up @@ -126,7 +126,7 @@ def self.compared?
attr_accessor :order
end

class ComparableWithFixnum
class ComparableWithInteger
include Comparable
def initialize(num)
@num = num
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/array/hash_spec.rb
Expand Up @@ -7,7 +7,7 @@

[[], [1, 2, 3]].each do |ary|
ary.hash.should == ary.dup.hash
ary.hash.should be_an_instance_of(Fixnum)
ary.hash.should be_an_instance_of(Integer)
end
end

Expand Down
8 changes: 4 additions & 4 deletions spec/ruby/core/array/sample_spec.rb
Expand Up @@ -69,7 +69,7 @@
obj = mock("array_sample_random")
obj.should_receive(:rand).and_return(0.5)

[1, 2].sample(random: obj).should be_an_instance_of(Fixnum)
[1, 2].sample(random: obj).should be_an_instance_of(Integer)
end

it "raises a NoMethodError if an object passed for the RNG does not define #rand" do
Expand All @@ -78,8 +78,8 @@
-> { [1, 2].sample(random: obj) }.should raise_error(NoMethodError)
end

describe "when the object returned by #rand is a Fixnum" do
it "uses the fixnum as index" do
describe "when the object returned by #rand is an Integer" do
it "uses the integer as index" do
random = mock("array_sample_random_ret")
random.should_receive(:rand).and_return(0)

Expand Down Expand Up @@ -107,7 +107,7 @@
end
end

describe "when the object returned by #rand is not a Fixnum but responds to #to_int" do
describe "when the object returned by #rand is not an Integer but responds to #to_int" do
it "calls #to_int on the Object" do
value = mock("array_sample_random_value")
value.should_receive(:to_int).and_return(1)
Expand Down
4 changes: 2 additions & 2 deletions spec/ruby/core/array/shared/slice.rb
Expand Up @@ -486,7 +486,7 @@ def to.to_int() -2 end
end
end

it "raises a RangeError when the start index is out of range of Fixnum" do
it "raises a RangeError when the start index is out of range of Integer" do
array = [1, 2, 3, 4, 5, 6]
obj = mock('large value')
obj.should_receive(:to_int).and_return(bignum_value)
Expand All @@ -502,7 +502,7 @@ def to.to_int() -2 end
array.send(@method, max_long.to_f.prev_float).should == nil
end

it "raises a RangeError when the length is out of range of Fixnum" do
it "raises a RangeError when the length is out of range of Integer" do
array = [1, 2, 3, 4, 5, 6]
obj = mock('large value')
obj.should_receive(:to_int).and_return(bignum_value)
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/array/shared/union.rb
Expand Up @@ -31,7 +31,7 @@
[0].send(@method, obj).should == ([0] | [1, 2, 3])
end

# MRI follows hashing semantics here, so doesn't actually call eql?/hash for Fixnum/Symbol
# MRI follows hashing semantics here, so doesn't actually call eql?/hash for Integer/Symbol
it "acts as if using an intermediate hash to collect values" do
not_supported_on :opal do
[5.0, 4.0].send(@method, [5, 4]).should == [5.0, 4.0, 5, 4]
Expand Down
8 changes: 4 additions & 4 deletions spec/ruby/core/array/sort_spec.rb
Expand Up @@ -111,18 +111,18 @@
[1, 2, 3].sort{ break :a }.should == :a
end

it "uses the sign of Bignum block results as the sort result" do
it "uses the sign of Integer block results as the sort result" do
a = [1, 2, 5, 10, 7, -4, 12]
begin
class Bignum;
class Integer
alias old_spaceship <=>
def <=>(other)
raise
end
end
a.sort {|n, m| (n - m) * (2 ** 200)}.should == [-4, 1, 2, 5, 7, 10, 12]
ensure
class Bignum
class Integer
alias <=> old_spaceship
end
end
Expand All @@ -132,7 +132,7 @@ class Bignum
a = [1, 2, 5, 10, 7, -4, 12]
a.sort { |n, m| n - m }.should == [-4, 1, 2, 5, 7, 10, 12]
a.sort { |n, m|
ArraySpecs::ComparableWithFixnum.new(n-m)
ArraySpecs::ComparableWithInteger.new(n-m)
}.should == [-4, 1, 2, 5, 7, 10, 12]
-> {
a.sort { |n, m| (n - m).to_s }
Expand Down
8 changes: 4 additions & 4 deletions spec/ruby/core/basicobject/instance_eval_spec.rb
Expand Up @@ -131,14 +131,14 @@ class B; end
end

quarantine! do # Not clean, leaves cvars lying around to break other specs
it "scopes class var accesses in the caller when called on a Fixnum" do
# Fixnum can take instance vars
Fixnum.class_eval "@@__tmp_instance_eval_spec = 1"
it "scopes class var accesses in the caller when called on an Integer" do
# Integer can take instance vars
Integer.class_eval "@@__tmp_instance_eval_spec = 1"
(defined? @@__tmp_instance_eval_spec).should be_nil

@@__tmp_instance_eval_spec = 2
1.instance_eval { @@__tmp_instance_eval_spec }.should == 2
Fixnum.__send__(:remove_class_variable, :@@__tmp_instance_eval_spec)
Integer.__send__(:remove_class_variable, :@@__tmp_instance_eval_spec)
end
end

Expand Down
8 changes: 4 additions & 4 deletions spec/ruby/core/basicobject/instance_exec_spec.rb
Expand Up @@ -85,14 +85,14 @@ def foo
end

quarantine! do # Not clean, leaves cvars lying around to break other specs
it "scopes class var accesses in the caller when called on a Fixnum" do
# Fixnum can take instance vars
Fixnum.class_eval "@@__tmp_instance_exec_spec = 1"
it "scopes class var accesses in the caller when called on an Integer" do
# Integer can take instance vars
Integer.class_eval "@@__tmp_instance_exec_spec = 1"
(defined? @@__tmp_instance_exec_spec).should == nil

@@__tmp_instance_exec_spec = 2
1.instance_exec { @@__tmp_instance_exec_spec }.should == 2
Fixnum.__send__(:remove_class_variable, :@@__tmp_instance_exec_spec)
Integer.__send__(:remove_class_variable, :@@__tmp_instance_exec_spec)
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/ruby/core/builtin_constants/builtin_constants_spec.rb
Expand Up @@ -7,8 +7,8 @@
end

describe "RUBY_PATCHLEVEL" do
it "is a Fixnum" do
RUBY_PATCHLEVEL.should be_kind_of(Fixnum)
it "is an Integer" do
RUBY_PATCHLEVEL.should be_kind_of(Integer)
end
end

Expand Down Expand Up @@ -51,7 +51,7 @@
describe "RUBY_REVISION" do
ruby_version_is ""..."2.7" do
it "is an Integer" do
RUBY_REVISION.should be_kind_of(Fixnum)
RUBY_REVISION.should be_kind_of(Integer)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/class/initialize_spec.rb
Expand Up @@ -7,7 +7,7 @@

it "raises a TypeError when called on already initialized classes" do
->{
Fixnum.send :initialize
Integer.send :initialize
}.should raise_error(TypeError)

->{
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/class/superclass_spec.rb
Expand Up @@ -8,7 +8,7 @@
Class.superclass.should == Module
Class.new.superclass.should == Object
Class.new(String).superclass.should == String
Class.new(Fixnum).superclass.should == Fixnum
Class.new(Integer).superclass.should == Integer
end

# redmine:567
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/complex/coerce_spec.rb
Expand Up @@ -19,7 +19,7 @@
result.last.should be_kind_of(Complex)
end

it "returns an array containing other and self as Complex when other is a Bignum" do
it "returns an array containing other and self as Complex when other is an Integer" do
result = @one.coerce(4294967296)
result.should == [4294967296, 1]
result.first.should be_kind_of(Complex)
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/complex/equal_value_spec.rb
Expand Up @@ -53,7 +53,7 @@
end

describe "with Object" do
# Fixnum#==, Float#== and Bignum#== only return booleans - Bug?
# Integer#== and Float#== only return booleans - Bug?
it "calls other#== with self" do
value = Complex(3, 0)

Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/complex/exponent_spec.rb
@@ -1,7 +1,7 @@
require_relative '../../spec_helper'

describe "Complex#**" do
describe "with Fixnum 0" do
describe "with Integer 0" do
it "returns Complex(1)" do
(Complex(3, 4) ** 0).should eql(Complex(1))
end
Expand Down
4 changes: 2 additions & 2 deletions spec/ruby/core/complex/shared/divide.rb
Expand Up @@ -12,7 +12,7 @@
end
end

describe "with Fixnum" do
describe "with Integer" do
it "divides both parts of the Complex number" do
Complex(20, 40).send(@method, 2).should == Complex(10, 20)
Complex(30, 30).send(@method, 10).should == Complex(3, 3)
Expand All @@ -27,7 +27,7 @@
end
end

describe "with Bignum" do
describe "with Integer" do
it "divides both parts of the Complex number" do
Complex(20, 40).send(@method, 2).should == Complex(10, 20)
Complex(15, 16).send(@method, 2.0).should be_close(Complex(7.5, 8), TOLERANCE)
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/complex/to_f_spec.rb
@@ -1,7 +1,7 @@
require_relative '../../spec_helper'

describe "Complex#to_f" do
describe "when the imaginary part is Fixnum 0" do
describe "when the imaginary part is Integer 0" do
it "returns the result of sending #to_f to the real part" do
real = mock_numeric('real')
real.should_receive(:to_f).and_return(:f)
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/complex/to_i_spec.rb
@@ -1,7 +1,7 @@
require_relative '../../spec_helper'

describe "Complex#to_i" do
describe "when the imaginary part is Fixnum 0" do
describe "when the imaginary part is Integer 0" do
it "returns the result of sending #to_i to the real part" do
real = mock_numeric('real')
real.should_receive(:to_i).and_return(:i)
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/complex/to_r_spec.rb
@@ -1,7 +1,7 @@
require_relative '../../spec_helper'

describe "Complex#to_r" do
describe "when the imaginary part is Fixnum 0" do
describe "when the imaginary part is Integer 0" do
it "returns the result of sending #to_r to the real part" do
real = mock_numeric('real')
real.should_receive(:to_r).and_return(:r)
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/dir/fileno_spec.rb
Expand Up @@ -27,7 +27,7 @@

if has_dir_fileno
it "returns the file descriptor of the dir" do
@dir.fileno.should be_kind_of(Fixnum)
@dir.fileno.should be_kind_of(Integer)
end
else
it "raises an error when not implemented on the platform" do
Expand Down

0 comments on commit 9c73c75

Please sign in to comment.