2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
|
|
|
require_relative 'fixtures/classes'
|
2021-10-05 13:41:44 -04:00
|
|
|
require_relative 'shared/strip'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "String#lstrip" do
|
2021-10-05 13:41:44 -04:00
|
|
|
it_behaves_like :string_strip, :lstrip
|
|
|
|
|
2017-05-07 08:04:49 -04:00
|
|
|
it "returns a copy of self with leading whitespace removed" do
|
|
|
|
" hello ".lstrip.should == "hello "
|
|
|
|
" hello world ".lstrip.should == "hello world "
|
|
|
|
"\n\r\t\n\v\r hello world ".lstrip.should == "hello world "
|
|
|
|
"hello".lstrip.should == "hello"
|
|
|
|
end
|
|
|
|
|
2022-03-28 11:47:04 -04:00
|
|
|
ruby_version_is '3.0' do
|
2021-02-09 16:50:36 -05:00
|
|
|
it "strips leading \\0" do
|
|
|
|
"\x00hello".lstrip.should == "hello"
|
|
|
|
"\000 \000hello\000 \000".lstrip.should == "hello\000 \000"
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "String#lstrip!" do
|
|
|
|
it "modifies self in place and returns self" do
|
|
|
|
a = " hello "
|
|
|
|
a.lstrip!.should equal(a)
|
|
|
|
a.should == "hello "
|
2021-02-09 16:50:36 -05:00
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2022-03-28 11:47:04 -04:00
|
|
|
ruby_version_is '3.0' do
|
2021-02-09 16:50:36 -05:00
|
|
|
it "strips leading \\0" do
|
|
|
|
a = "\000 \000hello\000 \000"
|
|
|
|
a.lstrip!
|
|
|
|
a.should == "hello\000 \000"
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil if no modifications were made" do
|
|
|
|
a = "hello"
|
|
|
|
a.lstrip!.should == nil
|
|
|
|
a.should == "hello"
|
|
|
|
end
|
|
|
|
|
2020-02-08 21:07:01 -05:00
|
|
|
it "raises a FrozenError on a frozen instance that is modified" do
|
|
|
|
-> { " hello ".freeze.lstrip! }.should raise_error(FrozenError)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# see [ruby-core:23657]
|
2020-02-08 21:07:01 -05:00
|
|
|
it "raises a FrozenError on a frozen instance that would not be modified" do
|
|
|
|
-> { "hello".freeze.lstrip! }.should raise_error(FrozenError)
|
|
|
|
-> { "".freeze.lstrip! }.should raise_error(FrozenError)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|