summaryrefslogtreecommitdiff
path: root/test/ruby/test_complex.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-08-31 11:01:59 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-09-02 14:33:23 +0900
commit9212d963070612e669c40e5fde7954f19d648002 (patch)
treeedffc38b5c9350989e767fcb0059bf04203c9f1d /test/ruby/test_complex.rb
parenta9b59e24f49f669f6ad2f3238c4c518027a7f72d (diff)
[Bug #18937] Coerce non-real non-Numeric into Complex at comparisons
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6317
Diffstat (limited to 'test/ruby/test_complex.rb')
-rw-r--r--test/ruby/test_complex.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb
index f85bf101e0..13511fd4cf 100644
--- a/test/ruby/test_complex.rb
+++ b/test/ruby/test_complex.rb
@@ -568,19 +568,23 @@ class Complex_Test < Test::Unit::TestCase
end
class ObjectX
- def +(x) Rational(1) end
+ def initialize(real = true, n = 1) @n = n; @real = real; end
+ def +(x) Rational(@n) end
alias - +
alias * +
alias / +
alias quo +
alias ** +
- def coerce(x) [x, Complex(1)] end
+ def coerce(x) [x, Complex(@n)] end
+ def real?; @real; end
end
def test_coerce2
x = ObjectX.new
+ y = ObjectX.new(false)
%w(+ - * / quo ** <=>).each do |op|
- assert_kind_of(Numeric, Complex(1).__send__(op, x))
+ assert_kind_of(Numeric, Complex(1).__send__(op, x), op)
+ assert_kind_of(Numeric, Complex(1).__send__(op, y), op)
end
end