path_coverage 0.7.0 → 0.7.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72f61105ee75c749617db00548e9d803bcae76919e51cac6b0a081b93eca54b4
4
- data.tar.gz: deec7238a3260dceecdb937464246a5b0d7b502c73826a6bde0947a611713b22
3
+ metadata.gz: 606de09991d4d1b5030cf4aaf30a6c2c611504ec9264056edcf060c0805cc2e3
4
+ data.tar.gz: e388a444fd0d651a640a3703ed3df432ebee62ad631b00edebc5f389c736360e
5
5
  SHA512:
6
- metadata.gz: e7b265531ef2dc15e67e3554d0cae1292163dd3874333a10546822bdb62dd06ceea24ecb12bfd62dad4d32d16eb2c9b3329eddfd3d26d8d3b73e96077f81a912
7
- data.tar.gz: d847e2497b63d34f392cd88d6b538fa3b5fc1ab92796a183e4cae55176c1edb43cf499310c31f1b4a0c8d5fbb75705c89f9153f938828c4ca7b2bd2619447357
6
+ metadata.gz: aae97e3b6a3d8c704a49bbde46aa341ae7d7e923d1e9d98fb6f63c53fca88a794b1b4a9f652649168b7e6854f847e9f7b7cf05e3418e93a933d6b40f4920f8a7
7
+ data.tar.gz: c49ef7782c1d2d5b3b20f0c9452bf4f535e71dba869fc306113d295912d10bfe7d9bf952dd2a25c4a15fbbd22ad1781472a783274159ed541c53d2c73bbe223a
@@ -74,6 +74,12 @@ module PathCoverage
74
74
  # raise, nil for an arm that does not leave the method.
75
75
  Arm = Data.define(:kind, :extent, :body, :leaves)
76
76
 
77
+ # The members a Condition need not be given: no command-call
78
+ # or fixed leaves, no extent and no site.
79
+ CONDITION_OPTIONAL = {
80
+ commands: [].freeze, fixed: {}.freeze, extent: nil, site: nil
81
+ }.freeze
82
+
77
83
  # One decision's condition as the manifest found it: its operator
78
84
  # and its operands, each the byte range of a leaf or a nested
79
85
  # Condition. A decision's commands are the byte ranges of its
@@ -82,16 +88,18 @@ module PathCoverage
82
88
  # outcome only, eg `Clock.new`. Its extent is the byte range
83
89
  # of the whole condition as written, eg a ternary's from its
84
90
  # predicate to its else arm, which its leaves alone cannot
85
- # give.
91
+ # give. Its site is the node_id Prism gives the node it is the
92
+ # decision of, the same in every parse of the same source, so
93
+ # that node, and no other starting where it does, is known as
94
+ # the decision; nil for a Condition that is no decision of its
95
+ # own, eg one nested in another's leaf, which no node is.
86
96
  Condition = Data.define(
87
- :operator, :operands, :commands, :fixed, :extent
97
+ :operator, :operands, :commands, :fixed, :extent, :site
88
98
  ) do
89
- # A condition with no command-call or fixed leaves, and no
90
- # extent, by default.
91
- def initialize(
92
- operator:, operands:, commands: [], fixed: {}, extent: nil
93
- )
94
- super
99
+ # A condition of operator and operands, each member of
100
+ # CONDITION_OPTIONAL given, or else its default.
101
+ def initialize(operator:, operands:, **given)
102
+ super(operator:, operands:, **CONDITION_OPTIONAL, **given)
95
103
  end
96
104
 
97
105
  # The byte range of every leaf operand, left to right, a
@@ -12,5 +12,12 @@ module PathCoverage
12
12
  def self.at(path, loc)
13
13
  "#{path}:#{loc.start_line}:#{loc.start_column}"
14
14
  end
15
+
16
+ # Example: "src/a:b.rb" for "src/a:b.rb:2:2".
17
+ # The path name names a decision in, all of it before its
18
+ # line and column, a colon in the path kept.
19
+ def self.path_of(name)
20
+ name.sub(/:\d+:\d+\z/, '')
21
+ end
15
22
  end
16
23
  end
