Class: DeepCover::Analyser::PerChar

Inherits:
DeepCover::Analyser show all
Defined in:
lib/deep_cover/analyser/per_char.rb

Instance Attribute Summary

Attributes included from Base

#options, #source

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#covered_code, #each_node, #initialize, #node_children, #node_covered?, #node_runs, #node_runs_map, #node_stat_contributions, #node_stat_type

Methods included from Tools::Covered

#covered?

Class Method Details

.human_nameObject



5
6
7
# File 'lib/deep_cover/analyser/per_char.rb', line 5

def self.human_name
  'Chars'
end

Instance Method Details

#bufferObject



34
35
36
# File 'lib/deep_cover/analyser/per_char.rb', line 34

def buffer
  covered_code.buffer
end

#node_stat_contribution(node) ⇒ Object



24
25
26
# File 'lib/deep_cover/analyser/per_char.rb', line 24

def node_stat_contribution(node)
  node.executed_locs.sum(&:size)
end

#resultsObject

Returns an array of characters for each line of code. Each character is either ‘ ’ (executed), ‘-’ (not executable) or ‘x’ (not covered)



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/deep_cover/analyser/per_char.rb', line 11

def results
  bc = buffer.source_lines.map { |line| '-' * line.size }
  each_node do |node|
    runs = node_runs(node)
    next if runs == nil
    node.proper_range.each do |pos|
      bc[buffer.line_for_position(pos) - buffer.first_line][buffer.column_for_position(pos)] = runs > 0 ? ' ' : 'x'
    end
  end
  bc.zip(buffer.source_lines) { |cov, line| cov[line.size..-1] = '' } # remove extraneous character for end lines, in any
  bc
end

#statsObject



28
29
30
31
32
# File 'lib/deep_cover/analyser/per_char.rb', line 28

def stats
  s = super
  actual_total = buffer.source.size
  s.with not_executable: actual_total - s.total
end