path_coverage 0.3.0 → 0.4.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.
@@ -259,10 +259,14 @@ body[data-open] button.lnum:focus-visible { outline: none; }
259
259
  }
260
260
  .operator { font-weight: 600; }
261
261
  .row .arm { white-space: pre; font-weight: 600; }
262
- /* An if's then names its arm, quoting no code, so is italic. */
263
- .row .arm[data-named] { font-style: italic; }
264
262
  .branch { white-space: pre; color: var(--muted); margin-right: -16px; }
265
- .row .text { white-space: pre; }
263
+ /* A leaf's text is never wider than 48ch, nor than its row has
264
+ room for: the rest of a long one scrolls within it, so its
265
+ cells stay in their columns at the row's right edge. */
266
+ .row .text {
267
+ white-space: pre; min-width: 0; max-width: 48ch;
268
+ overflow-x: auto; scrollbar-width: thin;
269
+ }
266
270
  /* A branch's cell, of the kind its data-bx names, drawn a whole
267
271
  row tall so branches join from row to row: v a vertical line,
268
272
  t a vertical with a stub right, l the top half of a vertical
@@ -286,9 +290,11 @@ body[data-open] button.lnum:focus-visible { outline: none; }
286
290
  background: var(--surface); color: var(--fg); font: 600 12px var(--font-code);
287
291
  }
288
292
  /* A cell's mark, drawn in place of a letter: a tick for a path
289
- that took an arm or called its operand, a disc for a &.
290
- receiver not nil, an empty set for one nil. */
293
+ that took a ?:'s arm, a return arrow for one that left the
294
+ method at a return or a raise, a disc for a &. receiver not
295
+ nil, an empty set for one nil. */
291
296
  .row .cell[data-mark="taken"]::before { content: "\2713"; }
297
+ .row .cell[data-mark="leaves"]::before { content: "\21A9"; }
292
298
  .row .cell[data-mark="present"]::before { content: "\25CF"; }
293
299
  .row .cell[data-mark="absent"]::before { content: "\2205"; }
294
300
  /* Hovering a cell with hover text, eg a path's count or a &.
@@ -423,7 +429,7 @@ body.dragging { cursor: col-resize; user-select: none; }
423
429
  .statements .prow.calls .plabel { width: auto; }
424
430
  .statements .plabel + .pcell { flex: 1; min-width: 56px; text-align: left; }
425
431
  .statements .prow.site, .statements .prow.site .pcell { cursor: pointer; }
426
- .statements .prow.site:hover .pcell, .statements .prow.site:hover .plabel { color: var(--link); }
432
+ .statements .prow.site:hover .pcell:not(.not-taken):not(.was-taken), .statements .prow.site:hover .plabel { color: var(--link); }
427
433
  .statements .prow.columns .plabel, .statements .prow.columns .pcell { color: var(--muted); }
428
434
  /* A card's paths not taken are orange and those taken blue, as a
429
435
  status always is; its column titles are too, as their key. None
@@ -432,10 +438,18 @@ body.dragging { cursor: col-resize; user-select: none; }
432
438
  .statements .pcell.was-taken,
433
439
  .statements .pcell.not-taken.none { color: var(--ok); }
434
440
  .prow.calls .plabel { color: var(--fg); }
441
+ /* How many times a card's method was called, after its name; a gap,
442
+ never called, coloured as one. */
443
+ .call-count { margin-left: 6px; color: var(--muted); font-weight: 400; }
444
+ .call-count.never { color: var(--bad); font-weight: 600; }
435
445
  /* Hovering a card's row lights its line in the code; hovering a
436
446
  fold's row marks the characters of its operand. */
437
447
  .src.lit { background: var(--cond-tint); }
438
448
  mark.chars { background: var(--lit); color: inherit; border-radius: 3px; box-shadow: 0 0 0 2px var(--lit); }
449
+ /* The fold row of the code under the pointer, lit as marked code is. */
450
+ .fold .row.hovered, .statements .prow.hovered {
451
+ background: var(--lit); border-radius: 3px;
452
+ }
439
453
  .fold .row[data-at] { cursor: default; }
440
454
  .fold .row[data-at]:hover { background: rgba(255, 255, 255, 0.08); }
441
455
 
@@ -1,111 +1,88 @@
1
1
  require_relative 'card'
2
2
  require_relative 'html_statements'
3
3
  require_relative 'html_tree'
4
- require_relative 'method_statements'
5
4
  require_relative 'site_tree'