@@ -0,0 +1,40 @@
1
+ require_relative 'decision'
2
+
3
+ module PathCoverage
4
+ # Decision mode's decisions in one file, each known by its site:
5
+ # the one node it is the decision of, by the node_id Prism gives
6
+ # it in every parse of the file. A node is a decision exactly
7
+ # when it is a site, never because it starts where one does, as
8
+ # the statements holding an if first do.
9
+ class DecisionSites
10
+ # The sites of decisions, { decision => Condition }, as
11
+ # Manifest.decisions gives them for the file at path. A
12
+ # decision named in another file is refused: a row would be
13
+ # named by one path and its decision by another.
14
+ def initialize(path, decisions)
15
+ @decisions = decisions
16
+ @names = decisions.to_h do |name, condition|
17
+ unless Decision.path_of(name) == path
18
+ raise ArgumentError, "decision #{name} is not in #{path}"
19
+ end
20
+
21
+ [condition.site, name]
22
+ end
23
+ end
24
+
25
+ # The name of the decision node is the site of, eg "k.rb:2:5";
26
+ # nil when node is the site of none.
27
+ def name_of(node)
28
+ @names[node.node_id]
29
+ end
30
+
31
+ # The Condition of the decision node is the site of; nil when
32
+ # node is the site of none.
33
+ def condition_of(node)
34
+ name = name_of(node)
35
+ return nil if name.nil?
36
+
37
+ @decisions.fetch(name)
38
+ end
39
+ end
40
+ end
@@ -67,14 +67,17 @@ module PathCoverage
67
67
  KEYWORDS.include?(loop.type) ? loop.statements : loop.body
68
68
  end
69
69
 
70
- # True for a keyword loop written after its body, eg x += 1
71
- # while x < 9, where a call put first in its body would run
72
- # once, not each pass, so none goes there.
70
+ # The types of node that are loops written after their body
71
+ # when they have no end of their own.
72
+ MODIFIABLE = %i[while_node until_node].freeze
73
+
74
+ # True for a loop written after its body, eg x += 1 while
75
+ # x < 9, or begin ... end while x < 9: a while or until with no
76
+ # end of its own, where a call put first in its body would run
77
+ # once, not each pass, so none goes there. A for always has
78
+ # its end, and an empty loop is no modifier.
73
79
  def self.modifier?(loop)
74
- return false unless KEYWORDS.include?(loop.type)
75
-
76
- body = loop.statements.location
77
- loop.keyword_loc.start_offset > body.start_offset
80
+ MODIFIABLE.include?(loop.type) && loop.closing_loc.nil?
78
81
  end
79
82
 
80
83
  # The first statement of a loop's body, a do ... rescue ... end
@@ -181,7 +181,8 @@ module PathCoverage
181
181
  end
182
182
 
183
183
  # Notes node as a decision, named where it starts: an if or an
184
- # unless at its keyword. It claims its place first, so a
184
+ # unless at its keyword; its site node's node_id, so node is
185
+ # the one node known as it. It claims its place first, so a
185
186
  # decision found inside one of its leaves or arms follows it.
186
187
  # While a leaf is being visited, any decision is collected as
187
188
  # part of that leaf instead, as it is part of one expression.
@@ -194,7 +195,8 @@ module PathCoverage
194
195
  outer = @notes
195
196
  @notes = { commands: [], fixed: {} }
196
197
  condition = scoped { condition_of(node) }
197
- @decisions[decision] = condition.with(**@notes)
198
+ @decisions[decision] =
199
+ condition.with(**@notes, site: node.node_id)
198
200
  @notes = outer
199
201
  end
200
202
 
@@ -4,9 +4,10 @@ require_relative 'manifest_chains'
4
4
  require_relative 'manifest_choices'
5
5
  require_relative 'decision'
6
6
  require_relative 'decision_paths'
7
+ require_relative 'decision_sites'
7
8
  require_relative 'decision_tree'
8
- require_relative 'leaving'
9
9
  require_relative 'statement_arms'
10
+ require_relative 'statement_tops'
10
11
  require_relative 'totals'
11
12
 
12
13
  module PathCoverage
@@ -152,12 +153,15 @@ module PathCoverage
152
153
  include ManifestChains
153
154
  include ManifestChoices
154
155
  include StatementArms
156
+ include StatementTops
155
157
 
156
158
  # Starts with no methods found; decisions are decision mode's,
