Add a shitload of operator expansions
This commit is contained in:
parent
b5430e2000
commit
bc408d52d2
3 changed files with 217 additions and 13 deletions
|
@ -1,4 +1,10 @@
|
||||||
# v0.2.1 xxx
|
# v0.2.1 2012-12-07
|
||||||
|
|
||||||
|
* [feature] Add a shitload of operator expansions for dm2 strategy
|
||||||
|
|
||||||
|
[Compare v0.2.1..v0.2.2](https://github.com/mbj/mutant/compare/v0.2.1...v0.2.2)
|
||||||
|
|
||||||
|
# v0.2.1 2012-12-07
|
||||||
|
|
||||||
* [fixed] Crash on unavailable source location
|
* [fixed] Crash on unavailable source location
|
||||||
* [fixed] Incorrect handling of if and unless statements
|
* [fixed] Incorrect handling of if and unless statements
|
||||||
|
|
|
@ -56,6 +56,38 @@ module Mutant
|
||||||
mutation.subject.matcher
|
mutation.subject.matcher
|
||||||
end
|
end
|
||||||
|
|
||||||
|
MAPPING = {
|
||||||
|
:'!~' => :nomatch_operator,
|
||||||
|
:'!=' => :inequality_operator,
|
||||||
|
:<=> => :spaceship_operator,
|
||||||
|
:=== => :case_equality_operator,
|
||||||
|
:[]= => :element_writer,
|
||||||
|
:[] => :element_reader,
|
||||||
|
:== => :equality_operator,
|
||||||
|
:<= => :less_than_or_equal_to_operator,
|
||||||
|
:>= => :greater_than_or_equal_to_operator,
|
||||||
|
:=~ => :match_operator,
|
||||||
|
:<< => :left_shift_operator,
|
||||||
|
:>> => :right_shift_operator,
|
||||||
|
:** => :exponentation_operator,
|
||||||
|
:* => :multiplication_operator,
|
||||||
|
:% => :modulo_operator,
|
||||||
|
:/ => :division_operator,
|
||||||
|
:| => :bitwise_or_operator,
|
||||||
|
:^ => :bitwise_xor_operator,
|
||||||
|
:& => :bitwise_and_operator,
|
||||||
|
:< => :less_than_operator,
|
||||||
|
:> => :greater_than_operator,
|
||||||
|
:+ => :addition_operator,
|
||||||
|
:- => :substraction_operator
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPANSIONS = {
|
||||||
|
/\?\z/ => '_predicate',
|
||||||
|
/=\z/ => '_writer',
|
||||||
|
/!\z/ => '_bang'
|
||||||
|
}
|
||||||
|
|
||||||
# Return spec file
|
# Return spec file
|
||||||
#
|
#
|
||||||
# @return [String]
|
# @return [String]
|
||||||
|
@ -63,15 +95,34 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def spec_file
|
def spec_file
|
||||||
method_name.to_s.
|
"#{mapped_name || expanded_name}_spec.rb"
|
||||||
gsub(/\A\[\]\z/, 'element_reader').
|
|
||||||
gsub(/\A\[\]=\z/, 'element_writer').
|
|
||||||
gsub(/\?\z/, '_predicate').
|
|
||||||
gsub(/=\z/, '_writer').
|
|
||||||
gsub(/!\z/, '_bang') + '_spec.rb'
|
|
||||||
end
|
end
|
||||||
memoize :spec_file
|
memoize :spec_file
|
||||||
|
|
||||||
|
# Return mapped name
|
||||||
|
#
|
||||||
|
# @return [Symbol]
|
||||||
|
# if name was mapped
|
||||||
|
#
|
||||||
|
# @return [nil]
|
||||||
|
# otherwise
|
||||||
|
#
|
||||||
|
def mapped_name
|
||||||
|
MAPPING[method_name]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Return expanded name
|
||||||
|
#
|
||||||
|
# @return [Symbol]
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
#
|
||||||
|
def expanded_name
|
||||||
|
EXPANSIONS.inject(method_name) do |name, (regexp, expansion)|
|
||||||
|
name.to_s.gsub(regexp, expansion)
|
||||||
|
end.to_sym
|
||||||
|
end
|
||||||
|
|
||||||
# Return method name
|
# Return method name
|
||||||
#
|
#
|
||||||
# @return [Symbol]
|
# @return [Symbol]
|
||||||
|
|
|
@ -16,15 +16,162 @@ describe Mutant::Strategy::Rspec::ExampleLookup, '#spec_file' do
|
||||||
it { should be_frozen }
|
it { should be_frozen }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with bitwise xor method' do
|
||||||
|
let(:method_name) { :^ }
|
||||||
|
let(:expected_spec_file) { 'bitwise_xor_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with bitwise or method' do
|
||||||
|
let(:method_name) { :| }
|
||||||
|
let(:expected_spec_file) { 'bitwise_or_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with bitwise and method' do
|
||||||
|
let(:method_name) { :& }
|
||||||
|
let(:expected_spec_file) { 'bitwise_and_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with spaceship method' do
|
||||||
|
let(:method_name) { :<=> }
|
||||||
|
let(:expected_spec_file) { 'spaceship_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with case equality operator method' do
|
||||||
|
let(:method_name) { :=== }
|
||||||
|
let(:expected_spec_file) { 'case_equality_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with modulo operator method' do
|
||||||
|
let(:method_name) { :% }
|
||||||
|
let(:expected_spec_file) { 'modulo_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with exponentation operator method' do
|
||||||
|
let(:method_name) { :** }
|
||||||
|
let(:expected_spec_file) { 'exponentation_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with substraction operator method' do
|
||||||
|
let(:method_name) { :- }
|
||||||
|
let(:expected_spec_file) { 'substraction_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with addition operator method' do
|
||||||
|
let(:method_name) { :+ }
|
||||||
|
let(:expected_spec_file) { 'addition_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with greater than or equal to operator method' do
|
||||||
|
let(:method_name) { :>= }
|
||||||
|
let(:expected_spec_file) { 'greater_than_or_equal_to_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with less than or equal to operator method' do
|
||||||
|
let(:method_name) { :<= }
|
||||||
|
let(:expected_spec_file) { 'less_than_or_equal_to_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with greater than operator method' do
|
||||||
|
let(:method_name) { :> }
|
||||||
|
let(:expected_spec_file) { 'greater_than_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with less than operator method' do
|
||||||
|
let(:method_name) { :< }
|
||||||
|
let(:expected_spec_file) { 'less_than_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with right shift operator method' do
|
||||||
|
let(:method_name) { :>> }
|
||||||
|
let(:expected_spec_file) { 'right_shift_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with left shift operator method' do
|
||||||
|
let(:method_name) { :<< }
|
||||||
|
let(:expected_spec_file) { 'left_shift_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with division operator method' do
|
||||||
|
let(:method_name) { :/ }
|
||||||
|
let(:expected_spec_file) { 'division_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with multiplication operator method' do
|
||||||
|
let(:method_name) { :* }
|
||||||
|
let(:expected_spec_file) { 'multiplication_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with nomatch operator method' do
|
||||||
|
let(:method_name) { :'!~' }
|
||||||
|
let(:expected_spec_file) { 'nomatch_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with match operator method' do
|
||||||
|
let(:method_name) { :=~ }
|
||||||
|
let(:expected_spec_file) { 'match_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with inequality operator method' do
|
||||||
|
let(:method_name) { :'!=' }
|
||||||
|
let(:expected_spec_file) { 'inequality_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with equality operator method' do
|
||||||
|
let(:method_name) { :== }
|
||||||
|
let(:expected_spec_file) { 'equality_operator_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
context 'with element reader method' do
|
context 'with element reader method' do
|
||||||
let(:method_name) { '[]' }
|
let(:method_name) { :[] }
|
||||||
let(:expected_spec_file) { 'element_reader_spec.rb' }
|
let(:expected_spec_file) { 'element_reader_spec.rb' }
|
||||||
|
|
||||||
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with element writer method' do
|
context 'with element writer method' do
|
||||||
let(:method_name) { '[]=' }
|
let(:method_name) { :[]= }
|
||||||
|
|
||||||
let(:expected_spec_file) { 'element_writer_spec.rb' }
|
let(:expected_spec_file) { 'element_writer_spec.rb' }
|
||||||
|
|
||||||
|
@ -32,28 +179,28 @@ describe Mutant::Strategy::Rspec::ExampleLookup, '#spec_file' do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with writer method' do
|
context 'with writer method' do
|
||||||
let(:method_name) { 'foo=' }
|
let(:method_name) { :foo= }
|
||||||
let(:expected_spec_file) { 'foo_writer_spec.rb' }
|
let(:expected_spec_file) { 'foo_writer_spec.rb' }
|
||||||
|
|
||||||
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with bang method' do
|
context 'with bang method' do
|
||||||
let(:method_name) { 'foo!' }
|
let(:method_name) { :foo! }
|
||||||
let(:expected_spec_file) { 'foo_bang_spec.rb' }
|
let(:expected_spec_file) { 'foo_bang_spec.rb' }
|
||||||
|
|
||||||
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with predicate method' do
|
context 'with predicate method' do
|
||||||
let(:method_name) { 'foo?' }
|
let(:method_name) { :foo? }
|
||||||
let(:expected_spec_file) { 'foo_predicate_spec.rb' }
|
let(:expected_spec_file) { 'foo_predicate_spec.rb' }
|
||||||
|
|
||||||
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with regular method' do
|
context 'with regular method' do
|
||||||
let(:method_name) { 'foo' }
|
let(:method_name) { :foo }
|
||||||
let(:expected_spec_file) { 'foo_spec.rb' }
|
let(:expected_spec_file) { 'foo_spec.rb' }
|
||||||
|
|
||||||
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue