Skip to content

Commit

Permalink
Add symbol-to-proc mutations
Browse files Browse the repository at this point in the history
- Adds mutations like `map(&:to_s)` -> `map(&:to_str)`.
  • Loading branch information
dgollahon committed Sep 8, 2020
1 parent 919ecbf commit 6992b9c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
9 changes: 9 additions & 0 deletions lib/mutant/mutator/node/block_pass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions meta/block_pass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6992b9c

Please sign in to comment.