|
10 | 10 | " hello world ".lstrip.should == "hello world "
|
11 | 11 | "\n\r\t\n\v\r hello world ".lstrip.should == "hello world "
|
12 | 12 | "hello".lstrip.should == "hello"
|
| 13 | + " こにちわ".lstrip.should == "こにちわ" |
| 14 | + end |
| 15 | + |
| 16 | + it "works with lazy substrings" do |
| 17 | + " hello "[1...-1].lstrip.should == "hello " |
| 18 | + " hello world "[1...-1].lstrip.should == "hello world " |
| 19 | + "\n\r\t\n\v\r hello world "[1...-1].lstrip.should == "hello world " |
| 20 | + " こにちわ "[1...-1].lstrip.should == "こにちわ" |
13 | 21 | end
|
14 | 22 |
|
15 | 23 | ruby_version_is '3.0' do
|
|
27 | 35 | a.should == "hello "
|
28 | 36 | end
|
29 | 37 |
|
| 38 | + it "returns nil if no modifications were made" do |
| 39 | + a = "hello" |
| 40 | + a.lstrip!.should == nil |
| 41 | + a.should == "hello" |
| 42 | + end |
| 43 | + |
| 44 | + it "makes a string empty if it is only whitespace" do |
| 45 | + "".lstrip!.should == nil |
| 46 | + " ".lstrip.should == "" |
| 47 | + " ".lstrip.should == "" |
| 48 | + end |
| 49 | + |
30 | 50 | ruby_version_is '3.0' do
|
31 |
| - it "strips leading \\0" do |
| 51 | + it "removes leading NULL bytes and whitespace" do |
32 | 52 | a = "\000 \000hello\000 \000"
|
33 | 53 | a.lstrip!
|
34 | 54 | a.should == "hello\000 \000"
|
35 | 55 | end
|
36 | 56 | end
|
37 | 57 |
|
38 |
| - it "returns nil if no modifications were made" do |
39 |
| - a = "hello" |
40 |
| - a.lstrip!.should == nil |
41 |
| - a.should == "hello" |
42 |
| - end |
43 |
| - |
44 | 58 | it "raises a FrozenError on a frozen instance that is modified" do
|
45 | 59 | -> { " hello ".freeze.lstrip! }.should raise_error(FrozenError)
|
46 | 60 | end
|
|
51 | 65 | -> { "".freeze.lstrip! }.should raise_error(FrozenError)
|
52 | 66 | end
|
53 | 67 |
|
54 |
| - it "raises an ArgumentError if the first codepoint is invalid" do |
| 68 | + it "raises an ArgumentError if the first non-space codepoint is invalid" do |
55 | 69 | s = "\xDFabc".force_encoding(Encoding::UTF_8)
|
56 | 70 | s.valid_encoding?.should be_false
|
57 | 71 | -> { s.lstrip! }.should raise_error(ArgumentError)
|
| 72 | + |
| 73 | + s = " \xDFabc".force_encoding(Encoding::UTF_8) |
| 74 | + s.valid_encoding?.should be_false |
| 75 | + -> { s.lstrip! }.should raise_error(ArgumentError) |
58 | 76 | end
|
59 | 77 | end
|
0 commit comments