157
- # { decision => Condition }.
159
+ # { decision => Condition }, each known by its site, as
160
+ # DecisionSites has them.
158
161
  def initialize(path, decisions)
159
162
  @path = path
160
163
  @decisions = decisions
164
+ @sites = DecisionSites.new(path, decisions)
161
165
  @methods = {}
162
166
  @names = {}
163
167
  @lasts = {}
@@ -229,19 +233,33 @@ module PathCoverage
229
233
  end
230
234
  end
231
235
 
232
- # The Statement row of node. A decision is where decision mode
233
- # names it, eg a modifier if at its keyword, with as many
234
- # paths as decision mode gives it. Anything else is where
235
- # it starts, with 1 path.
236
+ # The Statement row of node: a decision's row for the site of
237
+ # a decision, a plain row for any other node.
236
238
  def row_of(node)
237
- decision = decision_at(node)
238
- loc = decision ? decision_loc(node) : node.location
239
- name = Decision.at(@path, loc)
239
+ name = @sites.name_of(node)
240
+ name.nil? ? plain_row(node) : decision_row(node, name)
241
+ end
242
+
243
+ # The row of node, the site of the decision named name: at its
244
+ # decision_loc, eg a modifier if at its keyword, with as many
245
+ # paths as decision mode gives the decision.
246
+ def decision_row(node, name)
247
+ loc = decision_loc(node)
248
+ paths = DecisionPaths.possible(@decisions.fetch(name)).size
249
+ Statement.new(
250
+ line: loc.start_line, column: loc.start_column,
251
+ top: top_of(node), paths:, decision: name, name:
252
+ )
253
+ end
254
+
255
+ # The row of node, the site of no decision: named where it
256
+ # starts, with 1 path.
257
+ def plain_row(node)
258
+ loc = node.location
240
259
  Statement.new(
241
260
  line: loc.start_line, column: loc.start_column,
242
- top: top_of(node),
243
- paths: decision ? DecisionPaths.possible(decision).size : 1,
244
- decision: decision ? name : nil, name:
261
+ top: top_of(node), paths: 1, decision: nil,
262
+ name: Decision.at(@path, loc)
245
263
  )
246
264
  end
247
265
 
@@ -266,55 +284,16 @@ module PathCoverage
266
284
  end
267
285
  end
268
286
 
269
- # True when decision mode has a decision named where node's
270
- # decision would start.
287
+ # True when node is the site of one of decision mode's
288
+ # decisions.
271
289
  def decision?(node)
272
- !decision_at(node).nil?
290
+ !@sites.name_of(node).nil?
273
291
  end
274
292
 
275
- # Decision mode's Condition for the decision named where
276
- # node's decision would start; nil when it has none there.
293
+ # Decision mode's Condition for the decision node is the site
294
+ # of; nil when node is the site of none.
277
295
  def decision_at(node)
278
- @decisions[decision_name(node)]
279
- end
280
-
281
- # The name node's decision would have, by where it would start.
282
- def decision_name(node)
283
- Decision.at(@path, decision_loc(node))
284
- end
285
-
286
- TOPS = { call_node: '()', def_node: 'def' }.freeze
287
-
288
- # What statement is as written: a decision's operator, eg if,
289
- # when decision mode has a decision where it starts, an elsif
290
- # being elsif, as written, an if or unless with an else
291
- # if/else or unless/else; else = for a write, Leaving's word,
292
- # return or raise, for a statement that leaves the method,
293
- # () for a call, def for a def inside it, value for anything
294
- # else.
295
- def top_of(statement)
296
- decision = decision_at(statement)
297
- return 'elsif' if decision && elsif?(statement)
298
- return with_else(decision.operator, statement) if decision
299
- return '=' if write?(statement)
300
-
301
- word = Leaving.word(statement)
302
- return word if word
303
-
304
- TOPS.fetch(statement.type, 'value')
305
- end
306
-
307
- # True for an if written as an elsif.
308
- def elsif?(statement)
309
- statement.type == :if_node && statement.if_keyword == 'elsif'
310
- end
311
-
312
- # True for a write of any kind: of a variable, eg @x = 1
313
- # or x += 1, or a call Ruby makes of an index or attribute
314
- # write, eg a[i] = x or a.b = x.
315
- def write?(statement)
316
- statement.type.end_with?('_write_node') ||
317
- (statement.type == :call_node && statement.attribute_write?)
296
+ @sites.condition_of(node)
318
297
  end
