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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
require 'spec_helper'
RSpec.describe(Regexp::Expression::Shared) do
describe '::construct' do
{
Alternation => :meta,
Alternative => :expression,
Anchor::Base => :anchor,
Anchor::EndOfLine => :anchor,
Assertion::Base => :assertion,
Assertion::Lookahead => :assertion,
Backreference::Base => :backref,
Backreference::Number => :backref,
CharacterSet => :set,
CharacterSet::IntersectedSequence => :expression,
CharacterSet::Intersection => :set,
CharacterSet::Range => :set,
CharacterType::Any => :meta,
CharacterType::Base => :type,
CharacterType::Digit => :type,
Conditional::Branch => :expression,
Conditional::Condition => :conditional,
Conditional::Expression => :conditional,
EscapeSequence::Base => :escape,
EscapeSequence::Literal => :escape,
FreeSpace => :free_space,
Group::Base => :group,
Group::Capture => :group,
Keep::Mark => :keep,
Literal => :literal,
PosixClass => :posixclass,
Quantifier => :quantifier,
Root => :expression,
UnicodeProperty::Base => :property,
UnicodeProperty::Number::Decimal => :property,
}.each do |klass, expected_type|
it "works for #{klass}" do
result = klass.construct
expect(result).to be_a klass
expect(result.type).to eq expected_type
end
end
it 'allows overriding defaults' do
expect(Literal.construct(type: :foo).type).to eq :foo
end
it 'allows passing options' do
expect(Literal.construct(options: { i: true }).options[:i]).to eq true
end
it 'raises ArgumentError for unknown parameters' do
expect { Literal.construct(foo: :foo) }.to raise_error(ArgumentError)
end
end
end
|