From bc408d52d22d471592a414ddf96fb64ad7c23fd9 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sat, 8 Dec 2012 00:52:03 +0100 Subject: [PATCH] Add a shitload of operator expansions --- Changelog.md | 8 +- lib/mutant/strategy/rspec/example_lookup.rb | 63 ++++++- .../rspec/example_lookup/spec_file_spec.rb | 159 +++++++++++++++++- 3 files changed, 217 insertions(+), 13 deletions(-) diff --git a/Changelog.md b/Changelog.md index d489e2b2..3c9e84d0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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] Incorrect handling of if and unless statements diff --git a/lib/mutant/strategy/rspec/example_lookup.rb b/lib/mutant/strategy/rspec/example_lookup.rb index bc8aff57..b85cb0d3 100644 --- a/lib/mutant/strategy/rspec/example_lookup.rb +++ b/lib/mutant/strategy/rspec/example_lookup.rb @@ -56,6 +56,38 @@ module Mutant mutation.subject.matcher 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 [String] @@ -63,15 +95,34 @@ module Mutant # @api private # def spec_file - method_name.to_s. - gsub(/\A\[\]\z/, 'element_reader'). - gsub(/\A\[\]=\z/, 'element_writer'). - gsub(/\?\z/, '_predicate'). - gsub(/=\z/, '_writer'). - gsub(/!\z/, '_bang') + '_spec.rb' + "#{mapped_name || expanded_name}_spec.rb" end 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 [Symbol] diff --git a/spec/unit/mutant/strategy/rspec/example_lookup/spec_file_spec.rb b/spec/unit/mutant/strategy/rspec/example_lookup/spec_file_spec.rb index 790ae899..23483fe7 100644 --- a/spec/unit/mutant/strategy/rspec/example_lookup/spec_file_spec.rb +++ b/spec/unit/mutant/strategy/rspec/example_lookup/spec_file_spec.rb @@ -16,15 +16,162 @@ describe Mutant::Strategy::Rspec::ExampleLookup, '#spec_file' do it { should be_frozen } 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 - let(:method_name) { '[]' } + let(:method_name) { :[] } let(:expected_spec_file) { 'element_reader_spec.rb' } it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file' end context 'with element writer method' do - let(:method_name) { '[]=' } + let(:method_name) { :[]= } let(:expected_spec_file) { 'element_writer_spec.rb' } @@ -32,28 +179,28 @@ describe Mutant::Strategy::Rspec::ExampleLookup, '#spec_file' do end context 'with writer method' do - let(:method_name) { 'foo=' } + let(:method_name) { :foo= } let(:expected_spec_file) { 'foo_writer_spec.rb' } it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file' end context 'with bang method' do - let(:method_name) { 'foo!' } + let(:method_name) { :foo! } let(:expected_spec_file) { 'foo_bang_spec.rb' } it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file' end context 'with predicate method' do - let(:method_name) { 'foo?' } + let(:method_name) { :foo? } let(:expected_spec_file) { 'foo_predicate_spec.rb' } it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file' end context 'with regular method' do - let(:method_name) { 'foo' } + let(:method_name) { :foo } let(:expected_spec_file) { 'foo_spec.rb' } it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'