319
298
  end
320
299
  end
@@ -1,6 +1,8 @@
1
+ require_relative 'loop_forks'
1
2
  require_relative 'paths_tree'
2
3
  require_relative 'paths_ways'
3
4
  require_relative 'method_statements'
5
+ require_relative 'rescue_forks'
4
6
  require_relative 'way_algebras'
5
7
 
6
8
  module PathCoverage
@@ -9,22 +11,39 @@ module PathCoverage
9
11
  # and any taken that it rules out, which are counted, never
10
12
  # dropped, and reported. Paths combined count these, where paths
11
13
  # alone count each decision's paths on its own.
12
- # paths is as Result#paths gives it, and reached as
13
- # Recorder#reached does, nil when not known.
14
+ # recorded is [paths, reached]: paths as Result#paths gives it,
15
+ # and reached as Recorder#reached does, nil when not known.
16
+ # scopes is a def's [loop forks, rescue forks, forking], as
17
+ # scopes_of gives them, the scopes its flow is folded with.
14
18
  module PathsContext
15
19
  # Example: { "k.rb:1:0" => [2, 3] } for ship, its first row's
16
20
  # 2 paths both taken, its second's 1 path, of 2, that its
17
21
  # method can take, not taken.
18
- # Each def's flow total in source, [taken, size], its rows'
19
- # taken as MethodStatements.taken gives them, a row not known
20
- # counting as not taken, and its size their paths as rows
21
- # gives them.
22
- def self.totals(source, path, paths, reached, decisions)
22
+ # Each def's flow total in source, at path, [taken, size], its
23
+ # rows' taken as MethodStatements.taken gives them, a row not
24
+ # known counting as not taken, and its size their paths as rows
25
+ # gives them. forking says whether loops fork.
26
+ def self.totals(source, path, recorded, decisions, forking)
27
+ scopes = scopes_of(source, path, forking)
23
28
  flows = MethodStatements.of(source, path, decisions)
24
- flows.transform_values do |rows|
25
- shown = rows(source, decisions, rows, paths, reached)
29
+ flows.to_h do |key, rows|
30
+ shown = rows(source, decisions, rows, recorded,
31
+ scopes.fetch(key))
26
32
  seen = shown.filter_map(&:last).sum
27
- [seen, MethodStatements.size(shown.map { _1.first.paths })]
33
+ size = MethodStatements.size(shown.map { _1.first.paths })
34
+ [key, [seen, size]]
35
+ end
36
+ end
37
+
38
+ # Example: { "k.rb:1:0" => [{}, { "k.rb:3:2" => [...] }, false] }
39
+ # for a def at line 1 with no loop and one rescue fork.
40
+ # { def decision => its scopes } for each def in source, at
41
+ # path: its loops, as LoopForks gives them, its rescue forks,
42
+ # as RescueForks gives them, and forking, whether loops fork.
43
+ def self.scopes_of(source, path, forking)
44
+ forks = LoopForks.of(source, path)
45
+ RescueForks.of(source, path).to_h do |key, rescues|
46
+ [key, [forks.fetch(key), rescues, forking]]
28
47
  end
29
48
  end
30
49
 
@@ -32,27 +51,30 @@ module PathCoverage
32
51
  # as its paths how many of them its method can take or took,
33
52
  # as of gives them, and taken as MethodStatements.taken gives
34
53
  # it.
35
- def self.rows(source, decisions, rows, paths, reached)
36
- context = of(source, decisions, rows, paths, reached)
54
+ def self.rows(source, decisions, rows, recorded, scopes)
55
+ context = of(source, decisions, rows, recorded, scopes)
37
56
  shown = rows.zip(context).map do |row, (can, took)|
38
57
  row.with(paths: (can | took).size)
39
58
  end
40
- shown.zip(MethodStatements.taken(rows, paths, reached))
59
+ shown.zip(MethodStatements.taken(rows, *recorded))
41
60
  end
42
61
 
43
62
  # Example: [[[1], [1]], [[0, 1], [0]]] for return 0 if a, then
