-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow options to be passed when processing a String pattern
- Loading branch information
Showing
6 changed files
with
109 additions
and
26 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
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,27 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe('passing options to parse') do | ||
it 'ignores options if parsing from a Regexp' do | ||
root = RP.parse(/a+/ix, options: ::Regexp::MULTILINE) | ||
|
||
expect(root.options).to eq(i: true, x: true) | ||
end | ||
|
||
it 'sets options if parsing from a String' do | ||
root = RP.parse('a+', options: ::Regexp::MULTILINE | ::Regexp::EXTENDED) | ||
|
||
expect(root.options).to eq(m: true, x: true) | ||
end | ||
|
||
it 'allows options to not be supplied when parsing from a Regexp' do | ||
root = RP.parse(/a+/ix) | ||
|
||
expect(root.options).to eq(i: true, x: true) | ||
end | ||
|
||
it 'has an empty option-hash when parsing from a String and passing no options' do | ||
root = RP.parse('a+') | ||
|
||
expect(root.options).to be_empty | ||
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,40 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe('passing options to scan') do | ||
def expect_type_tokens(tokens, type_tokens) | ||
expect(tokens.map { |type, token, *| [type, token] }).to eq(type_tokens) | ||
end | ||
|
||
it 'ignores options if parsing from a Regexp' do | ||
expect_type_tokens( | ||
RS.scan(/a+#c/im, options: ::Regexp::EXTENDED), | ||
[ | ||
%i[literal literal], | ||
%i[quantifier one_or_more], | ||
%i[literal literal] | ||
] | ||
) | ||
end | ||
|
||
it 'sets free_spacing based on options if parsing from a String' do | ||
expect_type_tokens( | ||
RS.scan('a+#c', options: ::Regexp::MULTILINE | ::Regexp::EXTENDED), | ||
[ | ||
%i[literal literal], | ||
%i[quantifier one_or_more], | ||
%i[free_space comment] | ||
] | ||
) | ||
end | ||
|
||
it 'does not set free_spacing if parsing from a String and passing no options' do | ||
expect_type_tokens( | ||
RS.scan('a+#c'), | ||
[ | ||
%i[literal literal], | ||
%i[quantifier one_or_more], | ||
%i[literal literal] | ||
] | ||
) | ||
end | ||
end |