Skip to content

Commit

Permalink
Add ordering mutations
Browse files Browse the repository at this point in the history
[fix #1442]
  • Loading branch information
mbj committed May 12, 2024
1 parent dae46ad commit 353e25c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# v0.12.1 2024-05-11

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

Add ordering mutations to full and light operator set,
`#find/#detect/#min/#max/#min_by/#max_by -> #first/#last`. These mutations force
to provide test cases with more than one element to observe the extra
semantics by these methods over just `#first` and `#last`.

Add `#first -> #last` and `#last -> #first` to full operator set. These where
highly controversial in the past and thus where removed. People who do not care
about ordering of their collections can now choose the light operator set, so people who care
(and should care) can now care (again).

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

Change mutants test runner to always report in test definition order deterministically.
Expand Down
10 changes: 10 additions & 0 deletions lib/mutant/mutation/operators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,22 @@ class Full < self
all?: %i[any?],
any?: %i[all?],
at: %i[fetch key?],
detect: %i[first last],
fetch: %i[key?],
find: %i[first last],
first: %i[last],
flat_map: %i[map],
gsub: %i[sub],
is_a?: %i[instance_of?],
kind_of?: %i[instance_of?],
last: %i[first],
map: %i[each],
match: %i[match?],
max: %i[first last],
max_by: %i[first last],
method: %i[public_method],
min: %i[first last],
min_by: %i[first last],
reverse_each: %i[each],
reverse_map: %i[map each],
reverse_merge: %i[merge],
Expand All @@ -49,6 +57,8 @@ class Light < self
.tap do |replacements|
replacements.delete(:==)
replacements.delete(:eql?)
replacements.delete(:first)
replacements.delete(:last)
end
.freeze
end
Expand Down
51 changes: 51 additions & 0 deletions meta/send.rb
Original file line number Diff line number Diff line change
Expand Up @@ -884,3 +884,54 @@
mutation 'foo(nil)'
mutation 'foo(:"+__mutant__")'
end

Mutant::Meta::Example.add :send, operators: :light do
source 'first'

singleton_mutations
end

Mutant::Meta::Example.add :send, operators: :light do
source 'last'

singleton_mutations
end

Mutant::Meta::Example.add :send, operators: :full do
source 'first'

singleton_mutations

mutation 'last'
end

Mutant::Meta::Example.add :send, operators: :full do
source 'last'

singleton_mutations

mutation 'first'
end

%w[detect find max max_by min min_by].each do |selector|
Mutant::Meta::Example.add :send do
source selector

singleton_mutations

mutation 'first'
mutation 'last'
end

Mutant::Meta::Example.add :send do
source "#{selector}(&:block)"

singleton_mutations

mutation "#{selector}(&:block__mutant__)"
mutation "#{selector}(&nil)"
mutation 'first(&:block)'
mutation 'last(&:block)'
mutation selector
end
end

0 comments on commit 353e25c

Please sign in to comment.