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 ordering mutations #1444

Merged
merged 1 commit into from
May 12, 2024
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
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am slightly confused as to whether or not these were added to the full operator set because i think the deletion logic makes this just the full set and you also say:

People who do not care about ordering of their collections can now choose the light operator s

Copy link
Owner Author

@mbj mbj Jun 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgollahon Sorry for the late reply, the light operators do not include these operators. I've clarified thechangelog somewhat.

`#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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: where -> were

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