module SimpleCov::Combine::BranchesCombiner

def combine(coverage_a, coverage_b)

Returns:
  • (Hash) -
def combine(coverage_a, coverage_b)
  merged = {} #: Hash[untyped, [untyped, Hash[untyped, untyped]]]
  combined = [coverage_a, coverage_b].each_with_object(merged) do |coverage, memo|
    coverage.each do |condition, branches_inside|
      condition_key = tuple_identity(condition)
      condition_tuple, merged_branches = memo[condition_key] ||= [condition, {}]
      merge_branches(merged_branches, branches_inside)
      memo[condition_key] = [condition_tuple, merged_branches]
    end
  end
  combined.values.to_h { |condition, branches| [condition, branches.values.to_h] }
end

def merge_branches(target, source)

def merge_branches(target, source)
  source.each do |branch, count|
    branch_key = tuple_identity(branch)
    branch_tuple, existing_count = target[branch_key]
    target[branch_key] = [branch_tuple || branch, existing_count ? existing_count + count : count]
  end
end

def tuple_identity(tuple)

def tuple_identity(tuple)
  tuple = SourceFile::RubyDataParser.call(tuple)
  type, _id, start_line, start_column, end_line, end_column = tuple
  [type, start_line, start_column, end_line, end_column]
end