Add subject filter to matcher config

This commit is contained in:
Markus Schirp 2015-07-12 22:36:24 +00:00
parent bdf6765a0b
commit e3719c4f7d
5 changed files with 68 additions and 22 deletions

View file

@ -1,3 +1,3 @@
---
threshold: 18
total_score: 1178
total_score: 1173

View file

@ -13,7 +13,12 @@ module Mutant
def result
Filter.new(
Chain.build(config.match_expressions.map(&method(:matcher))),
ignored_subjects
Morpher::Evaluator::Predicate::Boolean::And.new(
[
ignored_subjects,
filtered_subjects
]
)
)
end
@ -34,7 +39,7 @@ module Mutant
private
# Predicate returning false on ignored subject
# Predicate returning false on expression ignored subject
#
# @return [#call]
#
@ -47,6 +52,15 @@ module Mutant
)
end
# Predicate returning false on filtered subject
#
# @return [#call]
#
# @api private
def filtered_subjects
Morpher::Evaluator::Predicate::Boolean::And.new(config.subject_filters)
end
# Matcher for expression on env
#
# @param [Mutant::Expression] expression

View file

@ -4,7 +4,8 @@ module Mutant
class Config
include Adamantium, Anima::Update, Anima.new(
:match_expressions,
:ignore_expressions
:ignore_expressions,
:subject_filters
)
INSPECT_FORMAT = "#<#{self} %s>".freeze
@ -12,6 +13,11 @@ module Mutant
ATTRIBUTE_FORMAT = '%s: [%s]'.freeze
ENUM_DELIMITER = ','.freeze
EMPTY_ATTRIBUTES = 'empty'.freeze
PRESENTATIONS = IceNine.deep_freeze(
match_expressions: :syntax,
ignore_expressions: :syntax,
subject_filters: :inspect
)
private_constant(*constants(false))
DEFAULT = new(Hash[anima.attribute_names.map { |name| [name, []] }])
@ -71,7 +77,9 @@ module Mutant
ATTRIBUTE_FORMAT %
[
attribute_name,
public_send(attribute_name).map(&:syntax).join(ENUM_DELIMITER)
public_send(attribute_name)
.map(&PRESENTATIONS.fetch(attribute_name))
.join(ENUM_DELIMITER)
]
end

View file

@ -14,7 +14,7 @@ RSpec.describe Mutant::Matcher::Compiler do
end
let(:expected_predicate) do
Morpher.compile(s(:negate, s(:or)))
Morpher.compile(s(:and, s(:negate, s(:or)), s(:and)))
end
describe '.call' do
@ -31,32 +31,47 @@ RSpec.describe Mutant::Matcher::Compiler do
end
context 'on config with match expression' do
context 'and no filter' do
let(:expected_predicate) do
Morpher::Evaluator::Predicate::Boolean::And.new(
[
Morpher::Evaluator::Predicate::Negation.new(
Morpher::Evaluator::Predicate::Boolean::Or.new(ignore_expression_predicates)
),
Morpher::Evaluator::Predicate::Boolean::And.new(subject_filter_predicates)
]
)
end
let(:expected_positive_matcher) { Mutant::Matcher::Chain.new([matcher_a]) }
let(:attributes) { { match_expressions: [expression_a] } }
let(:ignore_expression_predicates) { [] }
let(:subject_filter_predicates) { [] }
context 'and no other constraints' do
it { should eql(expected_matcher) }
end
context 'and ignore expressions' do
let(:attributes) do
{ match_expressions: [expression_a] }
super().merge(ignore_expressions: [expression_b])
end
let(:expected_positive_matcher) { Mutant::Matcher::Chain.new([matcher_a]) }
let(:ignore_expression_predicates) do
[Mutant::Matcher::Compiler::SubjectPrefix.new(expression_b)]
end
it { should eql(expected_matcher) }
end
context 'and ignore epxressions' do
context 'and subject filters' do
let(:filter) { double('filter') }
let(:attributes) do
{
match_expressions: [expression_a],
ignore_expressions: [expression_b]
}
super().merge(subject_filters: [filter])
end
let(:expected_positive_matcher) { Mutant::Matcher::Chain.new([matcher_a]) }
let(:expected_predicate) do
Morpher::Evaluator::Predicate::Negation.new(
Morpher::Evaluator::Predicate::Boolean::Or.new([
described_class::SubjectPrefix.new(expression_b)
])
)
let(:subject_filter_predicates) do
[filter]
end
it { should eql(expected_matcher) }

View file

@ -32,5 +32,14 @@ RSpec.describe Mutant::Matcher::Config do
it { should eql('#<Mutant::Matcher::Config match_expressions: [Foo] ignore_expressions: [Bar]>') }
end
context 'with subject filter' do
let(:object) do
described_class::DEFAULT
.add(:subject_filters, 'foo')
end
it { should eql('#<Mutant::Matcher::Config subject_filters: ["foo"]>') }
end
end
end