Sha256: 89f414dd0a7d318f27bf721e046919cf8e5cb7b75950e39725389225eda2a590

Contents?: true

Size: 1.51 KB

Versions: 25

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module Mutant
  class Mutator
    class Node
      # Mutator for arguments node
      class Arguments < self

        handle(:args)

        PROCARG = %i[restarg mlhs].freeze

      private

        def dispatch
          emit_argument_presence
          emit_argument_mutations
          emit_mlhs_expansion
        end

        def emit_argument_presence
          emit_type

          Util::Array::Presence.call(children).each do |children|
            unless children.one? && n_mlhs?(children.first)
              emit_type(*children)
            end
          end
        end

        def emit_argument_mutations
          children.each_with_index do |child, index|
            Mutator.mutate(child).each do |mutant|
              next if invalid_argument_replacement?(mutant, index)
              emit_child_update(index, mutant)
            end
          end
        end

        def invalid_argument_replacement?(mutant, index)
          n_arg?(mutant) && children[0...index].any?(&method(:n_optarg?))
        end

        def emit_mlhs_expansion
          mlhs_childs_with_index.each do |child, index|
            dup_children = children.dup
            dup_children.delete_at(index)
            dup_children.insert(index, *child)
            emit_type(*dup_children)
          end
        end

        def mlhs_childs_with_index
          children.each_with_index.select do |child,|
            n_mlhs?(child)
          end
        end

      end # Arguments
    end # Node
  end # Mutator
end # Mutant

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
mutant-0.10.20 lib/mutant/mutator/node/arguments.rb
mutant-0.10.19 lib/mutant/mutator/node/arguments.rb
mutant-0.10.18 lib/mutant/mutator/node/arguments.rb
mutant-0.10.17 lib/mutant/mutator/node/arguments.rb
mutant-0.10.16 lib/mutant/mutator/node/arguments.rb
mutant-0.10.15 lib/mutant/mutator/node/arguments.rb
mutant-0.10.14 lib/mutant/mutator/node/arguments.rb
mutant-0.10.13 lib/mutant/mutator/node/arguments.rb
mutant-0.10.12 lib/mutant/mutator/node/arguments.rb
mutant-0.10.11 lib/mutant/mutator/node/arguments.rb
mutant-0.10.10 lib/mutant/mutator/node/arguments.rb
mutant-0.10.9 lib/mutant/mutator/node/arguments.rb
mutant-0.10.8 lib/mutant/mutator/node/arguments.rb
mutant-0.10.7 lib/mutant/mutator/node/arguments.rb
mutant-0.10.6 lib/mutant/mutator/node/arguments.rb
mutant-0.10.5 lib/mutant/mutator/node/arguments.rb
mutant-0.10.4 lib/mutant/mutator/node/arguments.rb
mutant-0.10.1 lib/mutant/mutator/node/arguments.rb
mutant-0.10.0 lib/mutant/mutator/node/arguments.rb
mutant-0.9.14 lib/mutant/mutator/node/arguments.rb