Class: DeepCover::Reporter::Istanbul::CoveredCodeConverter

Inherits:
Struct
  • Object
show all
Includes:
Converters
Defined in:
lib/deep_cover/reporter/istanbul.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Converters

#convert_block, #convert_branch, #convert_def, #convert_function, #convert_list, #convert_range

Instance Attribute Details

#covered_codeObject

Returns the value of attribute covered_code

Returns:

  • (Object)

    the current value of covered_code



71
72
73
# File 'lib/deep_cover/reporter/istanbul.rb', line 71

def covered_code
  @covered_code
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



71
72
73
# File 'lib/deep_cover/reporter/istanbul.rb', line 71

def options
  @options
end

Instance Method Details

#branch_mapObject



94
95
96
97
98
# File 'lib/deep_cover/reporter/istanbul.rb', line 94

def branch_map
  branches.map do |node, branches_runs|
    convert_branch(node, branches_runs.keys)
  end
end

#branch_runsObject



105
106
107
# File 'lib/deep_cover/reporter/istanbul.rb', line 105

def branch_runs
  branches.values.map { |r| zero_to_something(r.values) }
end

#branchesObject



90
91
92
# File 'lib/deep_cover/reporter/istanbul.rb', line 90

def branches
  @branches ||= Analyser::Branch.new(node_analyser, **options).results
end

#convertObject



136
137
138
139
140
141
# File 'lib/deep_cover/reporter/istanbul.rb', line 136

def convert
  {
    path: covered_code.path,
    **data.transform_values { |l| convert_list(l) },
  }
end

#dataObject



125
126
127
128
129
130
131
132
133
134
# File 'lib/deep_cover/reporter/istanbul.rb', line 125

def data
  {
    statementMap: statement_map,
    s:            statement_runs,
    fnMap:        function_map,
    f:            function_runs,
    branchMap:    branch_map,
    b:            branch_runs,
  }
end

#function_mapObject



117
118
119
# File 'lib/deep_cover/reporter/istanbul.rb', line 117

def function_map
  functions.keys.map { |n| convert_function(n) }
end

#function_runsObject



121
122
123
# File 'lib/deep_cover/reporter/istanbul.rb', line 121

def function_runs
  functions.values
end

#functionsObject



82
83
84
# File 'lib/deep_cover/reporter/istanbul.rb', line 82

def functions
  @functions ||= Analyser::Function.new(node_analyser, **options).results
end

#node_analyserObject



74
75
76
# File 'lib/deep_cover/reporter/istanbul.rb', line 74

def node_analyser
  @node_analyser ||= Analyser::Node.new(covered_code, **options)
end

#node_runsObject



78
79
80
# File 'lib/deep_cover/reporter/istanbul.rb', line 78

def node_runs
  @node_runs ||= node_analyser.results
end

#statement_mapObject



109
110
111
# File 'lib/deep_cover/reporter/istanbul.rb', line 109

def statement_map
  statements.keys.map { |range| convert_range(range) }
end

#statement_runsObject



113
114
115
# File 'lib/deep_cover/reporter/istanbul.rb', line 113

def statement_runs
  statements.values
end

#statementsObject



86
87
88
# File 'lib/deep_cover/reporter/istanbul.rb', line 86

def statements
  @statements ||= Analyser::Statement.new(node_analyser, **options).results
end

#zero_to_something(values) ⇒ Object

Istanbul doesn’t understand how to ignore a branch…



101
102
103
# File 'lib/deep_cover/reporter/istanbul.rb', line 101

def zero_to_something(values)
  values.map { |v| v || 1 }
end