diff options
Diffstat (limited to 'spec/ruby/core/complex/inspect_spec.rb')
-rw-r--r-- | spec/ruby/core/complex/inspect_spec.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/ruby/core/complex/inspect_spec.rb b/spec/ruby/core/complex/inspect_spec.rb index 71aabde5be..045be94b22 100644 --- a/spec/ruby/core/complex/inspect_spec.rb +++ b/spec/ruby/core/complex/inspect_spec.rb @@ -1,4 +1,5 @@ require_relative '../../spec_helper' +require_relative '../numeric/fixtures/classes' describe "Complex#inspect" do it "returns (${real}+${image}i) for positive imaginary parts" do @@ -13,4 +14,24 @@ describe "Complex#inspect" do Complex(-1, -4).inspect.should == "(-1-4i)" Complex(-7, -6.7).inspect.should == "(-7-6.7i)" end + + it "calls #inspect on real and imaginary" do + real = NumericSpecs::Subclass.new + # + because of https://bugs.ruby-lang.org/issues/20337 + real.should_receive(:inspect).and_return(+"1") + imaginary = NumericSpecs::Subclass.new + imaginary.should_receive(:inspect).and_return("2") + imaginary.should_receive(:<).any_number_of_times.and_return(false) + Complex(real, imaginary).inspect.should == "(1+2i)" + end + + it "adds an `*' before the `i' if the last character of the imaginary part is not numeric" do + real = NumericSpecs::Subclass.new + # + because of https://bugs.ruby-lang.org/issues/20337 + real.should_receive(:inspect).and_return(+"(1)") + imaginary = NumericSpecs::Subclass.new + imaginary.should_receive(:inspect).and_return("(2)") + imaginary.should_receive(:<).any_number_of_times.and_return(false) + Complex(real, imaginary).inspect.should == "((1)+(2)*i)" + end end |