diff --git a/Changelog.md b/Changelog.md index 50f63ddc6..0b631229c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,6 @@ # Unreleased +* Add symbol-to-proc block mutations (`map(&:to_s)` -> `map(&to_str)`) [#1048](https://github.com/mbj/mutant/pull/1048) * Add block-pass mutations (`foo(&method(:bar))` -> `foo(&public_method(:bar))`) [#1047](https://github.com/mbj/mutant/pull/1047) * Add new mutation of `Array(foo)` -> `[foo]` [#1043](https://github.com/mbj/mutant/pull/1043) * Add new mutation to mutate dynamic sends to static sends ({`foo.__send__(:bar)`, `foo.send(:bar)`, `foo.public_send(:bar)`} -> `foo.bar`) [#1040](https://github.com/mbj/mutant/pull/1040) and [#1049](https://github.com/mbj/mutant/pull/1049) diff --git a/lib/mutant/mutator/node/block_pass.rb b/lib/mutant/mutator/node/block_pass.rb index f5005e474..83d9ea336 100644 --- a/lib/mutant/mutator/node/block_pass.rb +++ b/lib/mutant/mutator/node/block_pass.rb @@ -13,6 +13,15 @@ class BlockPass < self def dispatch emit_argument_mutations + emit_symbol_to_proc_mutations + end + + def emit_symbol_to_proc_mutations + return unless n_sym?(argument) + + Send::SELECTOR_REPLACEMENTS.fetch(*argument, EMPTY_ARRAY).each do |method| + emit_argument(s(:sym, method)) + end end end # Block end # Node diff --git a/meta/block_pass.rb b/meta/block_pass.rb index 6bbbb729e..4d895fab7 100644 --- a/meta/block_pass.rb +++ b/meta/block_pass.rb @@ -23,3 +23,24 @@ mutation 'foo(&public_method(:bar))' mutation 'foo(&:bar)' end + +Mutant::Meta::Example.add :block_pass do + source 'foo(&:to_s)' + + singleton_mutations + mutation 'foo' + mutation 'foo(&nil)' + mutation 'foo(&self)' + mutation 'foo(&:to_str)' + mutation 'foo(&:to_s__mutant__)' +end + +Mutant::Meta::Example.add :block_pass do + source 'foo(&:bar)' + + singleton_mutations + mutation 'foo' + mutation 'foo(&nil)' + mutation 'foo(&self)' + mutation 'foo(&:bar__mutant__)' +end