diff options
author | Sutou Kouhei <kou@cozmixng.org> | 2019-10-14 12:40:50 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-14 12:40:50 +0900 |
commit | 95c420c4a65ca2e7f3edf27134ad33691959296c (patch) | |
tree | 844e207d891996ecf7c60950d8a1e652be6d1938 /spec | |
parent | 6fa3492362dc91cfec7eb4fd55918791da5a34fb (diff) | |
download | ruby-95c420c4a65ca2e7f3edf27134ad33691959296c.tar.gz |
Import StringScanner 1.0.3 (#2553)
Diffstat (limited to 'spec')
-rw-r--r-- | spec/ruby/library/stringscanner/dup_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/library/stringscanner/scan_spec.rb | 42 |
2 files changed, 41 insertions, 3 deletions
diff --git a/spec/ruby/library/stringscanner/dup_spec.rb b/spec/ruby/library/stringscanner/dup_spec.rb index 3b426f138e..0fc52a1477 100644 --- a/spec/ruby/library/stringscanner/dup_spec.rb +++ b/spec/ruby/library/stringscanner/dup_spec.rb @@ -12,7 +12,7 @@ describe "StringScanner#dup" do s.string.should == @string end - it "copies the passed StringSCanner's position to self" do + it "copies the passed StringScanner's position to self" do @orig_s.pos = 5 s = @orig_s.dup s.pos.should eql(5) diff --git a/spec/ruby/library/stringscanner/scan_spec.rb b/spec/ruby/library/stringscanner/scan_spec.rb index 8b9960e6e6..2269abd6b3 100644 --- a/spec/ruby/library/stringscanner/scan_spec.rb +++ b/spec/ruby/library/stringscanner/scan_spec.rb @@ -50,10 +50,48 @@ describe "StringScanner#scan" do @s.scan(/./).should be_nil end - it "raises a TypeError if pattern isn't a Regexp" do - -> { @s.scan("aoeu") }.should raise_error(TypeError) + ruby_version_is ""..."2.7" do + it "raises a TypeError if pattern is a String" do + -> { @s.scan("aoeu") }.should raise_error(TypeError) + end + end + + ruby_version_is "2.7" do + it "treats String as the pattern itself" do + @s.scan("this").should be_nil + @s.scan("This").should == "This" + end + end + + it "raises a TypeError if pattern isn't a Regexp nor String" do -> { @s.scan(5) }.should raise_error(TypeError) -> { @s.scan(:test) }.should raise_error(TypeError) -> { @s.scan(mock('x')) }.should raise_error(TypeError) end end + +describe "StringScanner#scan with fixed_anchor: true" do + before :each do + @s = StringScanner.new("This\nis\na\ntest", fixed_anchor: true) + end + + ruby_version_is "2.7" do + it "returns the matched string" do + @s.scan(/\w+/).should == "This" + @s.scan(/.../m).should == "\nis" + @s.scan(//).should == "" + @s.scan(/\s+/).should == "\n" + end + + it "treats ^ as matching from the beginning of line" do + @s.scan(/\w+\n/).should == "This\n" + @s.scan(/^\w/).should == "i" + @s.scan(/^\w/).should be_nil + end + + it "treats \\A as matching from the beginning of string" do + @s.scan(/\A\w/).should == "T" + @s.scan(/\A\w/).should be_nil + end + end +end |