Sha256: b76896f634912ebc2ac0197cf2da7a14116ee1773b79887c903b56d0777d0fa5

Contents?: true

Size: 1.45 KB

Versions: 8

Compression:

Stored size: 1.45 KB

Contents

module Mutest
  class Mutator
    class Node
      # Mutator for required arguments
      class Argument < self
        handle(:arg, :restarg, :kwarg, :kwrestarg)

        UNDERSCORE = '_'.freeze

        children :name

        private

        # Emit mutations
        #
        # @return [undefined]
        def dispatch
          emit_name_mutation
        end

        # Emit name mutations
        #
        # @return [undefined]
        def emit_name_mutation
          return if skip?
          emit_name(:"#{UNDERSCORE}#{name}")
        end

        # Test if argument mutation is skipped
        #
        # @return [Boolean]
        def skip?
          name.nil? || name.to_s.start_with?(UNDERSCORE)
        end

        # Mutator for optional arguments
        class Optional < self
          TYPE_MAP = IceNine.deep_freeze(
            optarg:   :arg,
            kwoptarg: :kwarg
          )

          handle(:optarg, :kwoptarg)

          children :name, :default

          private

          # Emit mutations
          #
          # @return [undefined]
          def dispatch
            emit_name_mutation
            emit_required_mutation
            emit_default_mutations
          end

          # Emit required mutation
          #
          # @return [undefined]
          def emit_required_mutation
            emit(s(TYPE_MAP.fetch(node.type), name))
          end
        end # Optional
      end # Argument
    end # Node
  end # Mutator
end # Mutest

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mutest-0.0.9 lib/mutest/mutator/node/argument.rb
mutest-0.0.8 lib/mutest/mutator/node/argument.rb
mutest-0.0.7 lib/mutest/mutator/node/argument.rb
mutest-0.0.6 lib/mutest/mutator/node/argument.rb
mutest-0.0.5 lib/mutest/mutator/node/argument.rb
mutest-0.0.4 lib/mutest/mutator/node/argument.rb
mutest-0.0.3 lib/mutest/mutator/node/argument.rb
mutest-0.0.2 lib/mutest/mutator/node/argument.rb