File tree 2 files changed +5
-2
lines changed
2 files changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -546,6 +546,7 @@ describe "String" do
546
546
assert { " bar" .index('r' ).should eq(2 ) }
547
547
assert { " 日本語" .index('本' ).should eq(1 ) }
548
548
assert { " bar" .index('あ' ).should be_nil }
549
+ assert { " あいう_えお" .index('_' ).should eq(3 ) }
549
550
550
551
describe " with offset" do
551
552
assert { " foobarbaz" .index('a' , 5 ).should eq(7 ) }
@@ -594,6 +595,7 @@ describe "String" do
594
595
assert { " foobar" .rindex('a' ).should eq(4 ) }
595
596
assert { " foobar" .rindex('g' ).should be_nil }
596
597
assert { " 日本語日本語" .rindex('本' ).should eq(4 ) }
598
+ assert { " あいう_えお" .rindex('_' ).should eq(3 ) }
597
599
598
600
describe " with offset" do
599
601
assert { " faobar" .rindex('a' , 3 ).should eq(1 ) }
@@ -801,6 +803,7 @@ describe "String" do
801
803
assert { " foobar" .ends_with?('x' ).should be_false }
802
804
assert { " よし" .ends_with?('し' ).should be_true }
803
805
assert { " よし" .ends_with?('な' ).should be_false }
806
+ assert { " あいう_" .ends_with?('_' ).should be_true }
804
807
end
805
808
806
809
describe " =~" do
Original file line number Diff line number Diff line change @@ -2093,7 +2093,7 @@ class String
2093
2093
# ```
2094
2094
def index (search : Char , offset = 0 )
2095
2095
# If it's ASCII we can delegate to slice
2096
- if search.ascii?
2096
+ if search.ascii? && ascii_only?
2097
2097
return to_slice.index(search.ord.to_u8, offset)
2098
2098
end
2099
2099
@@ -2150,7 +2150,7 @@ class String
2150
2150
# ```
2151
2151
def rindex (search : Char , offset = size - 1 )
2152
2152
# If it's ASCII we can delegate to slice
2153
- if search.ascii?
2153
+ if search.ascii? && ascii_only?
2154
2154
return to_slice.rindex(search.ord.to_u8, offset)
2155
2155
end
2156
2156
You can’t perform that action at this time.
0 commit comments