Rename filters to predicate

This commit is contained in:
Markus Schirp 2013-09-07 23:12:03 +02:00
parent 12efdb39f7
commit f5f7aeac36
10 changed files with 85 additions and 83 deletions

View file

@ -34,10 +34,10 @@ require 'mutant/singleton_methods'
require 'mutant/constants'
require 'mutant/support/method_object'
require 'mutant/random'
require 'mutant/filter'
require 'mutant/filter/attribute'
require 'mutant/filter/whitelist'
require 'mutant/filter/blacklist'
require 'mutant/predicate'
require 'mutant/predicate/attribute'
require 'mutant/predicate/whitelist'
require 'mutant/predicate/blacklist'
require 'mutant/mutator'
require 'mutant/mutation'
require 'mutant/mutation/evil'

View file

@ -94,9 +94,9 @@ module Mutant
#
def filter
if @filters.empty?
Filter::ALL
Predicate::ALL
else
Filter::Whitelist.new(@filters)
Predicate::Whitelist.new(@filters)
end
end
@ -142,7 +142,7 @@ module Mutant
# Add mutation filter
#
# @param [Class<Filter>] klass
# @param [Class<Predicate>] klass
#
# @return [undefined]
#
@ -255,7 +255,7 @@ module Mutant
puts("mutant-#{Mutant::VERSION}")
Kernel.exit(0)
end.on('--code FILTER', 'Adds a code filter') do |filter|
add_filter(Filter::Attribute, :code, filter)
add_filter(Predicate::Attribute, :code, filter)
end.on('--fail-fast', 'Fail fast') do
@fail_fast = true
end.on('-d', '--debug', 'Enable debugging output') do

View file

@ -1,27 +0,0 @@
# encoding: utf-8
module Mutant
class Filter
# Mutaiton filter filtering in regexp match on mutation identification
class Regexp < self
include Concord::Public.new(:regexp)
# Test for match
#
# @param [Mutation] mutation
#
# @return [true]
# returns true if mutation identification is matched by regexp
#
# @return [false]
# returns false otherwise
#
# @api private
#
def match?(mutation)
!!(regexp =~ mutation.identification)
end
end # Regexp
end # Filter
end # Mutant

View file

@ -0,0 +1,30 @@
module Mutant
class Matcher
# Matcher filter
class Filter < self
include Concord.new(:matcher, :filter)
# Enumerate matches
#
# @return [self]
# if block given
#
# @return [Enumerator<Subject>]
# oherwise
#
# @api private
#
def each
return to_enum unless block_given?
matcher.each do |subject|
next if filter.match?(subject)
yield matcher
end
self
end
end # Filter
end
end # Mutant

View file

@ -1,6 +1,6 @@
module Mutant
# Abstract base class for mutation/subject filters
class Filter
# Abstract base class for predicates used to filter subjects / mutations
class Predicate
include Adamantium::Flat, AbstractType
extend DescendantsTracker
@ -9,7 +9,7 @@ module Mutant
# @param [Object] object
#
# @return [true]
# if object is matched by filter
# if object is matched by predicate
#
# @return [false]
# otherwise
@ -18,7 +18,7 @@ module Mutant
#
abstract_method :match?
# Build filter from string
# Build predicate from string
#
# @param [String] notation
#
@ -32,14 +32,14 @@ module Mutant
#
def self.build(notation)
descendants.each do |descendant|
filter = descendant.handle(notation)
return filter if filter
predicate = descendant.handle(notation)
return predicate if predicate
end
nil
end
# Return filter for handle
# Return predicate for handle
#
# @param [String] _notation
#
@ -52,7 +52,7 @@ module Mutant
nil
end
# Mutation filter matching all mutations
# Mutation predicate matching all mutations
Mutant.singleton_subclass_instance('ALL', self) do
# Test for match

View file

@ -1,8 +1,8 @@
# encoding: utf-8
module Mutant
class Filter
# Base class for filters filtering on object attributes
class Predicate
# Base class for predicates on object attributes
class Attribute < self
include Concord.new(:attribute_name, :expectation)
@ -20,7 +20,7 @@ module Mutant
object.public_send(attribute_name)
end
# Regexp based attribute filter
# Regexp based attribute predicate
class Regexp < self
# Test for match
@ -41,7 +41,7 @@ module Mutant
end # Regexp
# Equality based attribute filter
# Equality based attribute predicate
class Equality < self
# Test for match

View file

@ -1,8 +1,8 @@
# encoding: utf-8
module Mutant
class Filter
# Blacklist filter
class Predicate
# Blacklist predicate
class Blacklist < self
include Adamantium::Flat, Concord.new(:blacklist)
@ -19,7 +19,7 @@ module Mutant
# @api private
#
def match?(object)
blacklist.none? { |filter| filter.match?(object) }
blacklist.none? { |predicate| predicate.match?(object) }
end
end # Whitelist

View file

