path_coverage 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -134
  3. data/lib/path_coverage/call_trace.rb +26 -5
  4. data/lib/path_coverage/calls.rb +24 -0
  5. data/lib/path_coverage/configuration_limits.rb +1 -1
  6. data/lib/path_coverage/console_summary.rb +13 -13
  7. data/lib/path_coverage/fold_rows.rb +2 -2
  8. data/lib/path_coverage/gaps.rb +1 -1
  9. data/lib/path_coverage/json_reader.rb +3 -3
  10. data/lib/path_coverage/json_reports.rb +28 -21
  11. data/lib/path_coverage/json_writer.rb +4 -4
  12. data/lib/path_coverage/kernel.rb +41 -20
  13. data/lib/path_coverage/leaving.rb +14 -6
  14. data/lib/path_coverage/loop_forks.rb +1 -1
  15. data/lib/path_coverage/loop_nodes.rb +41 -5
  16. data/lib/path_coverage/method_loops.rb +56 -12
  17. data/lib/path_coverage/method_statements.rb +25 -12
  18. data/lib/path_coverage/method_ways.rb +48 -20
  19. data/lib/path_coverage/{card_context.rb → paths_context.rb} +16 -16
  20. data/lib/path_coverage/paths_fitting.rb +31 -0
  21. data/lib/path_coverage/paths_forks.rb +72 -0
  22. data/lib/path_coverage/{card_gaps.rb → paths_gaps.rb} +38 -26
  23. data/lib/path_coverage/paths_leaving.rb +40 -0
  24. data/lib/path_coverage/paths_rescues.rb +146 -0
  25. data/lib/path_coverage/{card_scopes.rb → paths_scopes.rb} +6 -6
  26. data/lib/path_coverage/{card_tree.rb → paths_tree.rb} +19 -15
  27. data/lib/path_coverage/{card_way_lists.rb → paths_way_lists.rb} +3 -3
  28. data/lib/path_coverage/paths_ways.rb +193 -0
  29. data/lib/path_coverage/recorder.rb +14 -0
  30. data/lib/path_coverage/render.rb +6 -6
  31. data/lib/path_coverage/rescue_forks.rb +174 -0
  32. data/lib/path_coverage/rewriter.rb +83 -14
  33. data/lib/path_coverage/source_report.rb +4 -4
  34. data/lib/path_coverage/stable_leaves.rb +3 -3
  35. data/lib/path_coverage/statement_arms.rb +23 -9
  36. data/lib/path_coverage/totals.rb +5 -5
  37. data/lib/path_coverage/version.rb +1 -1
  38. data/lib/path_coverage/way_algebras.rb +2 -2
  39. data/lib/path_coverage/ways_report.rb +8 -8
  40. data/lib/path_coverage/ways_totals.rb +7 -7
  41. data/lib/path_coverage/within_methods.rb +61 -61
  42. metadata +12 -8
  43. data/lib/path_coverage/card_forks.rb +0 -44
  44. data/lib/path_coverage/card_ways.rb +0 -196
@@ -1,4 +1,4 @@
1
- require_relative 'card_context'
1
+ require_relative 'paths_context'
2
2
  require_relative 'console_summary'
3
3
  require_relative 'gaps'
4
4
  require_relative 'json_reader'
@@ -53,12 +53,12 @@ module PathCoverage
53
53
  end
54
54
 
55
55
  # Prints the summary lines: the paths taken of all possible
56
- # alone, and combined, each def's card of files as decision_paths
56
+ # alone, and combined, each def's flow of files as decision_paths
57
57
  # and reached have it; then any operators ignored.
58
58
  def self.summary(files, config, decision_paths, reached)
