-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GR-18163] Implement missing StringScanner methods #peek_byte, #scan_…
…byte and #scan_integer PullRequest: truffleruby/4477
- Loading branch information
Showing
27 changed files
with
1,314 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require_relative '../../spec_helper' | ||
require 'strscan' | ||
|
||
describe "StringScanner#captures" do | ||
before do | ||
@s = StringScanner.new('Fri Dec 12 1975 14:39') | ||
end | ||
|
||
it "returns the array of captured values of the most recent matching" do | ||
@s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\d+)/) | ||
@s.captures.should == ["Fri", "Dec", "12"] | ||
end | ||
|
||
it "returns nil if the last match fails" do | ||
@s.scan(/nope/) | ||
@s.captures.should == nil | ||
end | ||
|
||
it "returns nil if there is no any match done" do | ||
@s.captures.should == nil | ||
end | ||
|
||
version_is StringScanner::Version, ""..."3.0.8" do # ruby_version_is ""..."3.3.3" | ||
it "returns '' for an optional capturing group if it doesn't match" do | ||
@s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\s+)?/) | ||
@s.captures.should == ["Fri", "Dec", ""] | ||
end | ||
end | ||
|
||
version_is StringScanner::Version, "3.0.8" do # ruby_version_is "3.3.3" | ||
it "returns nil for an optional capturing group if it doesn't match" do | ||
@s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\s+)?/) | ||
@s.captures.should == ["Fri", "Dec", nil] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require_relative '../../spec_helper' | ||
require 'strscan' | ||
|
||
describe "StringScanner#charpos" do | ||
it "returns character index corresponding to the current position" do | ||
s = StringScanner.new("abc") | ||
|
||
s.scan_until(/b/) | ||
s.charpos.should == 2 | ||
end | ||
|
||
it "is multi-byte character sensitive" do | ||
s = StringScanner.new("abcädeföghi") | ||
|
||
s.scan_until(/ö/) | ||
s.charpos.should == 8 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.