ruby-changes:48391
From: eregon <ko1@a...>
Date: Sat, 28 Oct 2017 19:32:50 +0900 (JST)
Subject: [ruby-changes:48391] eregon:r60505 (trunk): Add specs for [Feature #13983] Rational and Complex should be frozen
eregon 2017-10-28 19:32:45 +0900 (Sat, 28 Oct 2017) New Revision: 60505 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60505 Log: Add specs for [Feature #13983] Rational and Complex should be frozen Modified files: trunk/spec/ruby/core/kernel/freeze_spec.rb trunk/spec/ruby/core/kernel/frozen_spec.rb trunk/spec/ruby/core/kernel/shared/dup_clone.rb Index: spec/ruby/core/kernel/shared/dup_clone.rb =================================================================== --- spec/ruby/core/kernel/shared/dup_clone.rb (revision 60504) +++ spec/ruby/core/kernel/shared/dup_clone.rb (revision 60505) @@ -122,4 +122,28 @@ describe :kernel_dup_clone, shared: true https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/shared/dup_clone.rb#L122 :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 Index: spec/ruby/core/kernel/frozen_spec.rb =================================================================== --- spec/ruby/core/kernel/frozen_spec.rb (revision 60504) +++ spec/ruby/core/kernel/frozen_spec.rb (revision 60505) @@ -49,4 +49,30 @@ describe "Kernel#frozen?" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/frozen_spec.rb#L49 @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 Index: spec/ruby/core/kernel/freeze_spec.rb =================================================================== --- spec/ruby/core/kernel/freeze_spec.rb (revision 60504) +++ spec/ruby/core/kernel/freeze_spec.rb (revision 60505) @@ -51,6 +51,24 @@ describe "Kernel#freeze" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/freeze_spec.rb#L51 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/