2014-08-10 21:04:05 +00:00
|
|
|
RSpec.describe Mutant::Matcher::Compiler do
|
2014-07-06 14:30:28 +00:00
|
|
|
let(:object) { described_class }
|
|
|
|
|
|
|
|
let(:env) { Fixtures::TEST_ENV }
|
|
|
|
|
2015-06-21 14:44:33 +00:00
|
|
|
let(:expression_a) { parse_expression('Foo*') }
|
|
|
|
let(:expression_b) { parse_expression('Bar*') }
|
2014-07-06 14:30:28 +00:00
|
|
|
|
|
|
|
let(:matcher_a) { expression_a.matcher(env) }
|
|
|
|
let(:matcher_b) { expression_b.matcher(env) }
|
|
|
|
|
|
|
|
let(:expected_matcher) do
|
|
|
|
Mutant::Matcher::Filter.new(expected_positive_matcher, expected_predicate)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_predicate) do
|
|
|
|
Morpher.compile(s(:true))
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.call' do
|
|
|
|
subject { object.call(env, matcher_config.update(attributes)) }
|
|
|
|
|
|
|
|
let(:matcher_config) { Mutant::Matcher::Config::DEFAULT }
|
|
|
|
|
|
|
|
context 'on empty config' do
|
|
|
|
let(:attributes) { {} }
|
|
|
|
|
|
|
|
let(:expected_positive_matcher) { Mutant::Matcher::Chain.new([]) }
|
|
|
|
|
|
|
|
it { should eql(expected_matcher) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on config with match expression' do
|
|
|
|
context 'and no filter' do
|
|
|
|
let(:attributes) do
|
|
|
|
{ match_expressions: [expression_a] }
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_positive_matcher) { Mutant::Matcher::Chain.new([matcher_a]) }
|
|
|
|
|
|
|
|
it { should eql(expected_matcher) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and a subject filter' do
|
|
|
|
let(:attributes) do
|
|
|
|
{
|
|
|
|
match_expressions: [expression_a],
|
|
|
|
subject_ignores: [expression_b]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_positive_matcher) { Mutant::Matcher::Chain.new([matcher_a]) }
|
|
|
|
|
2014-07-07 15:07:36 +00:00
|
|
|
let(:expected_predicate) do
|
2014-07-06 14:30:28 +00:00
|
|
|
Morpher::Evaluator::Predicate::Negation.new(
|
|
|
|
Morpher::Evaluator::Predicate::Boolean::Or.new([
|
|
|
|
described_class::SubjectPrefix.new(expression_b)
|
|
|
|
])
|
|
|
|
)
|
2014-07-07 15:07:36 +00:00
|
|
|
end
|
2014-07-06 14:30:28 +00:00
|
|
|
|
|
|
|
it { should eql(expected_matcher) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and an attribute filter' do
|
|
|
|
let(:attributes) do
|
|
|
|
{
|
|
|
|
match_expressions: [expression_a],
|
|
|
|
subject_selects: [[:code, 'foo']]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_positive_matcher) { Mutant::Matcher::Chain.new([matcher_a]) }
|
|
|
|
|
2014-07-07 15:07:36 +00:00
|
|
|
let(:expected_predicate) do
|
2014-07-06 14:30:28 +00:00
|
|
|
Morpher::Evaluator::Predicate::Boolean::Or.new([
|
|
|
|
Morpher.compile(s(:eql, s(:attribute, :code), s(:static, 'foo')))
|
|
|
|
])
|
2014-07-07 15:07:36 +00:00
|
|
|
end
|
2014-07-06 14:30:28 +00:00
|
|
|
|
|
|
|
it { should eql(expected_matcher) }
|
|
|
|
end
|
2014-07-13 20:02:30 +00:00
|
|
|
|
|
|
|
context 'and subject and attribute filter' do
|
|
|
|
let(:attributes) do
|
|
|
|
{
|
|
|
|
match_expressions: [expression_a],
|
|
|
|
subject_ignores: [expression_b],
|
|
|
|
subject_selects: [[:code, 'foo']]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_positive_matcher) { Mutant::Matcher::Chain.new([matcher_a]) }
|
|
|
|
|
|
|
|
let(:expected_predicate) do
|
|
|
|
Morpher::Evaluator::Predicate::Boolean::And.new([
|
|
|
|
Morpher::Evaluator::Predicate::Boolean::Or.new([
|
|
|
|
Morpher.compile(s(:eql, s(:attribute, :code), s(:static, 'foo')))
|
|
|
|
]),
|
|
|
|
Morpher::Evaluator::Predicate::Negation.new(
|
|
|
|
Morpher::Evaluator::Predicate::Boolean::Or.new([
|
|
|
|
described_class::SubjectPrefix.new(expression_b)
|
|
|
|
])
|
|
|
|
)
|
|
|
|
])
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should eql(expected_matcher) }
|
|
|
|
end
|
2014-07-06 14:30:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'on config with multiple match expressions' do
|
|
|
|
let(:attributes) do
|
|
|
|
{ match_expressions: [expression_a, expression_b] }
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_positive_matcher) { Mutant::Matcher::Chain.new([matcher_a, matcher_b]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|