Sha256: 0deb65622936bb79feb3735d0202238a155d52c46c79489ca0ff6958fe51fbb4

Contents?: true

Size: 1007 Bytes

Versions: 21

Compression:

Stored size: 1007 Bytes

Contents

# frozen_string_literal: true

module SimpleCov
  module Combine
    #
    # Combine two different lines coverage results on same file
    #
    # Should be called through `SimpleCov.combine`.
    module LinesCombiner
    module_function

      def combine(coverage_a, coverage_b)
        coverage_a
          .zip(coverage_b)
          .map do |coverage_a_val, coverage_b_val|
            merge_line_coverage(coverage_a_val, coverage_b_val)
          end
      end

      # Return depends on coverage in a specific line
      #
      # @param [Integer || nil] first_val
      # @param [Integer || nil] second_val
      #
      # Logic:
      #
      # => nil + 0 = nil
      # => nil + nil = nil
      # => int + int = int
      #
      # @return [Integer || nil]
      def merge_line_coverage(first_val, second_val)
        sum = first_val.to_i + second_val.to_i

        if sum.zero? && (first_val.nil? || second_val.nil?)
          nil
        else
          sum
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 6 rubygems

Version Path
strongmind-simplecov-0.23.0 lib/simplecov/combine/lines_combiner.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/simplecov-0.22.0/lib/simplecov/combine/lines_combiner.rb
simplecov-0.22.0 lib/simplecov/combine/lines_combiner.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/simplecov-0.21.2/lib/simplecov/combine/lines_combiner.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/simplecov-0.21.2/lib/simplecov/combine/lines_combiner.rb
simplecov-0.21.2 lib/simplecov/combine/lines_combiner.rb
simplecov-0.21.1 lib/simplecov/combine/lines_combiner.rb
simplecov-0.21.0 lib/simplecov/combine/lines_combiner.rb
simplecov-0.20.0 lib/simplecov/combine/lines_combiner.rb
simplecov-0.19.1 lib/simplecov/combine/lines_combiner.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/simplecov-0.19.0/lib/simplecov/combine/lines_combiner.rb
simplecov-0.19.0 lib/simplecov/combine/lines_combiner.rb
simplecov-0.18.5 lib/simplecov/combine/lines_combiner.rb
simplecov-0.18.4 lib/simplecov/combine/lines_combiner.rb
simplecov-0.18.3 lib/simplecov/combine/lines_combiner.rb
simplecov-0.18.2 lib/simplecov/combine/lines_combiner.rb
simplecov-0.18.1 lib/simplecov/combine/lines_combiner.rb
simplecov-0.18.0 lib/simplecov/combine/lines_combiner.rb
simplecov-0.18.0.beta3 lib/simplecov/combine/lines_combiner.rb
simplecov-0.18.0.beta2 lib/simplecov/combine/lines_combiner.rb