Sha256: 12ca7c1157e8a8700e7b8b986a4b9d1151777cf634c6ae1a264a6ef605f806f8
Contents?: true
Size: 1.3 KB
Versions: 4
Compression:
Stored size: 1.3 KB
Contents
# frozen_string_literal: true module Leftovers module MatcherBuilders module NodeHasPositionalArgument class << self def build(positions, value_matcher) positions = ::Leftovers.wrap_array(positions) if !positions.empty? && !all_positions?(positions) && value_matcher build_has_positional_value_matcher(positions, value_matcher) elsif !positions.empty? && !value_matcher build_has_position_matcher(positions) elsif value_matcher build_has_any_positional_value_matcher(value_matcher) end end private def all_positions?(positions) positions.include?('*') end def build_has_position_matcher(positions) last_position = all_positions?(positions) ? 0 : positions.min Matchers::NodeHasPositionalArgument.new(last_position) end def build_has_any_positional_value_matcher(value_matcher) Matchers::NodeHasAnyPositionalArgumentWithValue.new(value_matcher) end def build_has_positional_value_matcher(positions, value_matcher) Or.each_or_self(positions) do |position| Matchers::NodeHasPositionalArgumentWithValue.new(position, value_matcher) end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems