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

Fix structure #1347

Merged
merged 5 commits into from
Jul 25, 2022
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
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.11.14 2022-07-25

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

Fix AST structure metadata issues.

# v0.11.13 2022-06-27

* Add support for org wide opensource licensing.
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
mutant (0.11.13)
mutant (0.11.14)
diff-lcs (~> 1.3)
parser (~> 3.1.0)
regexp_parser (~> 2.3, >= 2.3.1)
Expand Down Expand Up @@ -52,7 +52,7 @@ GEM
rubocop-ast (1.16.0)
parser (>= 3.1.1.0)
ruby-progressbar (1.11.0)
sorbet-runtime (0.5.10101)
sorbet-runtime (0.5.10206)
unicode-display_width (2.1.0)
unparser (0.6.5)
diff-lcs (~> 1.3)
Expand All @@ -71,4 +71,4 @@ DEPENDENCIES
rubocop (~> 1.7)

BUNDLED WITH
2.3.6
2.3.11
8 changes: 4 additions & 4 deletions lib/mutant/ast/find_metaclass_containing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class FindMetaclassContaining
#
# @api private
def call
AST.find_last_path(root) do |current|
next unless n_sclass?(current)
Structure.for(root.type).each_node(root) do |current|
return current if n_sclass?(current) && metaclass_of?(current)
end

metaclass_of?(current)
end.last
nil
end

private
Expand Down
9 changes: 7 additions & 2 deletions lib/mutant/ast/structure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def descendant?
end

def value(node)
node.children.fetch(index)
node.children.at(index)
end
end

Expand Down Expand Up @@ -246,7 +246,7 @@ def variable_descendants(node)
type: :class,
fixed: Node.fixed(
[
[Node::Fixed::Descendant, :name],
[Node::Fixed::Attribute, :name],
[Node::Fixed::Descendant, :superclass],
[Node::Fixed::Descendant, :body]
]
Expand Down Expand Up @@ -386,6 +386,11 @@ def variable_descendants(node)
fixed: Node.fixed([[Node::Fixed::Attribute, :value]]),
variable: nil
),
Node.new(
type: :forwarded_args,
fixed: EMPTY_ARRAY,
variable: nil
),
Node.new(
type: :for,
fixed: Node.fixed(
Expand Down
8 changes: 5 additions & 3 deletions lib/mutant/mutator/node/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ def unconditional_loop?
end

def body_has_control?
AST.find_last_path(body) do |node|
n_break?(node) || n_next?(node)
end.any?
AST::Structure.for(body.type).each_node(body) do |node|
return true if n_break?(node) || n_next?(node)
end

false
end

def mutate_body_receiver
Expand Down
2 changes: 1 addition & 1 deletion lib/mutant/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

module Mutant
# Current mutant version
VERSION = '0.11.13'
VERSION = '0.11.14'
end # Mutant
46 changes: 41 additions & 5 deletions spec/unit/mutant/ast/structure/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,50 @@ def apply
end

context 'with individual fixed descendants' do
it 'returns self' do
expect(apply).to be(instance)
context 'when descendants are present' do
it 'returns self' do
expect(apply).to be(instance)
end

it 'yields the descendants' do
apply

expect(yields).to eql([s(:int, 1)])
end
end

it 'yields the descendants' do
apply
context 'when descendant is absent' do
context 'and has a nil child array entry' do
let(:node) do
s(:test_type, :test_value, nil)
end

it 'returns self' do
expect(apply).to be(instance)
end

it 'does not yield the descendants' do
apply

expect(yields).to eql([])
end
end

context 'and is not present hin child array entry' do
let(:node) do
s(:test_type, :test_value)
end

it 'returns self' do
expect(apply).to be(instance)
end

it 'does not yield the descendants' do
apply

expect(yields).to eql([s(:int, 1)])
expect(yields).to eql([])
end
end
end
end

Expand Down