Skip to content
17 changes: 17 additions & 0 deletions spec/std/string_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ describe "String" do
it "gets byte_slice with negative index" do
"hello".byte_slice(-2, 3).should eq("lo")
end

it "gets byte_slice(Int) with start out of bounds" do
expect_raises(IndexError) do
"hello".byte_slice(10)
end
expect_raises(IndexError) do
"hello".byte_slice(-10)
end
end
end

describe "to_i" do
Expand Down Expand Up @@ -920,6 +929,14 @@ describe "String" do
it { "foo".byte_index('o'.ord).should eq(1) }
it { "foo bar booz".byte_index('o'.ord, 3).should eq(9) }
it { "foo".byte_index('a'.ord).should be_nil }
it { "foo".byte_index('a'.ord).should be_nil }
it { "foo".byte_index('o'.ord, 3).should be_nil }
it {
"Dizzy Miss Lizzy".byte_index('z'.ord).should eq(2)
"Dizzy Miss Lizzy".byte_index('z'.ord, 3).should eq(3)
"Dizzy Miss Lizzy".byte_index('z'.ord, -4).should eq(13)
"Dizzy Miss Lizzy".byte_index('z'.ord, -17).should be_nil
}

it "gets byte index of string" do
"hello world".byte_index("he").should eq(0)
Expand Down
Loading