44
63
  # a ?: of b, called once with a false and b true.
45
64
  # [the indices of its paths its method can take, those taken]
46
65
  # for each of rows, a flow's in source: those on some way
47
- # through the flow, as WayAlgebras::Labelled folds them; and
48
- # those taken, a return's or a raise's one path index 0.
49
- def self.of(source, decisions, rows, paths, reached)
66
+ # through the flow folded with scopes, as WayAlgebras::Labelled
67
+ # folds them, so each rescue's rows are an alternative to the
68
+ # others'; and those taken, a return's or a raise's one path
69
+ # index 0.
70
+ def self.of(source, decisions, rows, recorded, scopes)
50
71
  labelled = WayAlgebras::Labelled
51
- labels = PathsWays.flow(source, decisions, rows, labelled)
72
+ labels = PathsWays.flow(source, decisions, rows, labelled,
73
+ [true, *scopes])
52
74
  by_key = labels.group_by(&:first)
53
75
  rows.map do |row|
54
76
  can = by_key.fetch(PathsTree.key_of(row), []).map(&:last)
55
- [can, taken_paths(row, paths, reached)]
77
+ [can, taken_paths(row, *recorded)]
56
78
  end
57
79
  end
58
80
 
@@ -77,9 +99,11 @@ module PathCoverage
77
99
  files.flat_map do |full_path, parsed|
78
100
  source, decisions = parsed.values_at(:source, :decisions)
79
101
  path = config.relative(full_path)
102
+ scopes = scopes_of(source, path, config.loops?)
80
103
  flows = MethodStatements.of(source, path, decisions)
81
- flows.values.flat_map do |rows|
82
- ruled_in(source, decisions, rows, paths, reached)
104
+ flows.flat_map do |key, rows|
105
+ ruled_in(source, decisions, rows, [paths, reached],
106
+ scopes.fetch(key))
83
107
  end
84
108
  end
85
109
  end
@@ -87,8 +111,9 @@ module PathCoverage
87
111
  # [name, path] for each path of rows, a flow's in source, taken
88
112
  # though its method rules it out: a decision's name and the
89
113
  # path, as paths has it; a return's or a raise's and nil.
90
- def self.ruled_in(source, decisions, rows, paths, reached)
91
- context = of(source, decisions, rows, paths, reached)
114
+ def self.ruled_in(source, decisions, rows, recorded, scopes)
115
+ context = of(source, decisions, rows, recorded, scopes)
116
+ paths = recorded.first
92
117
  rows.zip(context).flat_map do |row, (can, took)|
93
118
  (took - can).map { [row.name, path_at(row, _1, paths)] }
94
119
  end
@@ -3,7 +3,7 @@ module PathCoverage
3
3
  # body, the arms of each decision in it whose arms are statements,
4
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
- # decision_name.
6
+ # top_of.
7
7
  module StatementArms
8
8
  # The nodes a statement's decisions are never looked for in: a
9
9
  # block's, a lambda's and a begin's statements are rows of
@@ -12,17 +12,6 @@ module PathCoverage
12
12
  # flow.
13
13
  UNSEEN = %i[block_node begin_node def_node lambda_node].freeze
14
14
 
15
- # Example: if/else for if a then 1 else 2 end.
16
- # operator, a decision node's, with /else after it when node is an
17
- # if or an unless with an else, so its row names both arms;
18
- # operator alone for any other, eg a ?:, whose arms are ? and :.
19
- def with_else(operator, node)
20
- return operator unless %w[if unless].include?(operator)
21
-
22
- clause = operator == 'if' ? node.subsequent : node.else_clause
23
- clause&.type == :else_node ? "#{operator}/else" : operator
24
- end
25
-
26
15
  # The tops of statements that end a path. A return or a raise
27
16
  # leaves the method. A next, a break or a retry leaves its pass
28
17
  # or its loop.
@@ -64,17 +53,13 @@ module PathCoverage
64
53
  # own, in the order they are written: in its leaves, eg a
65
54
  # modifier if's arm or a &. call's receiver; not in its arms
66
55
  # of statements, nor in a body, which have rows of their own.
