def diff(cov1, cov2)
      ncov = {}
      old_format = true

      cov1.each do |path1, runs1|
        if cov2[path1]
          runs2 = cov2[path1]

          if runs1.is_a?(Array) && runs2.is_a?(Array) && old_format
            # diff two old-format (ruby 2.4 or before) coverage results
            ncov[path1] = diff_lines(runs1, runs2)
            next
          end

          # promotes from old format to new one
          if runs1.is_a?(Array)
            runs1 = { :lines => runs1 }
          end
          if runs2.is_a?(Array)
            runs2 = { :lines => runs2 }
          end
          if old_format
            old_format = false
            old2new!(ncov)
          end

          # diff two new-format (ruby 2.5 or later) coverage results
          ncov[path1] = {}
          [
            [:lines, :diff_lines],
            [:branches, :diff_branches],
            [:methods, :diff_methods],
          ].each do |type, diff_func|
            if runs1[type]
              if runs2[type]
                ncov[path1][type] = send(diff_func, runs1[type], runs2[type])
              else
                ncov[path1][type] = runs1[type]
              end
            end
          end
        else
          if runs1.is_a?(Array) && old_format
            ncov[path1] = runs1
            next
          end

          # promotes from old format to new one
          if runs1.is_a?(Array)
            runs1 = { :lines => runs1 }
          end
          if old_format
            old_format = false
            old2new!(ncov)
          end
          ncov[path1] = runs1
        end
      end

      ncov
    end
def diff(cov1, cov2)
      ncov = {}
      old_format = true

      cov1.each do |path1, runs1|
        if cov2[path1]
          runs2 = cov2[path1]

          if runs1.is_a?(Array) && runs2.is_a?(Array) && old_format
            # diff two old-format (ruby 2.4 or before) coverage results
            ncov[path1] = diff_lines(runs1, runs2)
            next
          end

          # promotes from old format to new one
          if runs1.is_a?(Array)
            runs1 = { :lines => runs1 }
          end
          if runs2.is_a?(Array)
            runs2 = { :lines => runs2 }
          end
          if old_format
            old_format = false
            old2new!(ncov)
          end

          # diff two new-format (ruby 2.5 or later) coverage results
          ncov[path1] = {}
          [
            [:lines, :diff_lines],
            [:branches, :diff_branches],
            [:methods, :diff_methods],
          ].each do |type, diff_func|
            if runs1[type]
              if runs2[type]
                ncov[path1][type] = send(diff_func, runs1[type], runs2[type])
              else
                ncov[path1][type] = runs1[type]
              end
            end
          end
        else
          if runs1.is_a?(Array) && old_format
            ncov[path1] = runs1
            next
          end

          # promotes from old format to new one
          if runs1.is_a?(Array)
            runs1 = { :lines => runs1 }
          end
          if old_format
            old_format = false
            old2new!(ncov)
          end
          ncov[path1] = runs1
        end
      end

      ncov
    end
Extract the coverage results that is covered by `cov1` but not covered by `cov2`.