59
- cards = WithinMethods.cards(files, config, decision_paths,
59
+ flows = WithinMethods.flows(files, config, decision_paths,
60
60
  reached)
61
- puts ConsoleSummary.lines(decision_paths, cards,
61
+ puts ConsoleSummary.lines(decision_paths, flows,
62
62
  config.groups) +
63
63
  ConsoleSummary.ignored_lines(config.ignored)
64
64
  end
@@ -81,14 +81,14 @@ module PathCoverage
81
81
  # path taken that a treatment rules out, as outside lists
82
82
  # them, each leaf named by its text in files; then each path
83
83
  # taken, or return or raise reached, that its method rules
84
- # out, as CardContext.ruled_out finds them in files under
84
+ # out, as PathsContext.ruled_out finds them in files under
85
85
  # config. recorded is as run has it.
86
86
  def self.gaps(operands, files, config, recorded)
87
87
  texts = PathsReport.texts(files)
88
88
  paths, outside, reached =
89
89
  recorded.values_at(:decision_paths, :outside, :reached)
90
90
  lines = Gaps.lines(operands, paths:, texts:, outside:)
91
- ruled = CardContext.ruled_out(files, config, paths, reached)
91
+ ruled = PathsContext.ruled_out(files, config, paths, reached)
92
92
  lines += Gaps.ruled_by_method(ruled, texts)
93
93
  lines.each { |line| puts line }
94
94
  end
@@ -0,0 +1,174 @@
1
+ require 'prism'
2
+ require_relative 'decision'
3
+ require_relative 'leaving'
4
+
5
+ module PathCoverage
6
+ # The rescue forks of each def. Each begin with a rescue forks
7
+ # there, whether it is a def's body, a block's, or nested in a
8
+ # body. Either its body completes, or one of its rescues runs.
9
+ module RescueForks
10
+ # Example: { "k.rb:1:0" => { "k.rb:3:0" => [1, 0...30, 14...20,
11
+ # [38...40]] } } for a def at line 1 whose one rescue is at
12
+ # line 3.
13
+ # { def decision => { fork's name => [its rescues, its begin's
14
+ # byte range, its body's, [each rescue's body's]] } } for each
15
+ # def in source, at path. A fork is named where its first
16
+ # rescue is.
17
+ def self.of(source, path)
18
+ found(source, path).forks
19
+ end
20
+
21
+ # The Found that has visited each def in source, at path.
22
+ def self.found(source, path)
23
+ found = Found.new(path)
24
+ Prism.parse(source).value.accept(found)
25
+ found
26
+ end
27
+
28
+ # Finds the rescue fork of each def it visits.
29
+ class Found < Prism::Visitor
30
+ # Starts with no def visited. Forks are named as at path.
31
+ def initialize(path)
32
+ @path = path
33
+ @forks = {}
34
+ @completions = {}
35
+ @starts = {}
36
+ @values = {}
37
+ @def = nil
38
+ super()
39
+ end
40
+
41
+ # forks is { def decision => { fork's name => [its rescues,
42
+ # its begin's byte range, its body's, [each rescue's body's]]
43
+ # } }.
44
+ # completions is { fork's name => where its body completes }.
45
+ # starts is { [fork's name, rescue's number] => the byte
46
+ # offset where that rescue starts to run }. values is { fork's
47
+ # name => the byte range of a rescue modifier's rescue, its
48
+ # value }.
49
+ attr_reader :forks, :completions, :starts, :values
50
+
51
+ # Visits inside node, a def, noting the rescue forks in it as
52
+ # its own.
53
+ def visit_def_node(node)
54
+ outer = @def
55
+ @def = Decision.of(@path, node)
56
+ @forks[@def] = {}
57
+ super
58
+ @def = outer
59
+ end
60
+
61
+ # Notes node, a begin, as a rescue fork of the def it is in,
62
+ # when it has a rescue, then visits inside it. A def's body
63
+ # with a rescue is a begin, and so is a block's.
64
+ def visit_begin_node(node)
65
+ note_fork(node) unless @def.nil? || node.rescue_clause.nil?
66
+ super
67
+ end
68
+
69
+ # Notes node, a rescue modifier, x rescue y, as a rescue fork
70
+ # of the def it is in, then visits inside it. Its body is x,
71
+ # and its one rescue is y. Its name is where its rescue is.
72
+ def visit_rescue_modifier_node(node)
73
+ note_modifier(node) unless @def.nil?
74
+ super
75
+ end
76
+
77
+ # Notes the rescue fork of node, a rescue modifier.
78
+ def note_modifier(node)
79
+ name = Decision.at(@path, node.keyword_loc)
80
+ body = span(node.expression.location)
81
+ value = span(node.rescue_expression.location)
82
+ @forks[@def][name] = [1, span(node.location), body, [value]]
83
+ note_value(name, node.expression, value)
84
+ end
85
+
86
+ # Notes where the rescue modifier named name completes and
87
+ # where its rescue runs. It completes at expression, wrapped,
88
+ # unless that leaves. Its rescue runs at value, wrapped.
89
+ def note_value(name, expression, value)
90
+ if Leaving.word(expression).nil?
91
+ @completions[name] = span(expression.location)
92
+ end
93
+ @values[name] = value
94
+ end
95
+
96
+ # The byte range of location.
97
+ def span(location)
98
+ location.start_offset...location.end_offset
99
+ end
100
+
101
+ # Notes the rescue fork of node, a begin with a rescue. Its
102
+ # name is where its first rescue is.
103
+ def note_fork(node)
104
+ clause = node.rescue_clause
105
+ name = Decision.at(@path, clause.location)
106
+ note_completion(name, node.statements, clause)
107
+ count = noted(name, clause, 1)
108
+ @forks[@def][name] = [count, *spans_of(node, clause)]
109
+ end
110
+
111
+ # [the byte range of node, a begin, of its body, and of the
112
+ # body of each rescue from clause, its first].
113
+ def spans_of(node, clause)
114
+ whole = node.location
115
+ body = range_of(node.statements, clause.location.start_offset)
116
+ clauses = []
117
+ until clause.nil?
118
+ clauses << range_of(clause.statements,
119
+ header_end(clause))
120
+ clause = clause.subsequent
121
+ end
122
+ [whole.start_offset...whole.end_offset, body, clauses]
123
+ end
124
+
125
+ # The byte range of statements, or an empty range at offset
126
+ # when there are none.
127
+ def range_of(statements, offset)
128
+ return offset...offset if statements.nil?
129
+
130
+ loc = statements.location
131
+ loc.start_offset...loc.end_offset
132
+ end
133
+
134
+ # Notes where a body of statements completes. name is its
135
+ # fork's name, and clause its first rescue. An empty body
136
+ # completes at clause, by a byte offset, for a statement of
137
+ # its own. Otherwise it completes at its last statement, by
138
+ # its byte range, to wrap. A last statement that leaves is
139
+ # not noted, because that body never completes.
140
+ def note_completion(name, statements, clause)
141
+ if statements.nil?
142
+ return @completions[name] = clause.location.start_offset
143
+ end
144
+
145
+ last = statements.body.last
146
+ return unless Leaving.word(last).nil?
147
+
148
+ loc = last.location
149
+ @completions[name] = loc.start_offset...loc.end_offset
150
+ end
151
+
152
+ # How many rescues the fork named name has, counting from
153
+ # clause, the rescue numbered number. It notes where each
154
+ # rescue starts to run, after its header. Once the rescues
155
+ # run out it gives number less one.
156
+ def noted(name, clause, number)
157
+ return number - 1 if clause.nil?
158
+
159
+ @starts[[name, number]] = header_end(clause)
160
+ noted(name, clause.subsequent, number + 1)
161
+ end
162
+
163
+ # The byte offset where the header of clause, a rescue, ends.
164
+ # The header is its keyword, its exceptions, its => and
165
+ # reference, and its then, whichever of them it has.
166
+ def header_end(clause)
167
+ nodes = [*clause.exceptions, clause.reference].compact
168
+ locs = [clause.keyword_loc, clause.operator_loc,
169
+ clause.then_keyword_loc].compact
170
+ (nodes.map(&:location) + locs).map(&:end_offset).max
171
+ end
172
+ end
173
+ end
174
+ end
@@ -9,23 +9,91 @@ module PathCoverage
9
9
  module Rewriter
10
10
  # Returns source with each operand in decisions wrapped in a
11
11
  # record call, each decision as a whole in a leave call that
12
- # enters it first, and each statement in reaches, { name =>
13
- # offset }, after a reach call that counts its runs. Only
14
- # text is inserted, never a newline, so backtrace line
15
- # numbers still match the file on disk.
16
- def self.rewrite(source, decisions, reaches = {}, passes = {})
12
+ # enters it first, then the inserts of marks, as mark_inserts
13
+ # gives them. Only text is inserted, never a newline, so
14
+ # backtrace line numbers still match the file on disk.
15
+ def self.rewrite(source, decisions, marks = {})
17
16
  inserts = decisions.flat_map do |decision, condition|
18
17
  decision_inserts(decision, condition)
19
18
  end
20
- apply(source.dup, inserts + reach_inserts(reaches) +
21
- pass_inserts(passes))
19
+ apply(source.dup, inserts + mark_inserts(marks))
22
20
  end
23
21
 
22
+ # The inserts of marks, a hash. Each key is optional, and a
23
+ # missing key marks nothing. reaches is { name => offset }:
24
+ # each statement there gets a reach call before it, counting
25
+ # its runs. passes is { name => offset }: each loop body there
26
+ # gets a pass call first. entries is { name => offset }: each
27
+ # method's entry is reached there, outermost, before any
28
+ # statement's reach at the same place. completions is { rescue
29
+ # fork's name => where }: each body completing is noted there.
30
+ # rescues is { [fork's name, number] => offset }: each rescue
31
+ # running is noted there. values is { fork's name => byte
32
+ # range }: each rescue modifier's rescue running is noted
33
+ # there.
34
+ def self.mark_inserts(marks)
35
+ reach_inserts(marks.fetch(:reaches, {})) +
36
+ pass_inserts(marks.fetch(:passes, {})) +
37
+ reach_inserts(marks.fetch(:entries, {}), :entry) +
38
+ completed_inserts(marks.fetch(:completions, {})) +
39
+ rescued_inserts(marks.fetch(:rescues, {})) +
40
+ ran_inserts(marks.fetch(:values, {}))
41
+ end
42
+
43
+ # Example: { "k.rb:3:18" => 25...26 } wraps bytes 25...26.
44
+ # The inserts that wrap the rescue of each rescue modifier in
45
+ # values, { fork's name => its byte range }, in a ran call. The
46
+ # call keeps the rescue's value, and notes that its rescue 1
47
+ # ran.
48
+ def self.ran_inserts(values)
49
+ values.flat_map do |name, range|
50
+ rank = [range.size, LAYERS.index(:completed)]
51
+ call = "PathCoverage.ran(#{name.inspect}, 1, ("
52
+ [[range.begin, call, rank], [range.end, '))', rank, :close]]
53
+ end
54
+ end
55
+
56
+ # Example: { ["k.rb:4:2", 1] => 52 } puts a rescued call at 52.
57
+ # The inserts that put a rescued call after the header of each
58
+ # rescue in rescues, { [fork's name, its number] => offset }.
59
+ # The call is a statement of its own, the first its rescue
60
+ # runs.
61
+ def self.rescued_inserts(rescues)
62
+ rank = [Float::INFINITY, LAYERS.index(:reach)]
63
+ rescues.map do |(name, number), at|
64
+ call = "; PathCoverage.rescued(#{name.inspect}, #{number})"
65
+ [at, call, rank]
66
+ end
67
+ end
68
+
69
+ # Example: { "k.rb:4:2" => 30...43 } wraps bytes 30...43.
70
+ # The inserts that note each body of completions completing.
71
+ # completions is { rescue fork's name => where }. A byte range
72
+ # is a last statement, wrapped in a completed call that keeps
73
+ # its value, inside any reach before it. A byte offset is an
74
+ # empty body. It gets a completed call of nil, a statement of
75
+ # its own, because the body's value is nil either way.
76
+ def self.completed_inserts(completions)
77
+ completions.flat_map do |name, at|
78
+ call = "PathCoverage.completed(#{name.inspect}, "
79
+ next [[at, "#{call}nil); ", own_rank]] unless at.is_a?(Range)
80
+
81
+ rank = [at.size, LAYERS.index(:completed)]
82
+ [[at.begin, "#{call}(", rank], [at.end, '))', rank, :close]]
83
+ end
84
+ end
85
+
86
+ # The rank of a completed call that is a statement of its own,
87
+ # for an empty body. It is inside any reach at the same place.
88
+ def self.own_rank = [Float::INFINITY, LAYERS.index(:completed)]
89
+
24
90
  # Example: { "k.rb:4:16" => 60 } puts a pass call at 60.
25
91
  # The inserts that put a pass call, a statement of its own,
26
- # first in each loop body in passes, { name => offset }.
92
+ # first in each loop body in passes, { name => offset }. It
93
+ # comes before the reach of a row at the same place, so the
94
+ # row is a step of the pass.
27
95
  def self.pass_inserts(passes)
28
- rank = [Float::INFINITY, LAYERS.index(:reach)]
96
+ rank = [Float::INFINITY, LAYERS.index(:pass)]
29
97
  passes.map do |name, at|
30
98
  [at, "PathCoverage.pass(#{name.inspect}); ", rank]
31
99
  end
@@ -34,11 +102,11 @@ module PathCoverage
34
102
  # Example: { "k.rb:2:2" => 18 } puts a reach call at 18.
35
103
  # The inserts that put a reach call, a statement of its
36
104
  # own, before each statement in reaches, outside all else
37
- # there. A statement reached by
105
+ # there, in layer. A statement reached by
38
106
  # its byte range, eg an endless def's body, is wrapped in
39
107
  # parentheses with its call, being one expression.
40
- def self.reach_inserts(reaches)
41
- rank = [Float::INFINITY, LAYERS.index(:reach)]
108
+ def self.reach_inserts(reaches, layer = :reach)
109
+ rank = [Float::INFINITY, LAYERS.index(layer)]
42
110
  reaches.flat_map do |name, at|
43
111
  call = "PathCoverage.reach(#{name.inspect}); "
44
112
  next [[at, call, rank]] unless at.is_a?(Range)
@@ -98,8 +166,9 @@ module PathCoverage
98
166
  # The layers of inserts, innermost first, that break a tie
99
167
  # between inserts wrapping the same range: a leaf's call, a
100
168
  # nested kind's call around its whole, eg end_items, a decision's
101
- # leave, and a statement's reach.
102
- LAYERS = %i[leaf kind decision reach].freeze
169
+ # leave, a rescue body's last statement's completed, a
170
+ # statement's reach, a loop's pass, and a method's entry.
171
+ LAYERS = %i[leaf kind decision completed reach pass entry].freeze
103
172
 
104
173
  # The two inserts that wrap the code at range in call. Their
105
174
  # order, [size, rank], nests them among inserts at the same
@@ -14,18 +14,18 @@ module PathCoverage
14
14
  SCHEMA = 1
15
15
 
16
16
  # The URL of the schema the source report follows.
17
- SCHEMA_URL = 'https://path-coverage.github.io/schemas/v1/' \
17
+ SCHEMA_URL = 'https://path-coverage.github.io/schemas/v2/' \
18
18
  'path_coverage.source.schema.json'.freeze
19
19
 
20
20
  # The source report of a run, headed by its schema's URL and
21
21
  # version: config's ignored operators, the
22
22
  # covered files of each of config's groups, each top of the
23
- # rows of cards, { def decision => card }, coloured, and each of
23
+ # rows of flows, { def decision => flow }, coloured, and each of
24
24
  # files', { full path => {source:, decisions:} }, lines and
25
25
  # decisions, each decision's paths as decision_paths has
26
26
  # them, its fold headed by its row's top.
27
- def self.of(files, config, decision_paths, cards)
28
- rows = cards.values.flat_map { _1['rows'] }
27
+ def self.of(files, config, decision_paths, flows)
28
+ rows = flows.values.flat_map { _1['rows'] }
29
29
  tops = rows.to_h { [_1['decision'], _1['top']] }
30
30
  shown = files.to_h do |full_path, parsed|
31
31
  [config.relative(full_path),
@@ -2,7 +2,7 @@ require 'prism'
2
2
  require_relative 'condition'
3
3
 
4
4
  module PathCoverage
5
- # The leaves of a card whose outcomes cannot differ within one
5
+ # The leaves of a flow whose outcomes cannot differ within one
6
6
  # call: each a read of a local variable that its method never
7
7
  # writes, eg a parameter, where the leaf's outcome is the
8
8
  # variable's truthiness. Every such read in a call has the same
@@ -25,10 +25,10 @@ module PathCoverage
25
25
  # Example: { 32...33 => :a, 54...55 => :a } for def f(a),
26
26
  # return 0 if a, then a ? 1 : 2.
27
27
  # { leaf byte range => local name } for each truthy leaf of
28
- # the decisions of rows, a card's in source, decisions being
28
+ # the decisions of rows, a flow's in source, decisions being
29
29
  # { decision => Condition }, that reads, outside any block, a
30
30
  # local its def never writes, for each name two or more such
31
- # leaves read; none for a card in no def, or one whose def
31
+ # leaves read; none for a flow in no def, or one whose def
32
32
  # calls any of REWRITERS.
33
33
  def self.of(source, decisions, rows)
34
34
  conditions = decisions.values_at(*rows.map(&:decision).compact)
@@ -1,7 +1,7 @@
1
1
  module PathCoverage
2
- # The lists of statements a method's card has rows for: a def's
2
+ # The lists of statements a method's flow has rows for: a def's
3
3
  # body, the arms of each decision in it whose arms are statements,
4
- # and the body of each block in it, as the card lays them out
4
+ # and the body of each block in it, as the flow lays them out
5
5
  # flat. It relies on its includer's rows_in, decision? and
6
6
  # decision_name.
7
7
  module StatementArms
@@ -9,7 +9,7 @@ module PathCoverage
9
9
  # block's, a lambda's and a begin's statements are rows of
10
10
  # their own, after the statement holding them, and a def's
11
11
  # body runs only when it is called, its decisions rows of its own
12
- # card.
12
+ # flow.
13
13
  UNSEEN = %i[block_node begin_node def_node lambda_node].freeze
14
14
 
15
15
  # Example: if/else for if a then 1 else 2 end.
@@ -23,11 +23,13 @@ module PathCoverage
23
23
  clause&.type == :else_node ? "#{operator}/else" : operator
24
24
  end
25
25
 
26
- # The tops of statements that end a path, leaving the method.
27
- LEAVING = %w[return raise].freeze
26
+ # The tops of statements that end a path. A return or a raise
27
+ # leaves the method. A next, a break or a retry leaves its pass
28
+ # or its loop.
29
+ LEAVING = %w[return raise next break retry].freeze
28
30
 
29
31
  # True for a row that shapes its method's paths: a decision, or a
30
- # return or a raise, which ends a path. Any other, eg x = 1,
32
+ # statement in LEAVING, which ends a path. Any other, eg x = 1,
31
33
  # runs exactly where what holds it does, so is no row.
32
34
  def shapes?(node)
33
35
  decision?(node) || LEAVING.include?(top_of(node))
@@ -40,11 +42,23 @@ module PathCoverage
40
42
  body = node.body
41
43
  return node.end_keyword_loc.start_offset if body.nil?
42
44
 
43
- loc = body.location
45
+ loc = entered(body).location
44
46
  start = loc.start_offset
45
47
  node.equal_loc ? start...loc.end_offset : start
46
48
  end
47
49
 
50
+ # The node where body, a def's, is entered on every call.
51
+ # Usually that is body itself. A body with a rescue or an
52
+ # ensure has a begin that starts at the def. Its statements
53
+ # are entered instead. With no statements, its first rescue
54
+ # is, or else its ensure.
55
+ def entered(body)
56
+ return body unless body.type == :begin_node
57
+
58
+ [body.statements, body.rescue_clause, body.ensure_clause]
59
+ .compact.first
60
+ end
61
+
48
62
  # Example: return a ? 1 : 2 if x gives the ?:.
49
63
  # The decisions inside decision that are decisions of their
50
64
  # own, in the order they are written: in its leaves, eg a
@@ -54,7 +68,7 @@ module PathCoverage
54
68
  # where a decision does, eg a ?:'s predicate, names that
55
69
  # decision: each is kept once, and decision itself not at
56
70
  # all. None for a top that is no decision, eg a def inside a
57
- # def, whose decisions are on its own card.
71
+ # def, whose decisions are on its own flow.
58
72
  def inner_decisions(decision)
59
73
  return [] unless decision?(decision)
60
74
 
@@ -87,7 +101,7 @@ module PathCoverage
87
101
  # The body of each block and lambda in node, run 0 or more
88
102
  # times, and each begin: none inside an arm of statements or
89
103
  # another body, whose rows are their own, nor in a def, whose
90
- # rows are its own card's.
104
+ # rows are its own flow's.
91
105
  def bodies_in(node)
92
106
  case node.type
93
107
  when :def_node then []
@@ -12,12 +12,12 @@ module PathCoverage
12
12
  [every.count { |each| each[:count].positive? }, every.size]
13
13
  end
14
14
 
15
- # Example: cards [4, 6] and [17, 21] give [21, 27].
16
- # Paths combined through each method: cards is { def decision =>
17
- # [taken, size] }, each method's card's paths taken of its
15
+ # Example: flows [4, 6] and [17, 21] give [21, 27].
16
+ # Paths combined through each method: flows is { def decision =>
17
+ # [taken, size] }, each method's flow's paths taken of its
18
18
  # size, its rows' paths added up.
19
- def self.combined(cards)
20
- cards.values.reduce([0, 0]) do |(taken, possible), (more, of)|
19
+ def self.combined(flows)
20
+ flows.values.reduce([0, 0]) do |(taken, possible), (more, of)|
21
21
  [taken + more, possible + of]
22
22
  end
23
23
  end
@@ -1,3 +1,3 @@
1
1
  module PathCoverage
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
@@ -1,5 +1,5 @@
1
1
  module PathCoverage
2
- # The algebras CardWays can fold a card's ways in, each giving
2
+ # The algebras PathsWays can fold a flow's ways in, each giving
3
3
  # no ways, the one way through no rows, the one way taking a
4
4
  # labelled path, and ways added and joined one after another.
5
5
  # A way's label at a row is [row key, path index].
@@ -38,7 +38,7 @@ module PathCoverage
38
38
  def self.plus(ways, more) = ways | more
39
39
 
40
40
  # The labels of each way of ways going on to each of more:
41
- # every one of either, as CardWays never joins no ways.
41
+ # every one of either, as PathsWays never joins no ways.
42
42
  def self.times(ways, more) = ways | more
43
43
  end
44
44
 
@@ -1,7 +1,7 @@
1
1
  require 'json'
2
2
 
3
3
  module PathCoverage
4
- # A method card's taken ways, and its loops' passes, as the JSON
4
+ # A method flow's taken ways, and its loops' passes, as the JSON
5
5
  # report lists them: each way the steps one call, or one pass,
6
6
  # took, in order, a decision's {"at", "path"}, a loop's {"at",
7
7
  # "path", "passes"}, its path how many passes it made, or any
@@ -36,15 +36,15 @@ module PathCoverage
36
36
  end
37
37
 
38
38
  # { method's entry, or loop's name => { way => count } } of a
39
- # JSON report's cards, as a CallTrace counts them: each card
40
- # listing its calls' ways and its loops' passes; a top card
39
+ # JSON report's flows, as a CallTrace counts them: each flow
40
+ # listing its calls' ways and its loops' passes; a top flow
41
41
  # lists neither, as no call runs it.
42
42
  def self.ways(report)
43
- report['cards'].each_with_object({}) do |(entry, card), found|
44
- next unless card.key?('taken')
43
+ report['flows'].each_with_object({}) do |(entry, flow), found|
44
+ next unless flow.key?('taken')
45
45
 
46
- found[entry] = read(entry, card['taken'])
47
- card['passes'].each do |at, passes|
46
+ found[entry] = read(entry, flow['taken'])
47
+ flow['passes'].each do |at, passes|
48
48
  loop = named(entry, at)
49
49
  found[loop] = read(loop, passes)
50
50
  end
@@ -82,7 +82,7 @@ module PathCoverage
82
82
  end
83
83
 
84
84
  # The line:column of the row or loop named name, the column two
85
- # digits, as a card's rows have it: "k.rb:4:6" gives "4:06".
85
+ # digits, as a flow's rows have it: "k.rb:4:6" gives "4:06".
86
86
  def self.at(name)
87
87
  line, column = name.split(':').last(2)
88
88
  format('%<line>s:%<column>02d', line:, column: Integer(column))
@@ -11,8 +11,8 @@ module PathCoverage
11
11
  # impossible, or more paths than its max_paths.
12
12
  def self.failed?(report)
13
13
  listed, over = methods(report)
14
- untaken = listed.sum do |card|
15
- card['gaps'].size + card['impossible_taken'].size
14
+ untaken = listed.sum do |flow|
15
+ flow['gaps'].size + flow['impossible_taken'].size
16
16
  end
17
17
  !over.empty? || untaken.positive?
18
18
  end
@@ -30,15 +30,15 @@ module PathCoverage
30
30
  "Functions over --max-paths=#{limit}: #{over.size}"]
31
31
  end
32
32
 
33
- # [listed, over] of report's method cards: those listing their
33
+ # [listed, over] of report's method flows: those listing their
34
34
  # ways, and those with more paths than its max_paths, which
35
- # list none. A top card, run by no call, has no taken ways, so
35
+ # list none. A top flow, run by no call, has no taken ways, so
36
36
  # is in neither.
37
37
  def self.methods(report)
38
- found = report['cards'].values.group_by do |card|
39
- next :top unless card.key?('taken')
38
+ found = report['flows'].values.group_by do |flow|
39
+ next :top unless flow.key?('taken')
40
40
 
41
- card.key?('covered') ? :listed : :over
41
+ flow.key?('covered') ? :listed : :over
42
42
  end
43
43
  [found.fetch(:listed, []), found.fetch(:over, [])]
44
44
  end