5
+ require_relative 'within_methods'
6
6
 
7
7
  module PathCoverage
8
8
  # The cards of one file's page, as Card gives them, in the rail
9
9
  # beside its code: a card for each of its methods, and one for
10
10
  # each span of its lines holding sites at the top level; each
11
- # site's row with its tree folded under it. It relies on
12
- # HtmlReport.located to place each tree's rows in the source.
11
+ # drawn from the card the JSON report lists, as WithinMethods
12
+ # lists them, each site's row with its tree folded under it.
13
+ # It relies on HtmlReport.located to place each tree's rows in
14
+ # the source.
13
15
  module HtmlCards
14
16
  # The cards of each method of the file at path, parsed as
15
17
  # Manifest.parse gives it; site_paths as Result#paths gives
16
18
  # them, reached as Recorder#reached does.
17
19
  def self.methods(path, parsed, (site_paths, reached))
18
20
  source, sites = parsed.values_at(:source, :sites)
19
- names = MethodStatements.names(source, path, sites)
20
- lasts = MethodStatements.lasts(source, path, sites)
21
- tree = ->(at) { fold(source, sites, site_paths, at) }
22
- MethodStatements.of(source, path, sites).map do |site, rows|
23
- taken = MethodStatements.taken(rows, site_paths, reached)
24
- named = [names[site], lasts[site]]
25
- method_card(site, named, rows, taken, &tree)
26
- end
21
+ tree = ->(at, top) { fold(source, sites, site_paths, at, top) }
22
+ recorded = [site_paths, reached]
23
+ cards = WithinMethods.listed_in(path, parsed, *recorded)
24
+ cards.map { |site, card| method_card(site, card, &tree) }
27
25
  end
28
26
 
29
- # The Card of the def at site named name, ending on line last,
30
- # its rows' taken as taken gives them.
31
- def self.method_card(site, (name, last), rows, taken, &)
32
- html = HtmlStatements.card(site, name, rows, taken, last, &)
27
+ # The Card of the def at site, drawn from card, as
28
+ # WithinMethods.card gives it.
29
+ def self.method_card(site, card, &)
30
+ html = HtmlStatements.card(site, card, &)
33
31
  first, column = site.split(':').last(2).map { Integer(_1) }
34
- status = HtmlStatements.status(rows, taken)
35
- Card.new(first:, last:, column:, status:, top: false,
36
- sites: nil, html:)
32
+ status = HtmlStatements.status(card)
33
+ Card.new(first:, last: card['last'], column:, status:,
34
+ top: false, sites: nil, html:)
37
35
  end
38
36
 
39
37
  # A top card for each span of lines holding sites at the top
40
38
  # level of the file at path, outside every def, as each
41
- # span's lines share one button: a row per site in it. lines
42
- # are as SourceLines.of gives them.
43
- def self.tops(path, parsed, lines, site_paths)
39
+ # span's lines share one button: a row per site in it, as
40
+ # WithinMethods.listed_tops lists them from operands and
41
+ # site_paths.
42
+ def self.tops(path, parsed, (operands, site_paths))
44
43
  source, sites = parsed.values_at(:source, :sites)
45
- tree = ->(at) { fold(source, sites, site_paths, at) }
46
- scopes = scopes(source)
47
- spans(path, parsed, lines).map do |span, rows|
48
- top(path, span, rows, site_paths, scopes[span.begin], &tree)
49
- end
44
+ tree = ->(at, top) { fold(source, sites, site_paths, at, top) }
45
+ cards = WithinMethods.listed_tops(path, parsed,
46
+ [operands, site_paths])
47
+ cards.map { |site, card| top(site, card, &tree) }
50
48
  end
51
49
 
52
- # The top card of the span of lines of the file at path,
53
- # holding rows, titled scope.
54
- def self.top(path, span, rows, site_paths, scope, &)
55
- taken = MethodStatements.taken(rows, site_paths)
56
- site = "#{path}:#{span.begin}:0"
57
- html = HtmlStatements.top_card(site, scope, rows, taken,
58
- span.end, &)
59
- Card.new(first: span.begin, last: span.end, column: 0,
60
- status: HtmlStatements.status(rows, taken), top: true,
61
- sites: rows.size, html:)
50
+ # The Card of the top card at site, drawn from card.
51
+ def self.top(site, card, &)
52
+ html = HtmlStatements.top_card(site, card, &)
53
+ Card.new(first: card['first'], last: card['last'], column: 0,
54
+ status: HtmlStatements.status(card), top: true,
55
+ sites: card['rows'].size, html:)
62
56
  end
