Skip to content

Commit

Permalink
Add specs for String#index, #rindex search for Char::REPLACEMENT (
Browse files Browse the repository at this point in the history
#14946)

Co-authored-by: Quinton Miller <[email protected]>
  • Loading branch information
straight-shoota and HertzDevil authored Sep 3, 2024
1 parent e6b5b94 commit 281fc32
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/std/string_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ describe "String" do
it { "bar".index('あ').should be_nil }
it { "あいう_えお".index('_').should eq(3) }
it { "xyz\xFFxyz".index('\u{FFFD}').should eq(3) }
it { "\xFF".index('\u{FFFD}').should eq(1) }

describe "with offset" do
it { "foobarbaz".index('a', 5).should eq(7) }
Expand All @@ -967,6 +968,8 @@ describe "String" do
it { "日本語日本語".index('本', 2).should eq(4) }
it { "xyz\xFFxyz".index('\u{FFFD}', 2).should eq(3) }
it { "xyz\xFFxyz".index('\u{FFFD}', 4).should be_nil }
it { "日本\xFF".index('\u{FFFD}', 2).should eq(2) }
it { "日本\xFF".index('\u{FFFD}', 3).should be_nil }

# Check offset type
it { "foobarbaz".index('a', 5_i64).should eq(7) }
Expand Down Expand Up @@ -1110,6 +1113,7 @@ describe "String" do
it { "日本語日本語".rindex('本').should eq(4) }
it { "あいう_えお".rindex('_').should eq(3) }
it { "xyz\xFFxyz".rindex('\u{FFFD}').should eq(3) }
it { "\xFF".rindex('\u{FFFD}').should eq(1) }

describe "with offset" do
it { "bbbb".rindex('b', 2).should eq(2) }
Expand All @@ -1124,6 +1128,8 @@ describe "String" do
it { "日本語日本語".rindex('本', 3).should eq(1) }
it { "xyz\xFFxyz".rindex('\u{FFFD}', 4).should eq(3) }
it { "xyz\xFFxyz".rindex('\u{FFFD}', 2).should be_nil }
it { "日本\xFF".rindex('\u{FFFD}', 2).should eq(2) }
it { "日本\xFF".rindex('\u{FFFD}', 1).should be_nil }

# Check offset type
it { "bbbb".rindex('b', 2_i64).should eq(2) }
Expand Down

0 comments on commit 281fc32

Please sign in to comment.