<commit_before>
module DeepCover
  # This is not actually branch coverage, but we call it like that everything.
  # This is more like atom coverage.
  # To be renamed, along with the rest.
  class BranchCoverageInterpreter
    def initialize(covered_code)
      @covered_code = covered_code
    end

    def generate_results
      buffer = @covered_code.buffer
      bc = buffer.source_lines.map{|line| ' ' * line.size}
      @covered_code.covered_ast.each_node do |node|
        unless node.was_executed?
          bad = node.proper_range
          bad.each do |pos|
            bc[buffer.line_for_position(pos)-1][buffer.column_for_position(pos)] = node.executable? ? 'x' : '-'
          end
        end
      end
      bc.zip(buffer.source_lines){|cov, line| cov[line.size..-1] = ''} # remove extraneous character for end lines, in any
      bc
    end
  end
end<commit_msg>Branch cover checks overlap in ranges<commit_after>
module DeepCover
  # This is not actually branch coverage, but we call it like that everything.
  # This is more like atom coverage.
  # To be renamed, along with the rest.
  class BranchCoverageInterpreter
    def initialize(covered_code)
      @covered_code = covered_code
    end

    def generate_results
      check_node_overlap

      buffer = @covered_code.buffer
      bc = buffer.source_lines.map{|line| ' ' * line.size}
      @covered_code.covered_ast.each_node do |node|
        unless node.was_executed?
          bad = node.proper_range
          bad.each do |pos|
            bc[buffer.line_for_position(pos)-1][buffer.column_for_position(pos)] = node.executable? ? 'x' : '-'
          end
        end
      end
      bc.zip(buffer.source_lines){|cov, line| cov[line.size..-1] = ''} # remove extraneous character for end lines, in any
      bc
    end

    # For now, when an overlap is found, just open a binding.pry to make fixing it easier.
    def check_node_overlap
      node_to_positions = {}
      @covered_code.covered_ast.each_node do |node|
        node.proper_range.each do |position|
          if node_to_positions[position]
            already = node_to_positions[position]
            puts "There is a proper_range overlap between #{node} and #{already}"
            puts "Overlapping: #{already.proper_range & node.proper_range}"
            binding.pry
          end
          node_to_positions[position] = node
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08585649108253837, 'fraction_numerical': 0.0016590626296142678, 'mean_word_length': 2.526315789473684, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6098088', 'n_tokens_mistral': 730, 'n_tokens_neox': 713, 'n_words': 203}