63
57
 
64
- # A lambda giving the scope of a line of source, as scope
65
- # gives it, its modules and classes found once.
66
- def self.scopes(source)
67
- holders = holders_in(Prism.parse(source).value)
68
- ->(line) { scope(holders, line) }
58
+ # The rows of site's tree, as a file's page draws them, for
59
+ # its row's fold in a card, headed by top, its row's top, eg
60
+ # if/else, so the two always read the same.
61
+ def self.fold(source, sites, site_paths, site, top)
62
+ condition = sites.fetch(site)
63
+ tree = SiteTree.of(source, condition, site_paths.fetch(site))
64
+ located = HtmlReport.located(source, condition, tree)
65
+ else_at = else_at(source, condition)
66
+ HtmlTree.site_rows(located.merge(else_at:, label: top)).join
69
67
  end
70
68
 
71
- # Example: line 2, inside module Shop on lines 1 to 9, gives
72
- # Shop.
73
- # The name of the innermost of holders, modules and classes,
74
- # whose lines hold line, a top card's scope, as a def is a
75
- # method card's; file for a line in none.
76
- def self.scope(holders, line)
77
- holding = holders.select do |node|
78
- location = node.location
79
- (location.start_line..location.end_line).cover?(line)
80
- end
81
- holding.empty? ? 'file' : holding.last.name.to_s
82
- end
69
+ # [line, column, line, column] of condition's else keyword in
70
+ # source, so hovering it can open condition's fold, as
71
+ # hovering its if does; nil for one with no else, or one whose
72
+ # else has no code, or a ?:, whose else is no keyword. The
73
+ # keyword is what comes just before its arm's code, so an
74
+ # elsif, or an else with a comment after it, has none.
75
+ def self.else_at(source, condition)
76
+ return nil if condition.operator == '?:'
83
77
 
84
- # The kinds of node that are a top card's scope.
85
- HOLDERS = [Prism::ModuleNode, Prism::ClassNode].freeze
78
+ arm = condition.operands.grep(Arm).to_h { [_1.kind, _1] }[:else]
79
+ extent = arm&.extent
80
+ return nil unless extent
86
81
 
87
- # Every module and class node in the tree at node, each
88
- # before those nested in it.
89
- def self.holders_in(node)
90
- own = HOLDERS.include?(node.class) ? [node] : []
91
- own + node.compact_child_nodes.flat_map { holders_in(_1) }
92
- end
82
+ start = source.b.byteslice(0, extent.begin) =~ /\belse\s*\z/
83
+ return nil unless start
93
84
 
94
- # { span => its top-level rows } of the file at path, each
95
- # row under the span its line is in.
96
- def self.spans(path, parsed, lines)
97
- source, sites = parsed.values_at(:source, :sites)
98
- rows = MethodStatements.top_rows(source, path, sites)
99
- rows.group_by { lines[_1.line - 1][:span] }
100
- end
101
-
102
- # The rows of site's tree, as a file's page draws them, for
103
- # its row's fold in a card.
104
- def self.fold(source, sites, site_paths, site)
105
- condition = sites.fetch(site)
106
- tree = SiteTree.of(source, condition, site_paths.fetch(site))
107
- located = HtmlReport.located(source, condition, tree)
108
- HtmlTree.site_rows(located).join
85
+ HtmlReport.at(source, start...(start + 4))
109
86
  end
110
87
  end
111
88
  end
@@ -18,10 +18,15 @@ module PathCoverage
18
18
  PRESENCE[1] => ['', 'absent', PRESENCE[1]]
19
19
  }.freeze
20
20
 
21
- # [text, mark] of an arm's cell, or of one only called: taken
22
- # on a path that took it or called it, else blank.
21
+ # [text, mark] of a ternary's arm's cell: taken on a path
22
+ # that took it, else blank.
23
23
  TAKEN = { true => ['', 'taken'], false => [''] }.freeze
24
24
 
25
+ # [text, mark] of the cell of an arm that returns or raises:
26
+ # leaves on a path that took it, so left the method there,
27
+ # else blank.
28
+ LEAVES = { true => ['', 'leaves'], false => [''] }.freeze
29
+
25
30
  # The cells of values, each named as names gives it.
26
31
  def self.of(values, names = OUTCOMES)
