Skip to content

Commit

Permalink
[Bug #20296] Refine the test
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Feb 26, 2024
1 parent dc146ba commit f23d502
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions test/ruby/test_complex.rb
Expand Up @@ -980,17 +980,27 @@ def test_Complex_with_invalid_exception
}
end

def test_Complex_without_exception
assert_complex_without_exception('5x')
assert_complex_without_exception(nil)
assert_complex_without_exception(Object.new)
assert_complex_without_exception(1, nil)
assert_complex_without_exception(1, Object.new)
def assert_complex_with_exception(error, *args, message: nil)
assert_raise(error, message) do
Complex(*args, exception: true)
end
assert_nothing_raised(error, message) do
assert_nil(Complex(*args, exception: false))
assert_nil($!)
end
end

def test_Complex_with_exception
assert_complex_with_exception(ArgumentError, '5x')
assert_complex_with_exception(TypeError, nil)
assert_complex_with_exception(TypeError, Object.new)
assert_complex_with_exception(TypeError, 1, nil)
assert_complex_with_exception(TypeError, 1, Object.new)

o = Object.new
def o.to_c; raise; end
assert_complex_without_exception(o)
assert_complex_without_exception(1, o)
assert_complex_with_exception(RuntimeError, o)
assert_complex_with_exception(TypeError, 1, o)
end

def test_respond
Expand Down Expand Up @@ -1249,13 +1259,4 @@ def real?
Complex.polar(1, obj)
end
end

private

def assert_complex_without_exception(*args)
assert_nothing_raised(ArgumentError) do
assert_nil(Complex(*args, exception: false))
assert_nil($!)
end
end
end

0 comments on commit f23d502

Please sign in to comment.