67
- # A decision is named where it starts, so a node starting
68
- # where a decision does, eg a ?:'s predicate, names that
69
- # decision: each is kept once, and decision itself not at
70
- # all. None for a top that is no decision, eg a def inside a
71
- # def, whose decisions are on its own flow.
56
+ # Each is its own site node, found once. None for a top that
57
+ # is no decision, eg a def inside a def, whose decisions are
58
+ # on its own flow.
72
59
  def inner_decisions(decision)
73
60
  return [] unless decision?(decision)
74
61
 
75
- found = heads(decision).flat_map { decisions_within(_1) }
76
- named = found.to_h { [decision_name(_1), _1] }
77
- named.except(decision_name(decision)).values
62
+ heads(decision).flat_map { decisions_within(_1) }
78
63
  end
79
64
 
80
65
  # node when it is a decision, then each decision within it, in
@@ -0,0 +1,53 @@
1
+ require_relative 'leaving'
2
+
3
+ module PathCoverage
4
+ # What each statement of a method's flow is as written, the top
5
+ # its row is named by, eg if/else or =. It relies on its
6
+ # includer's decision_at.
7
+ module StatementTops
8
+ TOPS = { call_node: '()', def_node: 'def' }.freeze
9
+
10
+ # What statement is as written: a decision's operator, eg if,
11
+ # when statement is the site of a decision, an elsif
12
+ # being elsif, as written, an if or unless with an else
13
+ # if/else or unless/else; else = for a write, Leaving's word,
14
+ # return or raise, for a statement that leaves the method,
15
+ # () for a call, def for a def inside it, value for anything
16
+ # else.
17
+ def top_of(statement)
18
+ decision = decision_at(statement)
19
+ return 'elsif' if decision && elsif?(statement)
20
+ return with_else(decision.operator, statement) if decision
21
+ return '=' if write?(statement)
22
+
23
+ word = Leaving.word(statement)
24
+ return word if word
25
+
26
+ TOPS.fetch(statement.type, 'value')
27
+ end
28
+
29
+ # Example: if/else for if a then 1 else 2 end.
30
+ # operator, a decision node's, with /else after it when node is an
31
+ # if or an unless with an else, so its row names both arms;
32
+ # operator alone for any other, eg a ?:, whose arms are ? and :.
33
+ def with_else(operator, node)
34
+ return operator unless %w[if unless].include?(operator)
35
+
36
+ clause = operator == 'if' ? node.subsequent : node.else_clause
37
+ clause&.type == :else_node ? "#{operator}/else" : operator
38
+ end
39
+
40
+ # True for an if written as an elsif.
41
+ def elsif?(statement)
42
+ statement.type == :if_node && statement.if_keyword == 'elsif'
43
+ end
44
+
45
+ # True for a write of any kind: of a variable, eg @x = 1
46
+ # or x += 1, or a call Ruby makes of an index or attribute
47
+ # write, eg a[i] = x or a.b = x.
48
+ def write?(statement)
49
+ statement.type.end_with?('_write_node') ||
50
+ (statement.type == :call_node && statement.attribute_write?)
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module PathCoverage
2
- VERSION = '0.7.0'.freeze
2
+ VERSION = '0.7.2'.freeze
3
3
  end
@@ -3,7 +3,6 @@ require_relative 'paths_scopes'
3
3
  require_relative 'paths_tree'
4
4
  require_relative 'paths_way_lists'
5
5
  require_relative 'paths_ways'
6
- require_relative 'loop_forks'
7
6
  require_relative 'method_loops'
8
7
  require_relative 'method_statements'
9
8
  require_relative 'method_ways'
@@ -22,9 +21,11 @@ module PathCoverage
22
21
  files.map do |full_path, parsed|
23
22
  path = config.relative(full_path)
24
23
  source, decisions = parsed.values_at(:source, :decisions)
25
- args = [source, path, paths]
26
- top = MethodStatements.top_level(*args, decisions)
27
- PathsContext.totals(*args, reached, decisions)
24
+ top = MethodStatements.top_level(source, path, paths,
25
+ decisions)
26
+ recorded = [paths, reached]
27
+ PathsContext.totals(source, path, recorded, decisions,
28
+ config.loops?)
28
29
  .merge("#{path}:0:0" => top)
29
30
  end.reduce({}, :merge)
30
31
  end