27
32
  values.map { |value| cell(*names[value]) }.join
@@ -1,4 +1,3 @@
1
- require 'cgi/escape'
2
1
  require_relative 'condition'
3
2
  require_relative 'html_syntax'
4
3
  require_relative 'kinds'
@@ -7,17 +6,11 @@ module PathCoverage
7
6
  # The labels of a site's tree on a file's page, coloured as the
8
7
  # code they quote.
9
8
  module HtmlLabels
10
- # The label of an arm of a condition whose operator is
11
- # choice, as its kind names it, as HTML: a then that names its
12
- # arm, named, there being no then in the code, plain; a
13
- # ternary's coloured as HtmlSyntax.ternary_arm has it; any
14
- # other, eg else or when, coloured as the code it is.
15
- def self.arm(arm, choice, named)
16
- label = Kinds.of(choice).arm_label(arm, choice)
17
- return CGI.escapeHTML(label) if named
18
- return HtmlSyntax.ternary_arm(label) if choice == '?:'
19
-
20
- HtmlSyntax.fragment(label)
9
+ # The label of an arm of a ternary, the one kind whose fold
10
+ # shows its arms, as Choice names it, as HTML, coloured as
11
+ # HtmlSyntax.ternary_arm has it.
12
+ def self.arm(arm)
13
+ HtmlSyntax.ternary_arm(Kinds::Choice.arm_label(arm))
21
14
  end
22
15
  end
23
16
  end
@@ -64,7 +64,7 @@ module PathCoverage
64
64
  source, sites = parsed.values_at(:source, :sites)
65
65
  plain = SourceLines.of(source, sites, operands)
66
66
  lines = coloured(source, plain)
67
- tops = HtmlCards.tops(path, parsed, lines, site_paths)
67
+ tops = HtmlCards.tops(path, parsed, [operands, site_paths])
68
68
  page = HtmlFile.page(path, lines, cards + tops)
69
69
  FileUtils.mkdir_p(File.dirname(out))
70
70
  File.write(out, page)
@@ -11,20 +11,21 @@ module PathCoverage
11
11
  module HtmlStatements
12
12
  # Example: ship, an if then a value, gives its title row,
13
13
  # the column titles, then an if row and a value row.
14
- # The card of the def named name at site, its rows' taken as
15
- # MethodStatements.taken gives them, last its def's last
16
- # line. tree, when given, gives a row's site's tree rows,
17
- # folded under its row.
18
- def self.card(site, name, rows, taken, last, &)
14
+ # The card at site drawn from card, as the JSON report lists
15
+ # it, as WithinMethods.card gives it: its name, its last line,
16
+ # the ways through it and its rows. tree, when given, gives a
17
+ # row's site's tree rows, folded under its row.
18
+ def self.card(site, card, &)
19
19
  first, column = site.split(':').last(2)
20
+ rows = card['rows']
20
21
  attrs = [
21
22
  %(id="paths-#{first}" data-first="#{first}"),
22
- %(data-col="#{column}" data-last="#{last}"),
23
- %(data-status="#{status(rows, taken)}" hidden="hidden")
23
+ %(data-col="#{column}" data-last="#{card['last']}"),
24
+ %(data-status="#{status(card)}" hidden="hidden")
24
25
  ].join(' ')
