Skip to content

Commit

Permalink
Add predicate method mutations
Browse files Browse the repository at this point in the history
- Adds mutations from predicate-like methods (methods ending in ?) to `true`/`false`
  * `a.b?` -> `false`
  * `a.b?` -> `true`
- Closes #263
  • Loading branch information
dgollahon committed Jan 2, 2021
1 parent 3245c83 commit 65dfdf6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Unreleased

* [#1192](https://github.com/mbj/mutant/pull/1192)

* Add mutations from predicate-like methods (methods ending in ?) to `true`/`false`
* `a.b?` -> `false`
* `a.b?` -> `true`

* [#1186](https://github.com/mbj/mutant/pull/1186)

Add additional `*` -> `+` regexp quantifier mutations:
Expand Down
8 changes: 8 additions & 0 deletions lib/mutant/mutator/node/send.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def normal_dispatch
end

def emit_selector_specific_mutations
emit_predicate_mutations
emit_array_mutation
emit_static_send
emit_const_get_mutation
Expand All @@ -93,6 +94,13 @@ def emit_selector_specific_mutations
emit_lambda_mutation
end

def emit_predicate_mutations
return unless selector.match?(/\?\z/) && !selector.equal?(:defined?)

emit(s(:true))
emit(s(:false))
end

def emit_array_mutation
return unless selector.equal?(:Array) && possible_kernel_method?

Expand Down
10 changes: 10 additions & 0 deletions meta/send.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,17 @@

singleton_mutations
mutation 'any?'
mutation 'false'
mutation 'true'
end

Mutant::Meta::Example.add :send do
source 'any?'

singleton_mutations
mutation 'all?'
mutation 'false'
mutation 'true'
end

Mutant::Meta::Example.add :send do
Expand Down Expand Up @@ -211,6 +215,8 @@
mutation 'foo.is_a?(self)'
mutation 'self.is_a?(bar)'
mutation 'foo.instance_of?(bar)'
mutation 'false'
mutation 'true'
end

Mutant::Meta::Example.add :send do
Expand All @@ -224,6 +230,8 @@
mutation 'foo.is_a?(self)'
mutation 'self.is_a?(bar)'
mutation 'foo.instance_of?(bar)'
mutation 'false'
mutation 'true'
end

Mutant::Meta::Example.add :send do
Expand All @@ -237,6 +245,8 @@
mutation 'foo.kind_of?(self)'
mutation 'self.kind_of?(bar)'
mutation 'foo.instance_of?(bar)'
mutation 'false'
mutation 'true'
end

Mutant::Meta::Example.add :send do
Expand Down

0 comments on commit 65dfdf6

Please sign in to comment.