Skip to content
Open
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 ruby/lib/mutant/mutator/node/literal/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class String < self

def dispatch
emit_singletons
emit(s(:str, ''))
end

end # String
Expand Down
14 changes: 14 additions & 0 deletions ruby/lib/mutant/mutator/node/send.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def normal_dispatch
mutate_arguments
end

# rubocop:disable Metrics/MethodLength
def emit_selector_specific_mutations
emit_reduce_to_sum_mutation
emit_start_end_with_mutations
Expand All @@ -76,7 +77,9 @@ def emit_selector_specific_mutations
emit_dig_mutation
emit_double_negation_mutation
emit_lambda_mutation
emit_empty_collection_mutation
end
# rubocop:enable Metrics/MethodLength

def emit_reduce_to_sum_mutation
return unless selector.equal?(:reduce)
Expand Down Expand Up @@ -171,6 +174,17 @@ def emit_lambda_mutation
emit(s(:send, nil, :lambda)) if meta.proc?
end

def emit_empty_collection_mutation
case selector
when :to_a, :to_ary
emit(s(:array))
when :to_h, :to_hash
emit(s(:hash))
when :to_s, :to_str
emit(s(:str, ''))
end
end

def emit_dig_mutation
return if !selector.equal?(:dig) || arguments.none?

Expand Down
30 changes: 30 additions & 0 deletions ruby/meta/send.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
mutation 'foo'
mutation 'self.to_s'
mutation 'foo.to_str'
mutation '""'
end

Mutant::Meta::Example.add :send do
Expand All @@ -158,6 +159,7 @@
mutation 'foo'
mutation 'self.to_a'
mutation 'foo.to_ary'
mutation '[]'
end

Mutant::Meta::Example.add :send do
Expand All @@ -177,6 +179,34 @@
mutation 'foo'
mutation 'self.to_h'
mutation 'foo.to_hash'
mutation '{}'
end

Mutant::Meta::Example.add :send do
source 'foo.to_ary'

singleton_mutations
mutation 'foo'
mutation 'self.to_ary'
mutation '[]'
end

Mutant::Meta::Example.add :send do
source 'foo.to_hash'

singleton_mutations
mutation 'foo'
mutation 'self.to_hash'
mutation '{}'
end

Mutant::Meta::Example.add :send do
source 'foo.to_str'

singleton_mutations
mutation 'foo'
mutation 'self.to_str'
mutation '""'
end

Mutant::Meta::Example.add :send, operators: :full do
Expand Down
7 changes: 7 additions & 0 deletions ruby/meta/str.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
Mutant::Meta::Example.add :str do
source '"foo"'

singleton_mutations
mutation '""'
end

Mutant::Meta::Example.add :str do
source '""'

singleton_mutations
end