1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe('passing options to parse') do
it 'raises if if parsing from a Regexp and options are passed' do
expect { RP.parse(/a+/, options: ::Regexp::EXTENDED) }.to raise_error(
ArgumentError,
'options cannot be supplied unless parsing a String'
)
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
|