2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
|
|
|
require_relative 'fixtures/classes'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "String#lstrip" do
|
|
|
|
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"
|
|
|
|
"\000 \000hello\000 \000".lstrip.should == "\000 \000hello\000 \000"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not strip leading \\0" do
|
|
|
|
"\x00hello".lstrip.should == "\x00hello"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "taints the result when self is tainted" do
|
|
|
|
"".taint.lstrip.tainted?.should == true
|
|
|
|
"ok".taint.lstrip.tainted?.should == true
|
|
|
|
" ok".taint.lstrip.tainted?.should == true
|
|
|
|
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 "
|
|
|
|
|
|
|
|
a = "\000 \000hello\000 \000"
|
|
|
|
a.lstrip!
|
|
|
|
a.should == "\000 \000hello\000 \000"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil if no modifications were made" do
|
|
|
|
a = "hello"
|
|
|
|
a.lstrip!.should == nil
|
|
|
|
a.should == "hello"
|
|
|
|
end
|
|
|
|
|
2017-12-27 11:12:47 -05:00
|
|
|
it "raises a #{frozen_error_class} on a frozen instance that is modified" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { " hello ".freeze.lstrip! }.should raise_error(frozen_error_class)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# see [ruby-core:23657]
|
2017-12-27 11:12:47 -05:00
|
|
|
it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { "hello".freeze.lstrip! }.should raise_error(frozen_error_class)
|
|
|
|
-> { "".freeze.lstrip! }.should raise_error(frozen_error_class)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|