aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/library
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-03-28 14:22:29 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-03-28 14:22:29 +0000
commita28aa80c739a1d169649a4da833ef48cfb3465b3 (patch)
treec2f6bb79c268bd60116b54319ea96f01bb7dda79 /spec/ruby/library
parent0f64776745ef31e626dec0d42b7fb2a5988397ec (diff)
downloadruby-a28aa80c739a1d169649a4da833ef48cfb3465b3.tar.gz
Update to ruby/spec@e81b3cd
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library')
-rw-r--r--spec/ruby/library/bigdecimal/add_spec.rb8
-rw-r--r--spec/ruby/library/bigdecimal/div_spec.rb8
-rw-r--r--spec/ruby/library/bigdecimal/mult_spec.rb10
-rw-r--r--spec/ruby/library/bigdecimal/multiply_spec.rb8
-rw-r--r--spec/ruby/library/bigdecimal/remainder_spec.rb12
-rw-r--r--spec/ruby/library/bigdecimal/shared/modulo.rb9
-rw-r--r--spec/ruby/library/bigdecimal/shared/quo.rb8
-rw-r--r--spec/ruby/library/bigdecimal/sub_spec.rb10
-rw-r--r--spec/ruby/library/bigdecimal/util_spec.rb42
-rw-r--r--spec/ruby/library/rbconfig/rbconfig_spec.rb2
10 files changed, 113 insertions, 4 deletions
diff --git a/spec/ruby/library/bigdecimal/add_spec.rb b/spec/ruby/library/bigdecimal/add_spec.rb
index 024dd576cc..1ae5b7f428 100644
--- a/spec/ruby/library/bigdecimal/add_spec.rb
+++ b/spec/ruby/library/bigdecimal/add_spec.rb
@@ -73,6 +73,14 @@ describe "BigDecimal#add" do
# BigDecimal("0.88").add(0.0, 1).should == BigDecimal("0.9")
# end
+ describe "with Object" do
+ it "tries to coerce the other operand to self" do
+ object = mock("Object")
+ object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4])
+ @frac_3.add(object, 1).should == BigDecimal("0.1E16")
+ end
+ end
+
it "favors the precision specified in the second argument over the global limit" do
BigDecimalSpecs.with_limit(1) do
BigDecimal('0.888').add(@zero, 3).should == BigDecimal('0.888')
diff --git a/spec/ruby/library/bigdecimal/div_spec.rb b/spec/ruby/library/bigdecimal/div_spec.rb
index a774376f55..23d1ae1efd 100644
--- a/spec/ruby/library/bigdecimal/div_spec.rb
+++ b/spec/ruby/library/bigdecimal/div_spec.rb
@@ -42,6 +42,14 @@ describe "BigDecimal#div" do
}
end
+ describe "with Object" do
+ it "tries to coerce the other operand to self" do
+ object = mock("Object")
+ object.should_receive(:coerce).with(@one).and_return([@one, @two])
+ @one.div(object).should == @zero
+ end
+ end
+
it "raises FloatDomainError if NaN is involved" do
lambda { @one.div(@nan) }.should raise_error(FloatDomainError)
lambda { @nan.div(@one) }.should raise_error(FloatDomainError)
diff --git a/spec/ruby/library/bigdecimal/mult_spec.rb b/spec/ruby/library/bigdecimal/mult_spec.rb
index a4c1602182..b7f8044b0b 100644
--- a/spec/ruby/library/bigdecimal/mult_spec.rb
+++ b/spec/ruby/library/bigdecimal/mult_spec.rb
@@ -9,7 +9,8 @@ end
describe "BigDecimal#mult" do
before :each do
@one = BigDecimal "1"
- @e3_minus = BigDecimal "3E-20001"
+ @e3_minus = BigDecimal("3E-20001")
+ @e3_plus = BigDecimal("3E20001")
@e = BigDecimal "1.00000000000000000000123456789"
@tolerance = @e.sub @one, 1000
@tolerance2 = BigDecimal "30001E-20005"
@@ -21,4 +22,11 @@ describe "BigDecimal#mult" do
@e3_minus.mult(@one, 1).should be_close(0, @tolerance2)
end
+ describe "with Object" do
+ it "tries to coerce the other operand to self" do
+ object = mock("Object")
+ object.should_receive(:coerce).with(@e3_minus).and_return([@e3_minus, @e3_plus])
+ @e3_minus.mult(object, 1).should == BigDecimal("9")
+ end
+ end
end
diff --git a/spec/ruby/library/bigdecimal/multiply_spec.rb b/spec/ruby/library/bigdecimal/multiply_spec.rb
index 2741d3623e..4e5a8d6681 100644
--- a/spec/ruby/library/bigdecimal/multiply_spec.rb
+++ b/spec/ruby/library/bigdecimal/multiply_spec.rb
@@ -23,4 +23,12 @@ describe "BigDecimal#*" do
(@e3_minus * @e3_minus).should == BigDecimal("9E-40002")
(@e * @one).should == @e
end
+
+ describe "with Object" do
+ it "tries to coerce the other operand to self" do
+ object = mock("Object")
+ object.should_receive(:coerce).with(@e3_minus).and_return([@e3_minus, @e3_plus])
+ (@e3_minus * object).should == BigDecimal("9")
+ end
+ end
end
diff --git a/spec/ruby/library/bigdecimal/remainder_spec.rb b/spec/ruby/library/bigdecimal/remainder_spec.rb
index 28b25f8566..8626064a2f 100644
--- a/spec/ruby/library/bigdecimal/remainder_spec.rb
+++ b/spec/ruby/library/bigdecimal/remainder_spec.rb
@@ -5,7 +5,8 @@ describe "BigDecimal#remainder" do
before :each do
@zero = BigDecimal("0")
- @one = BigDecimal("0")
+ @one = BigDecimal("1")
+ @three = BigDecimal("3")
@mixed = BigDecimal("1.23456789")
@pos_int = BigDecimal("2E5555")
@neg_int = BigDecimal("-2E5555")
@@ -71,9 +72,16 @@ describe "BigDecimal#remainder" do
end
it "coerces arguments to BigDecimal if possible" do
- @one.remainder(2).should == @one
+ @three.remainder(2).should == @one
end
+ describe "with Object" do
+ it "tries to coerce the other operand to self" do
+ object = mock("Object")
+ object.should_receive(:coerce).with(@three).and_return([@three, 2])
+ @three.remainder(object).should == @one
+ end
+ end
it "raises TypeError if the argument cannot be coerced to BigDecimal" do
lambda {
diff --git a/spec/ruby/library/bigdecimal/shared/modulo.rb b/spec/ruby/library/bigdecimal/shared/modulo.rb
index c9691cbf37..d570b86d7a 100644
--- a/spec/ruby/library/bigdecimal/shared/modulo.rb
+++ b/spec/ruby/library/bigdecimal/shared/modulo.rb
@@ -70,6 +70,15 @@ describe :bigdecimal_modulo, shared: true do
res.kind_of?(BigDecimal).should == true
end
+ describe "with Object" do
+ it "tries to coerce the other operand to self" do
+ bd6543 = BigDecimal("6543.21")
+ object = mock("Object")
+ object.should_receive(:coerce).with(bd6543).and_return([bd6543, 137])
+ bd6543.send(@method, object, *@object).should == BigDecimal("104.21")
+ end
+ end
+
it "returns NaN if NaN is involved" do
@nan.send(@method, @nan).nan?.should == true
@nan.send(@method, @one).nan?.should == true
diff --git a/spec/ruby/library/bigdecimal/shared/quo.rb b/spec/ruby/library/bigdecimal/shared/quo.rb
index cb51c10d71..4d6d64b787 100644
--- a/spec/ruby/library/bigdecimal/shared/quo.rb
+++ b/spec/ruby/library/bigdecimal/shared/quo.rb
@@ -29,6 +29,14 @@ describe :bigdecimal_quo, shared: true do
@one.send(@method, BigDecimal('2E-5555'), *@object).should == BigDecimal('0.5E5555')
end
+ describe "with Object" do
+ it "tries to coerce the other operand to self" do
+ object = mock("Object")
+ object.should_receive(:coerce).with(@one).and_return([@one, @two])
+ @one.send(@method, object, *@object).should == BigDecimal("0.5")
+ end
+ end
+
it "returns 0 if divided by Infinity" do
@zero.send(@method, @infinity, *@object).should == 0
@frac_2.send(@method, @infinity, *@object).should == 0
diff --git a/spec/ruby/library/bigdecimal/sub_spec.rb b/spec/ruby/library/bigdecimal/sub_spec.rb
index 7f0305a1c6..f0068b12a9 100644
--- a/spec/ruby/library/bigdecimal/sub_spec.rb
+++ b/spec/ruby/library/bigdecimal/sub_spec.rb
@@ -13,6 +13,8 @@ describe "BigDecimal#sub" do
@one_minus = BigDecimal("-1")
@frac_1 = BigDecimal("1E-99999")
@frac_2 = BigDecimal("0.9E-99999")
+ @frac_3 = BigDecimal("12345E10")
+ @frac_4 = BigDecimal("98765E10")
end
it "returns a - b with given precision" do
@@ -32,6 +34,14 @@ describe "BigDecimal#sub" do
@frac_1.sub(@frac_1, 1000000).should == @zero
end
+ describe "with Object" do
+ it "tries to coerce the other operand to self" do
+ object = mock("Object")
+ object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4])
+ @frac_3.sub(object, 1).should == BigDecimal("-0.9E15")
+ end
+ end
+
it "returns NaN if NaN is involved" do
@one.sub(@nan, 1).nan?.should == true
@nan.sub(@one, 1).nan?.should == true
diff --git a/spec/ruby/library/bigdecimal/util_spec.rb b/spec/ruby/library/bigdecimal/util_spec.rb
new file mode 100644
index 0000000000..f41e131144
--- /dev/null
+++ b/spec/ruby/library/bigdecimal/util_spec.rb
@@ -0,0 +1,42 @@
+require_relative '../../spec_helper'
+require 'bigdecimal'
+require 'bigdecimal/util'
+
+describe "BigDecimal's util method definitions" do
+ describe "#to_d" do
+ it "should define #to_d on Integer" do
+ 42.to_d.should == BigDecimal(42)
+ end
+
+ it "should define #to_d on Float" do
+ 0.5.to_d.should == BigDecimal(0.5, Float::DIG)
+ 1.234.to_d(2).should == BigDecimal(1.234, 2)
+ end
+
+ it "should define #to_d on String" do
+ "0.5".to_d.should == BigDecimal(0.5, Float::DIG)
+ "45.67 degrees".to_d.should == BigDecimal(45.67, Float::DIG)
+ end
+
+ it "should define #to_d on BigDecimal" do
+ bd = BigDecimal("3.14")
+ bd.to_d.should equal(bd)
+ end
+
+ it "should define #to_d on Rational" do
+ Rational(22, 7).to_d(3).should == BigDecimal(3.14, 3)
+ end
+
+ ruby_version_is "2.6" do
+ it "should define #to_d on nil" do
+ nil.to_d.should == BigDecimal(0)
+ end
+ end
+ end
+
+ describe "#to_digits" do
+ it "should define #to_digits on BigDecimal" do
+ BigDecimal("3.14").to_digits.should == "3.14"
+ end
+ end
+end
diff --git a/spec/ruby/library/rbconfig/rbconfig_spec.rb b/spec/ruby/library/rbconfig/rbconfig_spec.rb
index 8fa63b6e27..71e3d376d1 100644
--- a/spec/ruby/library/rbconfig/rbconfig_spec.rb
+++ b/spec/ruby/library/rbconfig/rbconfig_spec.rb
@@ -10,7 +10,7 @@ describe 'RbConfig::CONFIG' do
end
# These directories have no meanings before the installation.
- if RbConfig::TOPDIR
+ guard -> { RbConfig::TOPDIR } do
it "['rubylibdir'] returns the directory containing Ruby standard libraries" do
rubylibdir = RbConfig::CONFIG['rubylibdir']
File.directory?(rubylibdir).should == true