path_coverage 0.4.0 → 0.5.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 (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +286 -199
  3. data/exe/path_coverage_report +4 -0
  4. data/lib/path_coverage/call_trace.rb +88 -0
  5. data/lib/path_coverage/calls.rb +49 -43
  6. data/lib/path_coverage/card_context.rb +104 -0
  7. data/lib/path_coverage/card_forks.rb +44 -0
  8. data/lib/path_coverage/card_gaps.rb +125 -0
  9. data/lib/path_coverage/card_scopes.rb +37 -0
  10. data/lib/path_coverage/card_tree.rb +79 -66
  11. data/lib/path_coverage/card_way_lists.rb +72 -0
  12. data/lib/path_coverage/card_ways.rb +123 -67
  13. data/lib/path_coverage/{html_syntax.rb → code_tokens.rb} +35 -33
  14. data/lib/path_coverage/condition.rb +14 -14
  15. data/lib/path_coverage/configuration.rb +7 -4
  16. data/lib/path_coverage/configuration_limits.rb +52 -0
  17. data/lib/path_coverage/configuration_paths.rb +7 -7
  18. data/lib/path_coverage/console_summary.rb +24 -22
  19. data/lib/path_coverage/{site.rb → decision.rb} +2 -2
  20. data/lib/path_coverage/decision_locations.rb +76 -0
  21. data/lib/path_coverage/{site_paths.rb → decision_paths.rb} +13 -11
  22. data/lib/path_coverage/{site_tree.rb → decision_tree.rb} +25 -16
  23. data/lib/path_coverage/fold_branches.rb +18 -0
  24. data/lib/path_coverage/fold_cells.rb +42 -0
  25. data/lib/path_coverage/{html_tree.rb → fold_rows.rb} +42 -71
  26. data/lib/path_coverage/gaps.rb +33 -15
  27. data/lib/path_coverage/json_reader.rb +54 -19
  28. data/lib/path_coverage/json_reports.rb +102 -0
  29. data/lib/path_coverage/json_writer.rb +27 -12
  30. data/lib/path_coverage/kernel.rb +56 -58
  31. data/lib/path_coverage/kinds/base.rb +16 -16
  32. data/lib/path_coverage/kinds/block.rb +16 -15
  33. data/lib/path_coverage/kinds/case.rb +14 -12
  34. data/lib/path_coverage/kinds/chain.rb +40 -11
  35. data/lib/path_coverage/kinds/choice.rb +4 -3
  36. data/lib/path_coverage/kinds/contains.rb +40 -32
  37. data/lib/path_coverage/kinds/safe.rb +38 -26
  38. data/lib/path_coverage/kinds/write.rb +6 -6
  39. data/lib/path_coverage/kinds.rb +2 -2
  40. data/lib/path_coverage/leaving.rb +44 -0
  41. data/lib/path_coverage/loop_forks.rb +57 -0
  42. data/lib/path_coverage/loop_nodes.rb +55 -0
  43. data/lib/path_coverage/manifest.rb +92 -58
  44. data/lib/path_coverage/manifest_blocks.rb +5 -26
  45. data/lib/path_coverage/manifest_case.rb +2 -2
  46. data/lib/path_coverage/manifest_chains.rb +8 -8
  47. data/lib/path_coverage/manifest_choices.rb +23 -20
  48. data/lib/path_coverage/manifest_disabled.rb +97 -0
  49. data/lib/path_coverage/manifest_folding.rb +43 -40
  50. data/lib/path_coverage/manifest_ignoring.rb +6 -6
  51. data/lib/path_coverage/manifest_writes.rb +11 -10
  52. data/lib/path_coverage/measured_by.rb +20 -0
  53. data/lib/path_coverage/merge.rb +7 -7
  54. data/lib/path_coverage/method_loops.rb +128 -0
  55. data/lib/path_coverage/method_statements.rb +130 -127
  56. data/lib/path_coverage/method_ways.rb +142 -0
  57. data/lib/path_coverage/paths_report.rb +16 -16
  58. data/lib/path_coverage/recorder.rb +57 -36
  59. data/lib/path_coverage/recorder_blocks.rb +17 -17
  60. data/lib/path_coverage/recorder_cases.rb +12 -11
  61. data/lib/path_coverage/recorder_chains.rb +12 -12
  62. data/lib/path_coverage/recorder_writes.rb +9 -9
  63. data/lib/path_coverage/render.rb +58 -51
  64. data/lib/path_coverage/result.rb +32 -31
  65. data/lib/path_coverage/rewriter.rb +39 -27
  66. data/lib/path_coverage/rewriter_nested.rb +13 -13
  67. data/lib/path_coverage/runs_report.rb +84 -0
  68. data/lib/path_coverage/source_lines.rb +16 -16
  69. data/lib/path_coverage/source_report.rb +100 -0
  70. data/lib/path_coverage/stable_leaves.rb +162 -0
  71. data/lib/path_coverage/statement_arms.rb +31 -30
  72. data/lib/path_coverage/summary.rb +4 -62
  73. data/lib/path_coverage/totals.rb +10 -8
  74. data/lib/path_coverage/version.rb +1 -1
  75. data/lib/path_coverage/walk.rb +106 -0
  76. data/lib/path_coverage/way_algebras.rb +127 -0
  77. data/lib/path_coverage/ways_report.rb +91 -0
  78. data/lib/path_coverage/ways_totals.rb +46 -0
  79. data/lib/path_coverage/within_methods.rb +135 -80
  80. metadata +33 -28
  81. data/lib/path_coverage/card.rb +0 -14
  82. data/lib/path_coverage/html/file.html +0 -33
  83. data/lib/path_coverage/html/index.html +0 -29
  84. data/lib/path_coverage/html/settings.js +0 -50
  85. data/lib/path_coverage/html/side.js +0 -599
  86. data/lib/path_coverage/html/sort.js +0 -34
  87. data/lib/path_coverage/html/style.css +0 -484
  88. data/lib/path_coverage/html/tabs.js +0 -15
  89. data/lib/path_coverage/html/theme.js +0 -27
  90. data/lib/path_coverage/html_branch.rb +0 -30
  91. data/lib/path_coverage/html_cards.rb +0 -88
  92. data/lib/path_coverage/html_cells.rb +0 -71
  93. data/lib/path_coverage/html_file.rb +0 -123
  94. data/lib/path_coverage/html_index.rb +0 -128
  95. data/lib/path_coverage/html_index_head.rb +0 -29
  96. data/lib/path_coverage/html_labels.rb +0 -16
  97. data/lib/path_coverage/html_methods.rb +0 -66
  98. data/lib/path_coverage/html_nav.rb +0 -67
  99. data/lib/path_coverage/html_report.rb +0 -131
  100. data/lib/path_coverage/html_statements.rb +0 -186
  101. data/lib/path_coverage/html_tabs.rb +0 -26
  102. data/lib/path_coverage/html_template.rb +0 -26
@@ -0,0 +1,128 @@
1
+ require 'prism'
2
+ require_relative 'card_tree'
3
+ require_relative 'decision'
4
+ require_relative 'loop_forks'
5
+ require_relative 'loop_nodes'
6
+ require_relative 'manifest'
7
+ require_relative 'method_statements'
8
+
9
+ module PathCoverage
10
+ # The loops of each method: the blocks, lambdas, whiles, untils
11
+ # and fors in its body, each run 0 or more times, and which of
12
+ # them hold each of its rows, as a call's Walk takes them; a
13
+ # while's or until's body holds its rows, its test only its
14
+ # first run's, as Walk's repeats have them.
15
+ module MethodLoops
16
+ # { def decision => { name => the loops holding it, outermost
17
+ # first } } for each def in source, at path: each of its
18
+ # rows, as MethodStatements gives them, and each loop holding
19
+ # one or forking, as LoopForks finds them, by name, as Decision
20
+ # names where it starts.
21
+ def self.of(source, path, decisions = nil)
22
+ decisions ||= Manifest.decisions(source, path)
23
+ rows = MethodStatements.of(source, path, decisions)
24
+ forks = LoopForks.of(source, path, decisions)
25
+ starts = CardTree.line_starts(source)
26
+ LoopNodes.defs(Prism.parse(source).value).to_h do |node|
27
+ decision = Decision.of(path, node)
28
+ loops = [named(node, path), forks[decision].keys]
29
+ [decision, holding(rows[decision], loops, starts)]
30
+ end
31
+ end
32
+
33
+ # { loop's name => where its first statement starts, a byte
34
+ # offset } of each loop in source, at path, holding a row or
35
+ # forking, as loops, the result of of, has them: where a pass
36
+ # call goes.
37
+ def self.passes(source, path, loops)
38
+ held = loops.values.flat_map { _1.to_a.flatten }.to_set
39
+ defs = LoopNodes.defs(Prism.parse(source).value)
40
+ nodes = defs.flat_map { LoopNodes.loops_in(_1.body) }
41
+ nodes.filter_map { pass_at(_1, path, held) }.to_h
42
+ end
43
+
44
+ # [name, offset] of node, a loop, where its pass call goes,
45
+ # when it is among held and its body has a statement; else nil.
46
+ def self.pass_at(node, path, held)
47
+ name = Decision.at(path, node.location)
48
+ return unless held.include?(name) && !LoopNodes.modifier?(node)
49
+
50
+ first = LoopNodes.first_statement(LoopNodes.body_of(node))
51
+ [name, first.location.start_offset] if first
52
+ end
53
+
54
+ # [[name, location], ...] of the loops in node's body, a def's,
55
+ # in the order they start, each location the source holding
56
+ # its rows: a block's or lambda's whole, a keyword loop's body;
57
+ # none of a keyword loop with an empty body.
58
+ def self.named(node, path)
59
+ LoopNodes.loops_in(node.body).filter_map do |loop|
60
+ keyword = LoopNodes::KEYWORDS.include?(loop.type)
61
+ held = keyword ? loop.statements : loop
62
+ [Decision.at(path, loop.location), held.location] if held
63
+ end
64
+ end
65
+
66
+ # { def decision => { row's name => the name of the while or
67
+ # until whose test holds it } } for each def in source, at
68
+ # path: rows whose later runs repeat the loop's first, so take
69
+ # no step, as Walk's repeats have them.
70
+ def self.repeats(source, path, decisions = nil)
71
+ rows = MethodStatements.of(source, path, decisions)
72
+ starts = CardTree.line_starts(source)
73
+ LoopNodes.defs(Prism.parse(source).value).to_h do |node|
74
+ decision = Decision.of(path, node)
75
+ tests = tests_in(node.body, path)
76
+ [decision, tested(rows[decision], tests, starts)]
77
+ end
78
+ end
79
+
80
+ # { row's name => the loop whose test holds it } of each of
81
+ # rows in one of tests, as tests_in gives them.
82
+ def self.tested(rows, tests, starts)
83
+ rows.filter_map do |row|
84
+ loop = around(tests, starts[row.line - 1] + row.column).first
85
+ [row.name, loop] if loop
86
+ end.to_h
87
+ end
88
+
89
+ # [[name, location], ...] of the test of each while and until
90
+ # in node's body, by its loop's name.
91
+ def self.tests_in(node, path)
92
+ LoopNodes.loops_in(node).filter_map do |loop|
93
+ next unless %i[while_node until_node].include?(loop.type)
94
+
95
+ [Decision.at(path, loop.location), loop.predicate.location]
96
+ end
97
+ end
98
+
99
+ # { name => the loops holding it, outermost first } of each of
100
+ # rows, of each loop holding one, and of each of forked, the
101
+ # names of the loops that fork; loops is [[name, location],
102
+ # ...] in the order they start.
103
+ def self.holding(rows, (loops, forked), starts)
104
+ held = rows.to_h do |row|
105
+ [row.name, around(loops, starts[row.line - 1] + row.column)]
106
+ end
107
+ held.merge(outer((held.values.flatten + forked).uniq, loops))
108
+ end
109
+
110
+ # { name => the loops holding it, outermost first } of each
111
+ # loop named in names; loops as holding has them.
112
+ def self.outer(names, loops)
113
+ locations = loops.to_h
114
+ names.to_h do |name|
115
+ [name, around(loops, locations[name].start_offset) - [name]]
116
+ end
117
+ end
118
+
119
+ # The names of the loops whose source holds the byte at
120
+ # offset, outermost first.
121
+ def self.around(loops, offset)
122
+ loops.filter_map do |name, location|
123
+ name if (location.start_offset...location.end_offset)
124
+ .cover?(offset)
125
+ end
126
+ end
127
+ end
128
+ end
@@ -2,105 +2,112 @@ require 'prism'
2
2
  require_relative 'manifest'
3
3
  require_relative 'manifest_chains'
4
4
  require_relative 'manifest_choices'
5
- require_relative 'site'
6
- require_relative 'site_paths'
7
- require_relative 'site_tree'
5
+ require_relative 'decision'
6
+ require_relative 'decision_paths'
7
+ require_relative 'decision_tree'
8
+ require_relative 'leaving'
8
9
  require_relative 'statement_arms'
9
10
  require_relative 'totals'
10
11
 
11
12
  module PathCoverage
12
13
  # One row of a method's card, a top-level statement or a
13
- # site at its top: where it starts; its top, what it is as
14
+ # decision at its top: where it starts; its top, what it is as
14
15
  # written, eg = for a write; how many paths it has; the name
15
- # of its site, nil when it is no site; and its own name, by
16
+ # of its decision, nil when it is no decision; and its own name, by
16
17
  # where it is, eg "k.rb:2:2".
17
- Statement = Data.define(:line, :column, :top, :paths, :site, :name)
18
+ Statement = Data.define(:line, :column, :top, :paths, :decision,
19
+ :name)
18
20
 
19
21
  # Finds, without running it, the top-level statements of each
20
22
  # method in source, one row each in its method's card.
21
23
  module MethodStatements
22
- # Each function below takes sites, { site => Condition }, the
23
- # sites the run has in source, as Manifest.parse gives them
24
- # with the run's ignore and treat settings; nil for those of
25
- # no settings.
24
+ # Each function below takes decisions, { decision =>
25
+ # Condition }, the decisions the run has in source, as
26
+ # Manifest.parse gives them with the run's ignore and treat
27
+ # settings; nil for those of no settings.
26
28
 
27
- # { def site => [Statement, ...] } for each def in source.
29
+ # { def decision => [Statement, ...] } for each def in source.
28
30
  # Example: def f; x = 1; x; end gives = and value rows.
29
- def self.of(source, path, sites = nil)
30
- collect(source, path, sites).methods
31
+ def self.of(source, path, decisions = nil)
32
+ collect(source, path, decisions).methods
31
33
  end
32
34
 
33
- # { def site => its name } for each def in source, eg
35
+ # { def decision => its name } for each def in source, eg
34
36
  # { "k.rb:4:2" => :ship }, each its card's title.
35
- def self.names(source, path, sites = nil)
36
- collect(source, path, sites).names
37
+ def self.names(source, path, decisions = nil)
38
+ collect(source, path, decisions).names
37
39
  end
38
40
 
39
- # { def site => its last line } for each def in source, eg
41
+ # { def decision => its last line } for each def in source, eg
40
42
  # { "k.rb:4:2" => 6 }, where its card ends.
41
- def self.lasts(source, path, sites = nil)
42
- collect(source, path, sites).lasts
43
+ def self.lasts(source, path, decisions = nil)
44
+ collect(source, path, decisions).lasts
43
45
  end
44
46
 
45
47
  # Example: { "k.rb:2:2" => 18 } for a write at byte 18.
46
48
  # Where a call can count the runs of each row that is no
47
- # site, in every def in source, by the row's name, where it
49
+ # decision, in every def in source, by the row's name, where it
48
50
  # starts: its byte offset, or, in an endless def, whose body
49
51
  # is one expression, its byte range, to be wrapped.
50
- def self.reaches(source, path, sites = nil)
51
- collect(source, path, sites).reaches
52
+ def self.reaches(source, path, decisions = nil)
53
+ collect(source, path, decisions).reaches
52
54
  end
53
55
 
54
56
  # A Collector that has visited each def in source, with
55
- # sites, or, for nil, those of no settings.
56
- def self.collect(source, path, sites)
57
- sites = Manifest.sites(source, path) if sites.nil?
58
- collector = Collector.new(path, sites)
57
+ # decisions, or, for nil, those of no settings.
58
+ def self.collect(source, path, decisions)
59
+ decisions = Manifest.decisions(source, path) if decisions.nil?
60
+ collector = Collector.new(path, decisions)
59
61
  Prism.parse(source).value.accept(collector)
60
62
  collector
61
63
  end
62
64
 
63
65
  # Example: RATE = x ? 2 : 1 at the top level, its then
64
66
  # taken, gives [1, 2].
65
- # [taken, possible] of the paths of the sites in source on
67
+ # [taken, possible] of the paths of the decisions in source on
66
68
  # no method's card, outside every def, as top_rows gives
67
69
  # them; paths as Result#paths gives them.
68
- def self.top_level(source, path, paths, sites = nil)
69
- names = top_rows(source, path, sites).map(&:site)
70
- Totals.decisions(paths.slice(*names))
70
+ def self.top_level(source, path, paths, decisions = nil)
71
+ names = top_rows(source, path, decisions).map(&:decision)
72
+ Totals.alone(paths.slice(*names))
71
73
  end
72
74
 
73
75
  # Example: RATE = x ? 2 : 1 gives a ?: row at 1:9.
74
- # A Statement row for each site in source on no method's
76
+ # A Statement row for each decision in source on no method's
75
77
  # card, outside every def, for the card of its own lines, in
76
78
  # the order written: where decision mode names it, its
77
79
  # operator, an elsif's elsif, and its paths.
78
- def self.top_rows(source, path, sites = nil)
79
- collector = collect(source, path, sites)
80
- carded = collector.methods.values.flatten.map(&:site)
81
- loose = collector.sites.except(*carded)
82
- rows = loose.map { |name, site| top_row(source, name, site) }
80
+ def self.top_rows(source, path, decisions = nil)
81
+ collector = collect(source, path, decisions)
82
+ carded = collector.methods.values.flatten.map(&:decision)
83
+ loose = collector.decisions.except(*carded)
84
+ rows = loose.map do |name, decision|
85
+ top_row(source, name, decision)
86
+ end
83
87
  rows.sort_by { [_1.line, _1.column] }
84
88
  end
85
89
 
86
- # The Statement row of the site named name, its Condition
87
- # site, at the top level of source.
88
- def self.top_row(source, name, site)
90
+ # The Statement row of the decision named name, its Condition
91
+ # decision, at the top level of source.
92
+ def self.top_row(source, name, decision)
89
93
  line, column = name.split(':').last(2).map { Integer(_1) }
90
- top = SiteTree.elsif?(source, site) ? 'elsif' : site.operator
91
- paths = SitePaths.possible(site).size
92
- Statement.new(line:, column:, top:, paths:, site: name, name:)
94
+ top = if DecisionTree.elsif?(source,
95
+ decision)
96
+ 'elsif'
97
+ else
98
+ decision.operator
99
+ end
100
+ paths = DecisionPaths.possible(decision).size
101
+ Statement.new(line:, column:, top:, paths:, decision: name,
102
+ name:)
93
103
  end
94
104
 
95
- # Example: { "k.rb:1:0" => [2, 4] }, 2 of ship's 4 taken.
96
- # Each def's card total in source, [taken, size], its rows'
97
- # taken as taken gives them from paths and reached; a row
98
- # not known counts as not taken, never more than it ran.
99
- def self.totals(source, path, paths, reached, sites = nil)
100
- of(source, path, sites).transform_values do |rows|
101
- seen = taken(rows, paths, reached).compact.sum
102
- [seen, size(rows.map(&:paths))]
103
- end
105
+ # Example: 19:04, a statement on line 19 at column 4.
106
+ # statement's line:column, the column two digits so they
107
+ # line up.
108
+ def self.at(statement)
109
+ format('%<line>d:%<column>02d',
110
+ line: statement.line, column: statement.column)
104
111
  end
105
112
 
106
113
  # Example: rows of 1, 2 and 2 paths, [1, 2, 2], have size 5.
@@ -111,22 +118,22 @@ module PathCoverage
111
118
  end
112
119
 
113
120
  # Example: an if row with only its then taken gives 1.
114
- # How many paths of each row were taken: for a site's row,
121
+ # How many paths of each row were taken: for a decision's row,
115
122
  # its paths with a count, paths being Result#paths; for any
116
123
  # other row, its 1 path when reached has a count for it, 0
117
124
  # when not, nil, not known, without reached.
118
125
  def self.taken(rows, paths, reached = nil)
119
126
  rows.map do |row|
120
- next taken_site(row, paths) if row.site
127
+ next taken_decision(row, paths) if row.decision
121
128
  next nil if reached.nil?
122
129
 
123
130
  reached.key?(row.name) ? 1 : 0
124
131
  end
125
132
  end
126
133
 
127
- # How many of a site row's paths have a count in paths.
128
- def self.taken_site(row, paths)
129
- counts = paths.fetch(row.site).map { |each| each[:count] }
134
+ # How many of a decision row's paths have a count in paths.
135
+ def self.taken_decision(row, paths)
136
+ counts = paths.fetch(row.decision).map { |each| each[:count] }
130
137
  counts.count(&:positive?)
131
138
  end
132
139
 
@@ -136,11 +143,11 @@ module PathCoverage
136
143
  include ManifestChoices
137
144
  include StatementArms
138
145
 
139
- # Starts with no methods found; sites are decision mode's,
140
- # { site => Condition }.
141
- def initialize(path, sites)
146
+ # Starts with no methods found; decisions are decision mode's,
147
+ # { decision => Condition }.
148
+ def initialize(path, decisions)
142
149
  @path = path
143
- @sites = sites
150
+ @decisions = decisions
144
151
  @methods = {}
145
152
  @names = {}
146
153
  @lasts = {}
@@ -148,137 +155,139 @@ module PathCoverage
148
155
  super()
149
156
  end
150
157
 
151
- # The methods found so far, { def site => rows }; their
152
- # names and last lines, { def site => name } and { def site
153
- # => line }; where each row that is no site is reached, as
154
- # MethodStatements.reaches has it; and the sites it was
155
- # given, { site => Condition }.
156
- attr_reader :methods, :names, :lasts, :reaches, :sites
158
+ # The methods found so far, { def decision => rows }; their
159
+ # names and last lines, { def decision => name } and
160
+ # { def decision => line }; where each row that is no
161
+ # decision is reached, as MethodStatements.reaches has it;
162
+ # and the decisions it was given, { decision => Condition }.
163
+ attr_reader :methods, :names, :lasts, :reaches, :decisions
157
164
 
158
165
  # Notes node's name, its last line, its body statements as
159
- # its rows, those in its sites' arms too, but only those that
160
- # shape its paths, as shapes? has it, none for an empty body,
161
- # and where each row that is no site is reached.
166
+ # its rows, those in its decisions' arms too, but only those
167
+ # that shape its paths, as shapes? has it, none for an empty
168
+ # body, and where each row that is no decision is reached.
162
169
  def visit_def_node(node)
163
170
  written = rows_in(statements_of(node.body))
164
171
  tops = written.select { shapes?(_1) }
165
- site = Site.of(@path, node)
166
- @methods[site] = tops.map { |top| row_of(top) }
167
- note_def(site, node)
172
+ decision = Decision.of(@path, node)
173
+ @methods[decision] = tops.map { |top| row_of(top) }
174
+ note_def(decision, node)
168
175
  note_reaches(tops, endless: !node.equal_loc.nil?)
169
176
  super
170
177
  end
171
178
 
172
- # Notes the name and last line of node, the def at site, and
173
- # where it is entered, reached under site's own name, so its
179
+ # Notes the name and last line of node, the def at decision, and
180
+ # where it is entered, reached under decision's own name, so its
174
181
  # card can say how many times it was called.
175
- def note_def(site, node)
176
- @names[site] = node.name
177
- @lasts[site] = node.location.end_line
178
- @reaches[site] = entry_at(node)
182
+ def note_def(decision, node)
183
+ @names[decision] = node.name
184
+ @lasts[decision] = node.location.end_line
185
+ @reaches[decision] = entry_at(node)
179
186
  end
180
187
 
181
- # Notes where each of tops that is no site, a return or a
188
+ # Notes where each of tops that is no decision, a return or a
182
189
  # raise, is reached: its byte offset, or, endless, its byte
183
190
  # range.
184
191
  def note_reaches(tops, endless:)
185
192
  tops.each do |top|
186
- next if site?(top)
193
+ next if decision?(top)
187
194
 
188
195
  loc = top.location
189
196
  start = loc.start_offset
190
197
  at = endless ? start...loc.end_offset : start
191
- @reaches[Site.at(@path, loc)] = at
198
+ @reaches[Decision.at(@path, loc)] = at
192
199
  end
193
200
  end
194
201
 
195
202
  # Example: if a then x = 1 end gives the if, then the write.
196
203
  # The nodes statements' rows are for, flat, in the order
197
204
  # they are written: each statement's tops, each with the
198
- # sites of their own inside it, in the order they are named,
205
+ # decisions of their own inside it, in the order they are named,
199
206
  # eg a || before the ?: whose predicate it is, then the rows
200
207
  # of its arms' statements, when it has any.
201
208
  def rows_in(statements)
202
209
  statements.flat_map do |statement|
203
210
  tops = top_nodes(statement).flat_map do |top|
204
- named = [top, *inner_sites(top)]
205
- ordered = named.sort_by { site_loc(_1).start_offset }
211
+ named = [top, *inner_decisions(top)]
212
+ ordered = named.sort_by { decision_loc(_1).start_offset }
206
213
  [*ordered, *rows_in(arms_of(top))]
207
214
  end
208
215
  tops + body_rows(statement)
209
216
  end
210
217
  end
211
218
 
212
- # The Statement row of node. A site is where decision mode
219
+ # The Statement row of node. A decision is where decision mode
213
220
  # names it, eg a modifier if at its keyword, with as many
214
221
  # paths as decision mode gives it. Anything else is where
215
222
  # it starts, with 1 path.
216
223
  def row_of(node)
217
- site = site_at(node)
218
- loc = site ? site_loc(node) : node.location
219
- name = Site.at(@path, loc)
224
+ decision = decision_at(node)
225
+ loc = decision ? decision_loc(node) : node.location
226
+ name = Decision.at(@path, loc)
220
227
  Statement.new(
221
228
  line: loc.start_line, column: loc.start_column,
222
229
  top: top_of(node),
223
- paths: site ? SitePaths.possible(site).size : 1,
224
- site: site ? name : nil, name:
230
+ paths: decision ? DecisionPaths.possible(decision).size : 1,
231
+ decision: decision ? name : nil, name:
225
232
  )
226
233
  end
227
234
 
228
235
  # Example: x = (a ? 1 : 2) + (b ? 3 : 4) gives both ?:s.
229
- # The nodes statement's rows are for: the outermost sites
236
+ # The nodes statement's rows are for: the outermost decisions
230
237
  # in it, in the order they run, as what holds them is
231
238
  # looked through; statement itself when it holds none.
232
239
  def top_nodes(statement)
233
- tops = sites_in(statement)
240
+ tops = decisions_in(statement)
234
241
  tops.empty? ? [statement] : tops
235
242
  end
236
243
 
237
- # node when it is a site, else the outermost sites in its
238
- # children, in order; none in a body or a def, as UNSEEN
244
+ # node when it is a decision, else the outermost decisions in
245
+ # its children, in order; none in a body or a def, as UNSEEN
239
246
  # has them.
240
- def sites_in(node)
241
- return [node] if site?(node)
247
+ def decisions_in(node)
248
+ return [node] if decision?(node)
242
249
  return [] if UNSEEN.include?(node.type)
243
250
 
244
- node.compact_child_nodes.flat_map { |child| sites_in(child) }
251
+ node.compact_child_nodes.flat_map do |child|
252
+ decisions_in(child)
253
+ end
245
254
  end
246
255
 
247
- # True when decision mode has a site named where node's
248
- # site would start.
249
- def site?(node)
250
- !site_at(node).nil?
256
+ # True when decision mode has a decision named where node's
257
+ # decision would start.
258
+ def decision?(node)
259
+ !decision_at(node).nil?
251
260
  end
252
261
 
253
- # Decision mode's Condition for the site named where
254
- # node's site would start; nil when it has none there.
255
- def site_at(node)
256
- @sites[site_name(node)]
262
+ # Decision mode's Condition for the decision named where
263
+ # node's decision would start; nil when it has none there.
264
+ def decision_at(node)
265
+ @decisions[decision_name(node)]
257
266
  end
258
267
 
259
- # The name node's site would have, by where it would start.
260
- def site_name(node)
261
- Site.at(@path, site_loc(node))
268
+ # The name node's decision would have, by where it would start.
269
+ def decision_name(node)
270
+ Decision.at(@path, decision_loc(node))
262
271
  end
263
272
 
264
- TOPS = {
265
- call_node: '()', return_node: 'return', def_node: 'def'
266
- }.freeze
273
+ TOPS = { call_node: '()', def_node: 'def' }.freeze
267
274
 
268
- # What statement is as written: a site's operator, eg if,
269
- # when decision mode has a site where it starts, an elsif
275
+ # What statement is as written: a decision's operator, eg if,
276
+ # when decision mode has a decision where it starts, an elsif
270
277
  # being elsif, as written, an if or unless with an else
271
- # if/else or unless/else; else = for a write, () for a
272
- # call, raise for a raise of the method's own, as it leaves
273
- # the method, return for a return, def for a def inside it,
274
- # value for anything else.
278
+ # if/else or unless/else; else = for a write, Leaving's word,
279
+ # return or raise, for a statement that leaves the method,
280
+ # () for a call, def for a def inside it, value for anything
281
+ # else.
275
282
  def top_of(statement)
276
- site = site_at(statement)
277
- return 'elsif' if site && elsif?(statement)
278
- return with_else(site.operator, statement) if site
279
- return 'raise' if raise?(statement)
283
+ decision = decision_at(statement)
284
+ return 'elsif' if decision && elsif?(statement)
285
+ return with_else(decision.operator, statement) if decision
280
286
  return '=' if write?(statement)
281
287
 
288
+ word = Leaving.word(statement)
289
+ return word if word
290
+
282
291
  TOPS.fetch(statement.type, 'value')
283
292
  end
284
293
 
@@ -294,12 +303,6 @@ module PathCoverage
294
303
  statement.type.end_with?('_write_node') ||
295
304
  (statement.type == :call_node && statement.attribute_write?)
296
305
  end
297
-
298
- # True when statement is a call of raise with no receiver.
299
- def raise?(statement)
300
- statement.type == :call_node && statement.receiver.nil? &&
301
- statement.name == :raise
302
- end
303
306
  end
304
307
  end
305
308
  end