Skip to content

Commit 70e8654

Browse files
committed
1 parent 8d6c676 commit 70e8654

26 files changed

+368
-18
lines changed

spec/ruby/core/encoding/compatible_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,11 @@
557557
[Encoding, "\x82\xa0".dup.force_encoding("shift_jis"), Encoding::Shift_JIS],
558558
].should be_computed_by(:compatible?, /abc/)
559559
end
560+
561+
it "returns the Regexp's Encoding if the String is ASCII only and the Regexp is not" do
562+
r = Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp"))
563+
Encoding.compatible?("hello".dup.force_encoding("utf-8"), r).should == Encoding::EUC_JP
564+
end
560565
end
561566

562567
describe "Encoding.compatible? String, Symbol" do
@@ -619,6 +624,15 @@
619624
Encoding.compatible?(/abc/, str).should == Encoding::US_ASCII
620625
end
621626

627+
it "returns the String's Encoding when the String is ASCII only with a different encoding" do
628+
r = Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp"))
629+
Encoding.compatible?(r, "hello".dup.force_encoding("utf-8")).should == Encoding::UTF_8
630+
end
631+
632+
it "returns the Regexp's Encoding if the String has the same non-ASCII encoding" do
633+
r = Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp"))
634+
Encoding.compatible?(r, "hello".dup.force_encoding("euc-jp")).should == Encoding::EUC_JP
635+
end
622636
end
623637

624638
describe "Encoding.compatible? Regexp, Regexp" do

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

spec/ruby/core/integer/lte_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,10 @@
4949
-> { @bignum <= "4" }.should raise_error(ArgumentError)
5050
-> { @bignum <= mock('str') }.should raise_error(ArgumentError)
5151
end
52+
53+
it "dispatches the correct operator after coercion" do
54+
(bignum_value <= IntegerSpecs::CoercibleNumeric.new(bignum_value * 2)).should == true
55+
(bignum_value <= IntegerSpecs::CoercibleNumeric.new(1)).should == false
56+
end
5257
end
5358
end

spec/ruby/core/integer/shared/equal.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,10 @@
5454
@bignum.send(@method, obj).should == true
5555
@bignum.send(@method, obj).should == false
5656
end
57+
58+
it "does not lose precision when comparing with a Float" do
59+
(bignum_value(1).send(@method, bignum_value.to_f)).should == false
60+
(bignum_value.send(@method, bignum_value.to_f)).should == true
61+
end
5762
end
5863
end

spec/ruby/core/kernel/fixtures/classes.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,25 @@ class B < A
180180
alias aliased_pub_method pub_method
181181
end
182182

183+
class BasicA < BasicObject
184+
define_method(:respond_to?, ::Kernel.instance_method(:respond_to?))
185+
186+
def pub_method; :public_method; end
187+
188+
def undefed_method; :undefed_method; end
189+
undef_method :undefed_method
190+
191+
protected
192+
def protected_method; :protected_method; end
193+
194+
private
195+
def private_method; :private_method; end
196+
end
197+
198+
class MissingA < A
199+
undef :respond_to_missing?
200+
end
201+
183202
class VisibilityChange
184203
class << self
185204
private :new

0 commit comments

Comments
 (0)