aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-28 10:32:45 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-28 10:32:45 +0000
commit1cb29f1cd20a55a22eefe61b0ebba4f8adf28b8d (patch)
tree145065e09ae16772c08748182441531e9b7ea66d /spec
parente6447c022936a2a28de5c719153dcc945774a425 (diff)
downloadruby-1cb29f1cd20a55a22eefe61b0ebba4f8adf28b8d.tar.gz
Add specs for [Feature #13983] Rational and Complex should be frozen
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60505 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/core/kernel/freeze_spec.rb18
-rw-r--r--spec/ruby/core/kernel/frozen_spec.rb26
-rw-r--r--spec/ruby/core/kernel/shared/dup_clone.rb24
3 files changed, 68 insertions, 0 deletions
diff --git a/spec/ruby/core/kernel/freeze_spec.rb b/spec/ruby/core/kernel/freeze_spec.rb
index 961c1bccf0..cf16512094 100644
--- a/spec/ruby/core/kernel/freeze_spec.rb
+++ b/spec/ruby/core/kernel/freeze_spec.rb
@@ -51,6 +51,24 @@ describe "Kernel#freeze" do
end
end
+ ruby_version_is "2.5" do
+ describe "on a Complex" do
+ it "has no effect since it is already frozen" do
+ c = Complex(1.3, 3.1)
+ c.frozen?.should be_true
+ c.freeze
+ end
+ end
+
+ describe "on a Rational" do
+ it "has no effect since it is already frozen" do
+ r = Rational(1, 3)
+ r.frozen?.should be_true
+ r.freeze
+ end
+ end
+ end
+
it "causes mutative calls to raise RuntimeError" do
o = Class.new do
def mutate; @foo = 1; end
diff --git a/spec/ruby/core/kernel/frozen_spec.rb b/spec/ruby/core/kernel/frozen_spec.rb
index 9444b62249..fad1971985 100644
--- a/spec/ruby/core/kernel/frozen_spec.rb
+++ b/spec/ruby/core/kernel/frozen_spec.rb
@@ -49,4 +49,30 @@ describe "Kernel#frozen?" do
@symbol.frozen?.should be_true
end
end
+
+ ruby_version_is "2.5" do
+ describe "on a Complex" do
+ it "returns true" do
+ c = Complex(1.3, 3.1)
+ c.frozen?.should be_true
+ end
+
+ it "literal returns true" do
+ c = eval "1.3i"
+ c.frozen?.should be_true
+ end
+ end
+
+ describe "on a Rational" do
+ it "returns true" do
+ r = Rational(1, 3)
+ r.frozen?.should be_true
+ end
+
+ it "literal returns true" do
+ r = eval "1/3r"
+ r.frozen?.should be_true
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/shared/dup_clone.rb b/spec/ruby/core/kernel/shared/dup_clone.rb
index 320da8fc38..116989958b 100644
--- a/spec/ruby/core/kernel/shared/dup_clone.rb
+++ b/spec/ruby/core/kernel/shared/dup_clone.rb
@@ -122,4 +122,28 @@ describe :kernel_dup_clone, shared: true do
:my_symbol.send(@method).should == :my_symbol
end
end
+
+ ruby_version_is ''...'2.5' do
+ it "raises a TypeError for Complex" do
+ c = Complex(1.3, 3.1)
+ lambda { c.send(@method) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError for Rational" do
+ r = Rational(1, 3)
+ lambda { r.send(@method) }.should raise_error(TypeError)
+ end
+ end
+
+ ruby_version_is '2.5' do
+ it "returns self for Complex" do
+ c = Complex(1.3, 3.1)
+ c.send(@method).should equal c
+ end
+
+ it "returns self for Rational" do
+ r = Rational(1, 3)
+ r.send(@method).should equal r
+ end
+ end
end