
* Avoids boot time mutation of REGISTER constant * Allows to define project specific expression parsing * Avoids custom (slow) serialization of Expression objects speeding up reporter / killer IPC * Improve specification * Improve integration API as it now finally references an object the config * Allow reproduction of syntax from Expression#syntax * Allow instantiation of Expresssion objects without generating the syntax, much nicer for most specs & internal code, avoids generating a string to parse it into an expression * Fix LSP violation in Mutant::Matcher namespace
67 lines
1.6 KiB
Ruby
67 lines
1.6 KiB
Ruby
RSpec.describe Mutant::Expression::Parser do
|
|
let(:object) { Mutant::Config::DEFAULT.expression_parser }
|
|
|
|
describe '#call' do
|
|
subject { object.call(input) }
|
|
|
|
context 'on nonsense' do
|
|
let(:input) { 'foo bar' }
|
|
|
|
it 'raises an exception' do
|
|
expect { subject }.to raise_error(
|
|
Mutant::Expression::Parser::InvalidExpressionError,
|
|
'Expression: "foo bar" is not valid'
|
|
)
|
|
end
|
|
end
|
|
|
|
context 'on a valid expression' do
|
|
let(:input) { 'Foo' }
|
|
|
|
it { should eql(Mutant::Expression::Namespace::Exact.new(scope_name: 'Foo')) }
|
|
end
|
|
end
|
|
|
|
describe '.try_parse' do
|
|
subject { object.try_parse(input) }
|
|
|
|
context 'on nonsense' do
|
|
let(:input) { 'foo bar' }
|
|
|
|
it { should be(nil) }
|
|
end
|
|
|
|
context 'on a valid expression' do
|
|
let(:input) { 'Foo' }
|
|
|
|
it { should eql(Mutant::Expression::Namespace::Exact.new(scope_name: 'Foo')) }
|
|
end
|
|
|
|
context 'on ambiguous expression' do
|
|
let(:object) { described_class.new([test_a, test_b]) }
|
|
|
|
let(:test_a) do
|
|
Class.new(Mutant::Expression) do
|
|
include Anima.new
|
|
const_set(:REGEXP, /\Atest-syntax\z/.freeze)
|
|
end
|
|
end
|
|
|
|
let(:test_b) do
|
|
Class.new(Mutant::Expression) do
|
|
include Anima.new
|
|
const_set(:REGEXP, /^test-syntax$/.freeze)
|
|
end
|
|
end
|
|
|
|
let(:input) { 'test-syntax' }
|
|
|
|
it 'raises expected exception' do
|
|
expect { subject }.to raise_error(
|
|
Mutant::Expression::Parser::AmbiguousExpressionError,
|
|
'Ambiguous expression: "test-syntax"'
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|