From 2bc293e899c9d32dcd794a73de8925c49ecf8f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Fri, 7 May 2021 10:04:08 +0900 Subject: cdhash_cmp: can take rational literals Rational literals are those integers suffixed with `r`. They tend to be a part of more complex expressions like `123/456r`, but in theory they can live alone. When such "bare" rational literals are passed to case-when branch, we have to take care of them. Fixes [Bug #17854] --- test/ruby/test_rational.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/ruby/test_rational.rb') diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb index fe9de64c4c..d7f4961214 100644 --- a/test/ruby/test_rational.rb +++ b/test/ruby/test_rational.rb @@ -830,6 +830,13 @@ class Rational_Test < Test::Unit::TestCase assert_raise(ZeroDivisionError) {Rational("1/0")} end + def test_cdhash + assert_separately([], <<-RUBY) + n = case 1 when 2r then false else true end + assert_equal(n, true, '[ruby-core:103759] [Bug #17854]') + RUBY + end + def test_Rational_with_invalid_exception assert_raise(ArgumentError) { Rational("1/1", exception: 1) -- cgit v1.2.3