@ -1,8 +1,7 @@
# encoding: utf-8
module Mutant
class Filter
class Predicate
# Whiltelist filter
class Whitelist < self
include Adamantium::Flat, Concord.new(:whitelist)
@ -24,5 +23,5 @@ module Mutant
end
end # Whitelist
end # Filter
end # Predicate
end # Mutant

View file

@ -28,7 +28,7 @@ describe Mutant::CLI, '.new' do
end
# Defaults
let(:expected_filter) { Mutant::Filter::ALL }
let(:expected_filter) { Mutant::Predicate::ALL }
let(:expected_strategy) { Mutant::Strategy::Rspec.new(0) }
let(:expected_reporter) { Mutant::Reporter::CLI.new($stdout) }
@ -122,13 +122,13 @@ describe Mutant::CLI, '.new' do
let(:filters) do
[
Mutant::Filter::Attribute.new(:code, 'faa'),
Mutant::Filter::Attribute.new(:code, 'bbb'),
Mutant::Predicate::Attribute.new(:code, 'faa'),
Mutant::Predicate::Attribute.new(:code, 'bbb'),
]
end
let(:expected_matcher) { ns::Method.new(cache, 'TestApp::Literal#float') }
let(:expected_filter) { Mutant::Filter::Whitelist.new(filters) }
let(:expected_filter) { Mutant::Predicate::Whitelist.new(filters) }
it_should_behave_like 'a cli parser'
end

View file

@ -1,22 +1,22 @@
require 'spec_helper'
filter_helpers = proc do
let(:item_a) { double('Item A', :foo => 'bar') }
let(:item_b) { double('Item B', :foo => 'baz') }
let(:input_a) { double('Input A', :foo => 'bar') }
let(:input_b) { double('Input B', :foo => 'baz') }
let(:filter_a) do
item_a = self.item_a
input_a = self.input_a
Module.new do
define_singleton_method(:match?) do |item|
item == item_a
define_singleton_method(:match?) do |input|
input == input_a
end
end
end
subject { object.match?(item) }
subject { object.match?(input) }
end
describe Mutant::Filter::Whitelist do
describe Mutant::Predicate::Whitelist do
instance_eval(&filter_helpers)
let(:object) { described_class.new(whitelist) }
@ -26,23 +26,23 @@ describe Mutant::Filter::Whitelist do
context 'with empty whitelist' do
let(:whitelist) { [] }
it 'accepts all items' do
expect(object.match?(item_a)).to be(false)
expect(object.match?(item_b)).to be(false)
it 'accepts all inputs' do
expect(object.match?(input_a)).to be(false)
expect(object.match?(input_b)).to be(false)
end
end
context 'with non empty whitelist' do
let(:whitelist) { [filter_a] }
context 'with whitelisted item' do
let(:item) { item_a }
context 'with whitelisted input' do
let(:input) { input_a }
it { should be(true) }
end
context 'with non whitelisted item' do
let(:item) { item_b }
context 'with non whitelisted input' do
let(:input) { input_b }
it { should be(false) }
end
@ -50,7 +50,7 @@ describe Mutant::Filter::Whitelist do
end
end
describe Mutant::Filter::Blacklist do
describe Mutant::Predicate::Blacklist do
instance_eval(&filter_helpers)
let(:object) { described_class.new(whitelist) }
@ -60,23 +60,23 @@ describe Mutant::Filter::Blacklist do
context 'with empty whitelist' do
let(:whitelist) { [] }
it 'accepts all items' do
expect(object.match?(item_a)).to be(true)
expect(object.match?(item_b)).to be(true)
it 'accepts all inputs' do
expect(object.match?(input_a)).to be(true)
expect(object.match?(input_b)).to be(true)
end
end
context 'with non empty whitelist' do
let(:whitelist) { [filter_a] }
context 'with whitelisted item' do
let(:item) { item_a }
context 'with whitelisted input' do
let(:input) { input_a }
it { should be(false) }
end
context 'with non whitelisted item' do
let(:item) { item_b }
context 'with non whitelisted input' do
let(:input) { input_b }
it { should be(true) }
end
@ -84,11 +84,11 @@ describe Mutant::Filter::Blacklist do
end
end
describe Mutant::Filter::Attribute::Equality do
describe Mutant::Predicate::Attribute::Equality do
instance_eval(&filter_helpers)
let(:object) { described_class.new(attribute_name, expected_value) }
let(:item) { double('Item', attribute_name => actual_value) }
let(:input) { double('Input', attribute_name => actual_value) }
let(:attribute_name) { :foo }
let(:expected_value) { 'value' }
@ -108,11 +108,11 @@ describe Mutant::Filter::Attribute::Equality do
end
end
describe Mutant::Filter::Attribute::Regexp do
describe Mutant::Predicate::Attribute::Regexp do
instance_eval(&filter_helpers)
let(:object) { described_class.new(attribute_name, expectation) }
let(:item) { double('Item', attribute_name => actual_value) }
let(:input) { double('Input', attribute_name => actual_value) }
let(:attribute_name) { :foo }
let(:expectation) { /\Avalue\z/ }