Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add symbol-to-proc mutations #1048

Merged
merged 1 commit into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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