@@ -116,7 +117,7 @@ module PathCoverage
116
117
  source, decisions = parsed.values_at(:source, :decisions)
117
118
  titles = titles(source, path, decisions)
118
119
  lister = WayLister.new(source, path, decisions, counted)
119
- context = [source, decisions, paths, reached]
120
+ context = [source, decisions, [paths, reached], lister]
120
121
  MethodStatements.of(source, path, decisions).to_h do |key, rows|
121
122
  count = lister.count(key, rows)
122
123
  named = [*titles[key], count, reached&.fetch(key, 0)]
@@ -126,12 +127,13 @@ module PathCoverage
126
127
  end
127
128
 
128
129
  # The flow of the def at key, its rows, named as flow takes
129
- # named; context is [source, decisions, paths, reached], as
130
- # listed_in has them.
130
+ # named; context is [source, decisions, recorded, lister], as
131
+ # listed_in has them, recorded as PathsContext takes it, and
132
+ # lister the WayLister giving the def's scopes.
131
133
  def self.method_flow(key, rows, named, context)
132
- source, decisions, paths, reached = context
133
- shown = PathsContext.rows(source, decisions, rows, paths,
134
- reached)
134
+ source, decisions, recorded, lister = context
135
+ shown = PathsContext.rows(source, decisions, rows, recorded,
136
+ lister.scopes(key))
135
137
  flow(key, named, shown)
136
138
  end
137
139
 
@@ -156,9 +158,7 @@ module PathCoverage
156
158
  @ways = ways
157
159
  @limit = limit
158
160
  @loops = MethodLoops.of(source, path, decisions)
159
- @forks = LoopForks.of(source, path)
160
- @rescues = RescueForks.of(source, path)
161
- @forking = loops
161
+ @scopes = PathsContext.scopes_of(source, path, loops)
162
162
  end
163
163
 
164
164
  # How many ways go through the flow of the def at key, its
@@ -185,26 +185,27 @@ module PathCoverage
185
185
  walked.merge(PathsWayLists.checked(key, @ways, checked))
186
186
  end
187
187
 
188
- private
189
-
190
188
  # [forks, rescues, forking] of the def at key, as
191
- # MethodWays.split_flow takes them. forks is each of its
192
- # loops, as LoopForks gives them. rescues is its rescue
193
- # forks. forking says whether its loops fork.
189
+ # MethodWays.split_flow and PathsContext take them, as
190
+ # PathsContext.scopes_of gives them.
194
191
  def scopes(key)
195
- [@forks.fetch(key), @rescues.fetch(key), @forking]
192
+ @scopes.fetch(key)
196
193
  end
197
194
 
195
+ private
196
+
198
197
  # The names of the loops of the def at key: those holding a
199
198
  # row, and those that fork.
200
199
  def loops(key)
201
- (@loops[key].values.flatten + @forks.fetch(key).keys).uniq
200
+ forks = scopes(key).first
201
+ (@loops[key].values.flatten + forks.keys).uniq
202
202
  end
203
203
 
204
204
  # The loops of the def at key that fork, as
205
205
  # LoopForks gives them; none unless loops are forks.
206
206
  def forked(key)
207
- @forking ? @forks.fetch(key) : {}
207
+ forks, _, forking = scopes(key)
208
+ forking ? forks : {}
208
209
  end
209
210
  end
210
211
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: path_coverage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Jagger
@@ -49,6 +49,7 @@ files:
49
49
  - lib/path_coverage/decision.rb
50
50
  - lib/path_coverage/decision_locations.rb
51
51
  - lib/path_coverage/decision_paths.rb
52
+ - lib/path_coverage/decision_sites.rb
52
53
  - lib/path_coverage/decision_tree.rb
53
54
  - lib/path_coverage/fold_branches.rb
54
55
  - lib/path_coverage/fold_cells.rb
@@ -111,6 +112,7 @@ files:
111
112
  - lib/path_coverage/source_report.rb
112
113
  - lib/path_coverage/stable_leaves.rb
113
114
  - lib/path_coverage/statement_arms.rb
115
+ - lib/path_coverage/statement_tops.rb
114
116
  - lib/path_coverage/summary.rb
115
117
  - lib/path_coverage/totals.rb
116
118
  - lib/path_coverage/version.rb