25
- head = title_row(first, name, rows, taken) + columns_row
26
+ head = title_row(first, card, rows) + columns_row
26
27
  %(<div class="#{GRID}" #{attrs}>) +
27
- %(#{head}#{body(rows, taken, &)}</div>)
28
+ %(#{head}#{body(rows, &)}</div>)
28
29
  end
29
30
 
30
31
  # The classes of every card.
@@ -33,45 +34,69 @@ module PathCoverage
33
34
  # Example: FEE = (a ? 1 : 0) + (b ? 2 : 0) on line 1, scope
34
35
  # file, gives a card titled file, a ?: row each.
35
36
  # The card of the sites at the top level whose lines start at
36
- # site, as card gives it, last its lines' last; titled by
37
- # scope, eg file or its module, as a method's card is by its
38
- # method, and marked top-level, as it is no method's: a class
39
- # no other part of the page has, so no style of another's, eg
40
- # the header's top line's display, shows it when it is
41
- # hidden.
42
- def self.top_card(site, scope, rows, taken, last, &)
43
- card(site, scope, rows, taken, last, &)
37
+ # site, drawn from card as card draws a def's, its name its
38
+ # scope, eg file or its module, as a method's card is named
39
+ # by its method, its last its lines' last; and marked
40
+ # top-level, as it is no method's: a class no other part of
41
+ # the page has, so no style of another's, eg the header's top
42
+ # line's display, shows it when it is hidden.
43
+ def self.top_card(site, card, &)
44
+ card(site, card, &)
44
45
  .sub(%(class="#{GRID}"), %(class="#{GRID} top-level"))
45
46
  end
46
47
 
47
- # Each statement's row, a site's with the rows tree gives
48
- # for that site folded under it.
49
- def self.body(rows, taken, &tree)
50
- rows.zip(taken).map do |row, count|
51
- site = row.site
52
- folded = tree&.call(site) if site
53
- row_of(row, count, folds: !folded.nil?) + fold(row, folded)
48
+ # Each row's, a site's with the rows tree gives for that site,
49
+ # headed as its row is, folded under it; rows as the JSON
50
+ # report lists a card's.
51
+ def self.body(rows, &tree)
52
+ rows.map do |row|
53
+ site = row['site']
54
+ folded = tree&.call(site, row['top']) if site
55
+ row_of(row, folds: !folded.nil?) + fold(site, folded)
54
56
  end.join
55
57
  end
56
58
 
57
- # covered when every row's taken is known and is all of its
58
- # paths; gaps otherwise, as a row not known may have one.
59
- def self.status(rows, taken)
60
- done = rows.zip(taken).all? { |row, count| count == row.paths }
59
+ # card's status: covered when every row's taken is known and
60
+ # is all of its paths, and its method was called, if it is a
61
+ # method's; gaps otherwise, as a row not known may have one,
62
+ # and a method never called, even of no rows, ran none of its
63
+ # code.
64
+ def self.status(card)
65
+ rows = card['rows']
66
+ done = rows.all? { |row| row['taken'] == row['paths'] } &&
67
+ card['calls'] != 0
61
68
  done ? 'covered' : 'gaps'
62
69
  end
63
70
 
64
- # The row level with the def: its name, *complexity, then
65
- # how many of its paths were not taken, those of rows not
66
- # known among them, and how many were.
67
- def self.title_row(first, name, rows, taken)
68
- seen = taken.compact.sum
71
+ # The row level with the def: card's name and how many times
72
+ # it was called, *its ways, then how many of its rows' paths
73
+ # were not taken, those of rows not known among them, and how
74
+ # many were.
75
+ def self.title_row(first, card, rows)
76
+ seen = rows.map { _1['taken'] }.compact.sum
77
+ paths = rows.map { _1['paths'] }
69
78
  cells = [
70
- "*#{MethodStatements.complexity(rows)}",
71
- (MethodStatements.size(rows) - seen).to_s, seen.to_s
79
+ "*#{card['ways']}",
80
+ (MethodStatements.size(paths) - seen).to_s, seen.to_s
72
81
  ]
73
82
  attrs = %(class="prow calls" data-line="#{first}")
74
- row(attrs, CGI.escapeHTML(name.to_s), cells)
83
+ row(attrs, title_label(card), cells)
84
+ end
85
+
86
+ # The label of card's title row: its name, escaped, then how
87
+ # many times its method was called.
88
+ def self.title_label(card)
89
+ CGI.escapeHTML(card['name'].to_s) + call_count(card['calls'])
90
+ end
91
+
92
+ # Example: 3 as <span class="call-count">&times;3</span>.
93
+ # How many times a method was called, after its name, a gap,
94
+ # never, for 0; none for a top card, or when not known.
95
+ def self.call_count(calls)
96
+ return '' if calls.nil?
97
+
98
+ css = calls.zero? ? 'call-count never' : 'call-count'
99
+ %(<span class="#{css}">&times;#{calls}</span>)
75
100
  end
76
101
 
77
102
  # The row naming the not taken and taken columns.
@@ -80,44 +105,39 @@ module PathCoverage
80
105
  row('class="prow columns"', 'line:col', cells)
81
106
  end
82
107
 
83
- # One statement's row: its line:column, the column two
84
- # digits so they line up, its top, how many of its paths
85
- # were not taken, and how many were, ? for both when not
86
- # known. A site's row is marked as one, so a click on it can
87
- # open its tree; when it folds a tree, its arrow, left of its
108
+ # One statement's row, as the JSON report lists it: its
109
+ # line:column, its at, its top, how many of its paths were
110
+ # not taken, and how many were, ? for both when not known. A
111
+ # site's row is marked as one, so a click on it can open its
112
+ # tree; when it folds a tree, its arrow, left of its
88
113
  # line:column, shows whether the fold is open.
89
- def self.row_of(statement, count, folds: false)
90
- counts = count ? [statement.paths - count, count] : %w[? ?]
91
- cells = [top(statement), *counts.map(&:to_s)]
92
- css = statement.site ? 'prow site' : 'prow'
93
- attrs = %(class="#{css}" data-line="#{statement.line}")
94
- lead = folds ? arrow(statement) : ''
95
- row(attrs, label(statement), cells, lead)
114
+ def self.row_of(row, folds: false)
115
+ count = row['taken']
116
+ counts = count ? [row['paths'] - count, count] : %w[? ?]
117
+ cells = [top(row['top']), *counts.map(&:to_s)]
118
+ css = row['site'] ? 'prow site' : 'prow'
119
+ at = row['at']
120
+ attrs = %(class="#{css}" data-line="#{Integer(at[/\d+/])}")
121
+ lead = folds ? arrow(at) : ''
122
+ row(attrs, at, cells, lead)
96
123
  end
97
124
 
98
125
  # Example: if, a site's top, as <span class="k">if</span>.
99
- # statement's top, coloured as the code pane colours the
100
- # code it quotes, eg if, def and return as keywords; but
101
- # value and (), which name kinds of statement and quote no
102
- # code, escaped and plain.
103
- def self.top(statement)
104
- text = statement.top
105
- return CGI.escapeHTML(text) if KINDS.include?(text)
106
-
107
- HtmlSyntax.fragment(text)
126
+ # A row's top, text, coloured as the code pane colours the
127
+ # code it quotes, eg if and return as keywords, as
128
+ # HtmlSyntax.label colours it.
129
+ def self.top(text)
130
+ HtmlSyntax.label(text)
108
131
  end
109
132
 
110
- # The tops that name a kind of statement, quoting no code.
111
- KINDS = %w[value ()].freeze
112
-
113
- # The arrow left of a row's line:column, its glyph, as
114
- # style.css draws it, pointing down while its fold is shut
133
+ # The arrow left of the line:column at of a row, its glyph,
134
+ # as style.css draws it, pointing down while its fold is shut
115
135
  # and up while it is open.
116
- def self.arrow(statement)
136
+ def self.arrow(at)
117
137
  [
118
138
  '<button type="button" class="fold-arrow"',
119
139
  ' aria-expanded="false"',
120
- %( aria-label="Paths of #{label(statement)}"></button>)
140
+ %( aria-label="Paths of #{at}"></button>)
121
141
  ].join
122
142
  end
123
143
 
@@ -129,14 +149,14 @@ module PathCoverage
129
149
  line: statement.line, column: statement.column)
130
150
  end
131
151
 
132
- # The fold under statement's row, hidden until the row is
133
- # clicked: tree, its site's rows as its tree draws them.
134
- # Empty for a row with no tree.
135
- def self.fold(statement, tree)
152
+ # The fold under the row of site, hidden until the row is
153
+ # clicked: tree, site's rows as its tree draws them. Empty
154
+ # for a row with no tree.
155
+ def self.fold(site, tree)
136
156
  return '' unless tree
137
157
 
138
158
  [
139
- %(<div class="fold" data-site="#{statement.site}"),
159
+ %(<div class="fold" data-site="#{site}"),
140
160
  ' hidden="hidden"><div class="site" data-site="">',
141
161
  tree, '</div></div>'
142
162
  ].join
@@ -133,6 +133,17 @@ module PathCoverage
133
133
  html(text, of(text).fetch(1, []))
134
134
  end
135
135
 
136
+ # Example: if/else as <span class="k">if</span>/<span
137
+ # class="k">else</span>.
138
+ # A row's or a fold's label, coloured as fragment colours it;
139
+ # but a label naming a choice and its else, eg if/else, each of
140
+ # its words, as code would read /else as a regexp's start.
141
+ def self.label(text)
142
+ return fragment(text) unless text.match?(%r{\A\w+/else\z})
143
+
144
+ text.split('/').map { fragment(_1) }.join('/')
145
+ end
146
+
136
147
  # A ternary's arm's label, eg ? total > 100, as HTML: its ? or
137
148
  # : coloured as an operator, the code after it as code.
138
149
  def self.ternary_arm(label)