From e61095426bbb0de2ab0a941f9ed3a3acdb7833e8 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Thu, 19 Sep 2019 20:19:38 +0900 Subject: Simplify arguments check in `String#index` Also fix document about type of the first argument. --- test/t/string.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test') diff --git a/test/t/string.rb b/test/t/string.rb index c820bfa92..01f3da327 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -451,12 +451,16 @@ assert('String#index', '15.2.10.5.22') do assert_equal 3, 'abcabc'.index('a', 1) assert_equal 5, "hello".index("", 5) assert_equal nil, "hello".index("", 6) + assert_equal 3, "hello".index("l", -2) + assert_raise(ArgumentError) { "hello".index } + assert_raise(TypeError) { "hello".index(101) } end assert('String#index(UTF-8)', '15.2.10.5.22') do assert_equal 0, '⓿➊➋➌➍➎'.index('⓿') assert_nil '⓿➊➋➌➍➎'.index('➓') assert_equal 6, '⓿➊➋➌➍➎⓿➊➋➌➍➎'.index('⓿', 1) + assert_equal 6, '⓿➊➋➌➍➎⓿➊➋➌➍➎'.index('⓿', -7) assert_equal 6, "⓿➊➋➌➍➎".index("", 6) assert_equal nil, "⓿➊➋➌➍➎".index("", 7) assert_equal 0, '⓿➊➋➌➍➎'.index("\xe2") -- cgit v1.2.3