path_coverage 0.2.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.
- checksums.yaml +4 -4
- data/README.md +172 -121
- data/lib/path_coverage/calls.rb +4 -11
- data/lib/path_coverage/card.rb +14 -0
- data/lib/path_coverage/card_tree.rb +186 -0
- data/lib/path_coverage/card_ways.rb +140 -0
- data/lib/path_coverage/condition.rb +11 -4
- data/lib/path_coverage/configuration.rb +1 -17
- data/lib/path_coverage/configuration_paths.rb +4 -2
- data/lib/path_coverage/console_summary.rb +15 -17
- data/lib/path_coverage/gaps.rb +12 -9
- data/lib/path_coverage/html/file.html +5 -5
- data/lib/path_coverage/html/index.html +3 -1
- data/lib/path_coverage/html/settings.js +50 -0
- data/lib/path_coverage/html/side.js +470 -432
- data/lib/path_coverage/html/style.css +345 -226
- data/lib/path_coverage/html/theme.js +27 -0
- data/lib/path_coverage/html_branch.rb +30 -0
- data/lib/path_coverage/html_cards.rb +88 -0
- data/lib/path_coverage/html_cells.rb +71 -0
- data/lib/path_coverage/html_file.rb +82 -68
- data/lib/path_coverage/html_index.rb +28 -29
- data/lib/path_coverage/html_index_head.rb +10 -30
- data/lib/path_coverage/html_labels.rb +16 -0
- data/lib/path_coverage/html_methods.rb +66 -0
- data/lib/path_coverage/html_nav.rb +50 -50
- data/lib/path_coverage/html_report.rb +45 -49
- data/lib/path_coverage/html_statements.rb +186 -0
- data/lib/path_coverage/html_syntax.rb +167 -0
- data/lib/path_coverage/html_template.rb +6 -0
- data/lib/path_coverage/html_tree.rb +90 -88
- data/lib/path_coverage/json_reader.rb +21 -14
- data/lib/path_coverage/json_writer.rb +26 -13
- data/lib/path_coverage/kernel.rb +32 -51
- data/lib/path_coverage/kinds/block.rb +2 -1
- data/lib/path_coverage/kinds/case.rb +7 -9
- data/lib/path_coverage/kinds/choice.rb +3 -7
- data/lib/path_coverage/kinds/contains.rb +9 -5
- data/lib/path_coverage/kinds/safe.rb +6 -18
- data/lib/path_coverage/kinds/write.rb +0 -6
- data/lib/path_coverage/manifest.rb +5 -3
- data/lib/path_coverage/manifest_blocks.rb +3 -4
- data/lib/path_coverage/manifest_case.rb +2 -3
- data/lib/path_coverage/manifest_choices.rb +41 -20
- data/lib/path_coverage/manifest_folding.rb +48 -11
- data/lib/path_coverage/merge.rb +3 -3
- data/lib/path_coverage/method_statements.rb +305 -0
- data/lib/path_coverage/recorder.rb +12 -31
- data/lib/path_coverage/render.rb +19 -22
- data/lib/path_coverage/rewriter.rb +36 -55
- data/lib/path_coverage/site_paths.rb +8 -0
- data/lib/path_coverage/site_tree.rb +9 -0
- data/lib/path_coverage/statement_arms.rb +194 -0
- data/lib/path_coverage/summary.rb +11 -15
- data/lib/path_coverage/totals.rb +6 -12
- data/lib/path_coverage/version.rb +1 -1
- data/lib/path_coverage/within_methods.rb +177 -0
- metadata +19 -12
- data/lib/path_coverage/html/toggle.js +0 -12
- data/lib/path_coverage/html_paths.rb +0 -138
- data/lib/path_coverage/path_gaps.rb +0 -41
- data/lib/path_coverage/path_manifest.rb +0 -110
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Switches the page between light and dark as the title bar's theme
|
|
2
|
+
// button is pressed: the page's html element names the theme, and
|
|
3
|
+
// the page's CSS draws it. The theme is a setting, carried from page
|
|
4
|
+
// to page as settings.js has it; a page with none opens dark.
|
|
5
|
+
(function () {
|
|
6
|
+
var settings = window.pathCoverageSettings;
|
|
7
|
+
var button = document.querySelector('button.theme');
|
|
8
|
+
if (!button) { return; }
|
|
9
|
+
|
|
10
|
+
// Names theme on the html element, labels the button with the
|
|
11
|
+
// theme it switches to, and makes every link carry theme.
|
|
12
|
+
function show(theme) {
|
|
13
|
+
document.documentElement.setAttribute('data-theme', theme);
|
|
14
|
+
var other = theme === 'dark' ? 'light' : 'dark';
|
|
15
|
+
button.textContent = theme === 'dark' ? '☀' : '☾';
|
|
16
|
+
button.setAttribute('aria-label', 'Switch to ' + other);
|
|
17
|
+
button.title = 'Switch to ' + other;
|
|
18
|
+
settings.carry('theme', theme);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
show(settings.given('theme', ['light', 'dark']) || 'dark');
|
|
22
|
+
button.addEventListener('click', function () {
|
|
23
|
+
var theme = document.documentElement.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';
|
|
24
|
+
show(theme);
|
|
25
|
+
settings.keep('theme', theme);
|
|
26
|
+
});
|
|
27
|
+
})();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module PathCoverage
|
|
2
|
+
# The branches of a site's tree on a file's page, joining each
|
|
3
|
+
# operand's row to its operator's. A branch is a string of
|
|
4
|
+
# kinds, one letter per cell: t a tee, l an ell, v a bar, h a
|
|
5
|
+
# dash, s a space. CSS draws each kind as lines a whole row
|
|
6
|
+
# tall, so a branch joins the rows above and below it.
|
|
7
|
+
module HtmlBranch
|
|
8
|
+
# The branch to an operand with more after it.
|
|
9
|
+
TEE = 'ths'.freeze
|
|
10
|
+
# The branch to the last operand.
|
|
11
|
+
ELL = 'lhs'.freeze
|
|
12
|
+
# The indent under an operand with more after it, its bar
|
|
13
|
+
# running on down to them.
|
|
14
|
+
BAR = 'vss'.freeze
|
|
15
|
+
# The indent under the last operand.
|
|
16
|
+
GAP = 'sss'.freeze
|
|
17
|
+
|
|
18
|
+
# Example: ths gives a tee, a dash and a space cell.
|
|
19
|
+
# The cell drawing branch: a cell of each of its kinds,
|
|
20
|
+
# hidden from screen readers, as the rows' order already
|
|
21
|
+
# says how they nest.
|
|
22
|
+
def self.cell(branch)
|
|
23
|
+
cells = branch.chars.map do |kind|
|
|
24
|
+
%(<span class="bx" data-bx="#{kind}"></span>)
|
|
25
|
+
end
|
|
26
|
+
attrs = 'class="branch" data-branch="" aria-hidden="true"'
|
|
27
|
+
%(<span #{attrs}>#{cells.join}</span>)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require_relative 'card'
|
|
2
|
+
require_relative 'html_statements'
|
|
3
|
+
require_relative 'html_tree'
|
|
4
|
+
require_relative 'site_tree'
|
|
5
|
+
require_relative 'within_methods'
|
|
6
|
+
|
|
7
|
+
module PathCoverage
|
|
8
|
+
# The cards of one file's page, as Card gives them, in the rail
|
|
9
|
+
# beside its code: a card for each of its methods, and one for
|
|
10
|
+
# each span of its lines holding sites at the top level; each
|
|
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.
|
|
15
|
+
module HtmlCards
|
|
16
|
+
# The cards of each method of the file at path, parsed as
|
|
17
|
+
# Manifest.parse gives it; site_paths as Result#paths gives
|
|
18
|
+
# them, reached as Recorder#reached does.
|
|
19
|
+
def self.methods(path, parsed, (site_paths, reached))
|
|
20
|
+
source, sites = parsed.values_at(:source, :sites)
|
|
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) }
|
|
25
|
+
end
|
|
26
|
+
|
|
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, &)
|
|
31
|
+
first, column = site.split(':').last(2).map { Integer(_1) }
|
|
32
|
+
status = HtmlStatements.status(card)
|
|
33
|
+
Card.new(first:, last: card['last'], column:, status:,
|
|
34
|
+
top: false, sites: nil, html:)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# A top card for each span of lines holding sites at the top
|
|
38
|
+
# level of the file at path, outside every def, as each
|
|
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))
|
|
43
|
+
source, sites = parsed.values_at(:source, :sites)
|
|
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) }
|
|
48
|
+
end
|
|
49
|
+
|
|
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:)
|
|
56
|
+
end
|
|
57
|
+
|
|
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
|
|
67
|
+
end
|
|
68
|
+
|
|
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 == '?:'
|
|
77
|
+
|
|
78
|
+
arm = condition.operands.grep(Arm).to_h { [_1.kind, _1] }[:else]
|
|
79
|
+
extent = arm&.extent
|
|
80
|
+
return nil unless extent
|
|
81
|
+
|
|
82
|
+
start = source.b.byteslice(0, extent.begin) =~ /\belse\s*\z/
|
|
83
|
+
return nil unless start
|
|
84
|
+
|
|
85
|
+
HtmlReport.at(source, start...(start + 4))
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require_relative 'kinds'
|
|
2
|
+
|
|
3
|
+
module PathCoverage
|
|
4
|
+
# The cells of a row of a site's tree on a file's page, one per
|
|
5
|
+
# path. A cell says what its path did: its text a letter, eg T
|
|
6
|
+
# or F, or empty with a mark CSS draws, eg a tick; with text to
|
|
7
|
+
# show on hover when its mark alone may not say enough.
|
|
8
|
+
module HtmlCells
|
|
9
|
+
# [text, mark, hover] of a leaf's or a condition's cell, by
|
|
10
|
+
# the value it took on the path: a letter for each value
|
|
11
|
+
# but a &. receiver's, which is a mark, present or absent,
|
|
12
|
+
# hovering as not nil or nil.
|
|
13
|
+
OUTCOMES = {
|
|
14
|
+
true => ['T'], false => ['F'], nil => [''],
|
|
15
|
+
ITEMS[0] => ['0'], ITEMS[1] => ['1'], ITEMS[2] => ['*'],
|
|
16
|
+
ANSWERS[0] => ['T'], ANSWERS[1] => ['F'], ANSWERS[2] => ['TF'],
|
|
17
|
+
PRESENCE[0] => ['', 'present', PRESENCE[0]],
|
|
18
|
+
PRESENCE[1] => ['', 'absent', PRESENCE[1]]
|
|
19
|
+
}.freeze
|
|
20
|
+
|
|
21
|
+
# [text, mark] of a ternary's arm's cell: taken on a path
|
|
22
|
+
# that took it, else blank.
|
|
23
|
+
TAKEN = { true => ['', 'taken'], false => [''] }.freeze
|
|
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
|
+
|
|
30
|
+
# The cells of values, each named as names gives it.
|
|
31
|
+
def self.of(values, names = OUTCOMES)
|
|
32
|
+
values.map { |value| cell(*names[value]) }.join
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# One cell: text, and its mark and its hover, when it has
|
|
36
|
+
# them.
|
|
37
|
+
def self.cell(text, mark = nil, hover = nil)
|
|
38
|
+
attrs = +'class="cell" data-cell=""'
|
|
39
|
+
attrs << %( data-mark="#{mark}") if mark
|
|
40
|
+
attrs << %( data-hover="#{hover}") if hover
|
|
41
|
+
%(<span #{attrs}>#{text}</span>)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Example: counts 0, 2 and 1284 give 0, * and *.
|
|
45
|
+
# One cell per path: 0 for a path never taken, marked as a
|
|
46
|
+
# gap, * for one taken any number of times, as whether it
|
|
47
|
+
# was taken is what counts; how many times shows on hover,
|
|
48
|
+
# so a count in the thousands never widens the cell.
|
|
49
|
+
def self.counts(counts)
|
|
50
|
+
counts.map do |count|
|
|
51
|
+
css, mark = MARKS[count.zero?]
|
|
52
|
+
hover = times(count)
|
|
53
|
+
%(<span class="#{css}" data-count="" data-hover="#{hover}">) +
|
|
54
|
+
%(#{mark}</span>)
|
|
55
|
+
end.join
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# [class, mark] of a path's count cell, by whether its count
|
|
59
|
+
# is zero.
|
|
60
|
+
MARKS = { true => ['count never', '0'],
|
|
61
|
+
false => ['count', '*'] }.freeze
|
|
62
|
+
|
|
63
|
+
# Example: 1 gives 1 time, 1284 gives 1,284 times.
|
|
64
|
+
# How many times a path was taken, as its mark's hover reads
|
|
65
|
+
# it, its thousands apart, so a big count still reads.
|
|
66
|
+
def self.times(count)
|
|
67
|
+
digits = count.to_s.reverse.scan(/\d{1,3}/).join(',').reverse
|
|
68
|
+
"#{digits} #{count == 1 ? 'time' : 'times'}"
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -1,109 +1,123 @@
|
|
|
1
1
|
require 'cgi/escape'
|
|
2
|
+
require_relative 'card'
|
|
3
|
+
require_relative 'html_methods'
|
|
2
4
|
require_relative 'html_nav'
|
|
5
|
+
require_relative 'html_syntax'
|
|
3
6
|
require_relative 'html_template'
|
|
4
|
-
require_relative 'html_tree'
|
|
5
7
|
|
|
6
8
|
module PathCoverage
|
|
7
|
-
# One covered file's HTML page: its source
|
|
8
|
-
#
|
|
9
|
-
# opens
|
|
9
|
+
# One covered file's HTML page: its source beside the rail of
|
|
10
|
+
# its cards, as Card gives them, one open at a time. A method's
|
|
11
|
+
# def number opens its card; a site outside every method has
|
|
12
|
+
# one button over its lines' numbers that opens their top card.
|
|
10
13
|
module HtmlFile
|
|
11
14
|
# The whole page for the file at path (relative to root),
|
|
12
15
|
# written at files/<path>.html, so it links back to the
|
|
13
16
|
# index one folder up for each folder in that.
|
|
14
|
-
def self.page(path, lines,
|
|
15
|
-
HtmlTemplate.
|
|
16
|
-
|
|
17
|
+
def self.page(path, lines, cards = [])
|
|
18
|
+
HtmlTemplate.page(
|
|
19
|
+
'file.html',
|
|
17
20
|
'path' => CGI.escapeHTML(path),
|
|
18
21
|
'index' => "#{'../' * (path.count('/') + 1)}index.html",
|
|
19
|
-
'style' => HtmlTemplate.asset('style.css'),
|
|
20
22
|
'script' => script,
|
|
21
|
-
'
|
|
22
|
-
'jumps' => HtmlNav.jumps(
|
|
23
|
-
'listing' => listing(lines,
|
|
23
|
+
'rail' => cards.map(&:html).join("\n"),
|
|
24
|
+
'jumps' => HtmlNav.jumps(cards),
|
|
25
|
+
'listing' => listing(lines, cards)
|
|
24
26
|
)
|
|
25
27
|
end
|
|
26
28
|
|
|
27
|
-
# The page's script: its
|
|
29
|
+
# The page's script: its rail's behaviour, then its settings
|
|
30
|
+
# and its theme button.
|
|
28
31
|
def self.script
|
|
29
|
-
|
|
32
|
+
%w[side.js settings.js theme.js].map do |name|
|
|
33
|
+
HtmlTemplate.asset(name)
|
|
34
|
+
end.join
|
|
30
35
|
end
|
|
31
36
|
|
|
32
|
-
# The source listing of lines, as SourceLines.of gives them
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
# The source listing of lines, as SourceLines.of gives them,
|
|
38
|
+
# marked with the methods of cards: a row per line, but one
|
|
39
|
+
# row over all the lines of a site outside every method.
|
|
40
|
+
def self.listing(lines, cards = [])
|
|
41
|
+
methods = HtmlMethods.of(cards)
|
|
42
|
+
tops = cards.select(&:top).to_h { |card| [card.first, card] }
|
|
43
|
+
rows = lines.chunk { |line| row_key(line, methods) }
|
|
44
|
+
body = rows.map do |key, row|
|
|
45
|
+
next line(row[0], cards, methods) unless key.is_a?(Range)
|
|
46
|
+
|
|
47
|
+
loose_block(row, cards, tops[key.begin])
|
|
39
48
|
end
|
|
40
|
-
gaps = HtmlNav.gap_lines(blocks)
|
|
41
|
-
body = blocks.map { |block| block(block, trees, gaps) }
|
|
42
49
|
%(<div class="code">\n#{body.join("\n")}\n</div>)
|
|
43
50
|
end
|
|
44
51
|
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return plain_line(first, cell) if first[:span].nil?
|
|
52
|
+
# The span of line's site when it is outside every method, so
|
|
53
|
+
# its lines share one row; else line's own number.
|
|
54
|
+
def self.row_key(line, methods)
|
|
55
|
+
span = line[:span]
|
|
56
|
+
loose = span && HtmlMethods.loose?(methods, span.begin)
|
|
57
|
+
loose ? span : line[:number]
|
|
58
|
+
end
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
# A line of its own, after its gutter, folded when it is in a
|
|
61
|
+
# method's body.
|
|
62
|
+
def self.line(line, cards, methods)
|
|
63
|
+
number = line[:number]
|
|
64
|
+
cell = HtmlNav.cell([number], cards)
|
|
65
|
+
folded = HtmlMethods.folded?(methods, number)
|
|
66
|
+
css = folded ? 'line method-folded' : 'line'
|
|
67
|
+
parts = number(number, methods) + code(line, methods)
|
|
68
|
+
%(<div class="#{css}">#{cell}#{parts}</div>)
|
|
58
69
|
end
|
|
59
70
|
|
|
60
|
-
# The lines of
|
|
61
|
-
# all their numbers,
|
|
62
|
-
# two or more,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
button = button(lines[0],
|
|
69
|
-
|
|
71
|
+
# The lines of a site outside every method after their gutter:
|
|
72
|
+
# one button over all their numbers, opening their top card,
|
|
73
|
+
# top, and how many sites it opens when that is two or more,
|
|
74
|
+
# beside their code.
|
|
75
|
+
def self.loose_block(lines, cards, top)
|
|
76
|
+
numbers = lines.map { |line| line[:number] }
|
|
77
|
+
cell = HtmlNav.cell(numbers, cards)
|
|
78
|
+
spans = numbers.map { |number| number(number, []) }.join
|
|
79
|
+
button = button(lines[0], top, site_count(top) + spans)
|
|
80
|
+
srcs = lines.map { |line| code(line, []) }.join
|
|
81
|
+
%(<div class="block">#{cell}#{button}) +
|
|
82
|
+
%(<div class="srcs">#{srcs}</div></div>)
|
|
70
83
|
end
|
|
71
84
|
|
|
72
|
-
# The count of a
|
|
73
|
-
def self.site_count(
|
|
85
|
+
# The count of a top card's sites, shown only for two or more.
|
|
86
|
+
def self.site_count(top)
|
|
87
|
+
sites = top ? top.sites : 0
|
|
74
88
|
return '' if sites < 2
|
|
75
89
|
|
|
76
90
|
%(<span class="site-count" data-site-count="">#{sites}</span>)
|
|
77
91
|
end
|
|
78
92
|
|
|
79
|
-
#
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
# The button over a span's numbers, toggling the tree named
|
|
86
|
-
# after its first line; expanded when that tree starts open.
|
|
87
|
-
def self.button(first, numbers)
|
|
88
|
-
expanded = first[:status] == :gaps
|
|
93
|
+
# The button over a loose site's numbers, wearing its top
|
|
94
|
+
# card's status, else its first line's, closed until its card
|
|
95
|
+
# opens.
|
|
96
|
+
def self.button(first, top, numbers)
|
|
97
|
+
status = top ? top.status : first[:status]
|
|
89
98
|
[
|
|
90
|
-
%(<button type="button" class="lnum"),
|
|
91
|
-
%( data-status="#{
|
|
92
|
-
%( aria-
|
|
93
|
-
|
|
99
|
+
%(<button type="button" class="lnum loose"),
|
|
100
|
+
%( data-status="#{status}" aria-expanded="false"),
|
|
101
|
+
%( aria-controls="paths-#{first[:number]}">),
|
|
102
|
+
numbers, '</button>'
|
|
94
103
|
].join
|
|
95
104
|
end
|
|
96
105
|
|
|
97
|
-
# One line's number, the target of a link to #L<number
|
|
98
|
-
def
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
# One line's number, the target of a link to #L<number>; a
|
|
107
|
+
# def's marked to open its method's card.
|
|
108
|
+
def self.number(number, methods)
|
|
109
|
+
css = HtmlMethods.number_attributes(methods, number)
|
|
110
|
+
attributes = %(#{css} id="L#{number}" data-line="#{number}")
|
|
111
|
+
%(<span #{attributes}>#{number}</span>)
|
|
101
112
|
end
|
|
102
113
|
|
|
103
|
-
# One line's code, escaped
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
114
|
+
# One line's code, escaped, each of its tokens, if any, in a
|
|
115
|
+
# span of its colour's class, marked with its methods.
|
|
116
|
+
def self.code(line, methods)
|
|
117
|
+
number, plain = line.values_at(:number, :text)
|
|
118
|
+
text = HtmlSyntax.html(plain, line.fetch(:tokens, []))
|
|
119
|
+
css = HtmlMethods.src_attributes(methods, number, plain)
|
|
120
|
+
%(<span #{css} data-src="">#{text}</span>)
|
|
107
121
|
end
|
|
108
122
|
end
|
|
109
123
|
end
|
|
@@ -16,9 +16,8 @@ module PathCoverage
|
|
|
16
16
|
def self.page(rows, total, groups = [], ignored: [])
|
|
17
17
|
tables = [['All files', rows, total], *groups]
|
|
18
18
|
names = tables.map(&:first)
|
|
19
|
-
HtmlTemplate.
|
|
20
|
-
|
|
21
|
-
'style' => HtmlTemplate.asset('style.css'),
|
|
19
|
+
HtmlTemplate.page(
|
|
20
|
+
'index.html',
|
|
22
21
|
'script' => script(groups),
|
|
23
22
|
'tabs' => groups.empty? ? '' : HtmlTabs.bar(names),
|
|
24
23
|
'tables' => tables_of(tables),
|
|
@@ -43,18 +42,21 @@ module PathCoverage
|
|
|
43
42
|
end.join("\n")
|
|
44
43
|
end
|
|
45
44
|
|
|
46
|
-
# The page's script: its column sorting,
|
|
47
|
-
# its
|
|
45
|
+
# The page's script: its column sorting, with groups its tab
|
|
46
|
+
# switching, then its settings and its theme button.
|
|
48
47
|
def self.script(groups)
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
names = ['sort.js', *('tabs.js' unless groups.empty?),
|
|
49
|
+
'settings.js', 'theme.js']
|
|
50
|
+
names.map { |name| HtmlTemplate.asset(name) }.join
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
# The index-th tab's table of rows, total as its footer; any
|
|
54
|
-
# but the first starts hidden.
|
|
54
|
+
# but the first starts hidden. Only the first, All files,
|
|
55
|
+
# gives its rows ids, as the others repeat its rows.
|
|
55
56
|
def self.table(index, rows, total)
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
anchored = index.zero?
|
|
58
|
+
body = rows.map { |row| row(row, anchored:) }.join("\n")
|
|
59
|
+
head = HtmlIndexHead.row
|
|
58
60
|
[
|
|
59
61
|
open_tag(index),
|
|
60
62
|
"<thead>\n#{head}\n</thead>",
|
|
@@ -73,11 +75,13 @@ module PathCoverage
|
|
|
73
75
|
end
|
|
74
76
|
|
|
75
77
|
# The table row of one Summary.files row; each cell has a
|
|
76
|
-
# data-sort value for the page's column sorting.
|
|
77
|
-
|
|
78
|
+
# data-sort value for the page's column sorting. An anchored
|
|
79
|
+
# row has the id row-<path>, which the file's page links to.
|
|
80
|
+
def self.row(row, anchored: false)
|
|
78
81
|
path = CGI.escapeHTML(row[:path])
|
|
79
82
|
link = %(<a href="files/#{path}.html">#{path}</a>)
|
|
80
|
-
"
|
|
83
|
+
id = anchored ? %( id="row-#{path}") : ''
|
|
84
|
+
"<tr#{id}>#{cell(path, link)}#{counts(row).join}</tr>"
|
|
81
85
|
end
|
|
82
86
|
|
|
83
87
|
# The footer row: the sums over the table's files.
|
|
@@ -86,32 +90,27 @@ module PathCoverage
|
|
|
86
90
|
end
|
|
87
91
|
|
|
88
92
|
# The cells after the file's: its sites, then its total
|
|
89
|
-
# within each
|
|
90
|
-
# total within each method.
|
|
93
|
+
# within each method.
|
|
91
94
|
def self.counts(row)
|
|
92
|
-
|
|
93
|
-
cell(row[:sites], row[:sites]),
|
|
94
|
-
*paths_cells(row[:decisions], 'no decisions')
|
|
95
|
-
]
|
|
96
|
-
return cells unless row[:methods]
|
|
97
|
-
|
|
98
|
-
none = 'no method with two or more decisions'
|
|
99
|
-
cells + paths_cells(row[:methods], none)
|
|
95
|
+
[cell(row[:sites], row[:sites]), *paths_cells(row[:methods])]
|
|
100
96
|
end
|
|
101
97
|
|
|
98
|
+
# Why a total of no paths shows no percent.
|
|
99
|
+
NONE = 'no method with two or more decisions'.freeze
|
|
100
|
+
|
|
102
101
|
# Three cells showing [taken, possible] paths, eg 3, / 6 and
|
|
103
102
|
# 50%, each sorted by its number, so they read 3 / 6 50%.
|
|
104
103
|
# With no paths to take, as in a group no file is in, or a
|
|
105
104
|
# file with no method of two or more decisions, the percent
|
|
106
|
-
# shows -, titled with
|
|
107
|
-
# value, which sort.js keeps last whichever way the column
|
|
108
|
-
#
|
|
109
|
-
def self.paths_cells(pair
|
|
105
|
+
# shows -, titled with NONE, saying why, with an empty sort
|
|
106
|
+
# value, which sort.js keeps last whichever way the column is
|
|
107
|
+
# sorted.
|
|
108
|
+
def self.paths_cells(pair)
|
|
110
109
|
taken, possible = pair
|
|
111
110
|
counts = [cell(taken, taken, css: 'taken'),
|
|
112
111
|
cell(possible, "/ #{possible}", css: 'of')]
|
|
113
|
-
|
|
114
|
-
return [*counts,
|
|
112
|
+
none = cell('', '-', NONE, css: 'percent')
|
|
113
|
+
return [*counts, none] if possible.zero?
|
|
115
114
|
|
|
116
115
|
percent = (100.0 * taken / possible).round
|
|
117
116
|
[*counts, cell(percent, "#{percent}%", css: 'percent')]
|
|
@@ -1,41 +1,21 @@
|
|
|
1
1
|
module PathCoverage
|
|
2
|
-
# The
|
|
3
|
-
#
|
|
4
|
-
#
|
|
2
|
+
# The heading row of the HTML index's files tables: File and
|
|
3
|
+
# Sites, then the taken, / of and % columns of each file's total
|
|
4
|
+
# within each method, every column sortable.
|
|
5
5
|
module HtmlIndexHead
|
|
6
6
|
# The class and label of each of a total's three columns.
|
|
7
7
|
PARTS = [%w[taken taken], ['of', '/ of'], %w[percent %]].freeze
|
|
8
8
|
|
|
9
|
-
# The
|
|
10
|
-
|
|
11
|
-
def self.of(methods)
|
|
12
|
-
names = ['Within each decision']
|
|
13
|
-
names << 'Within each method' if methods
|
|
14
|
-
rows = [top_row(names), part_row(names)]
|
|
15
|
-
rows.map { |row| "<tr>\n#{row}\n</tr>" }.join("\n")
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# The first heading row: File and Sites, each over both rows,
|
|
19
|
-
# then each total's name over its three columns.
|
|
20
|
-
def self.top_row(names)
|
|
9
|
+
# The heading row.
|
|
10
|
+
def self.row
|
|
21
11
|
fixed = [
|
|
22
|
-
heading('
|
|
23
|
-
heading(' class="num"
|
|
12
|
+
heading('', 0, 'text', 'File'),
|
|
13
|
+
heading(' class="num"', 1, 'number', 'Sites')
|
|
24
14
|
]
|
|
25
|
-
|
|
26
|
-
%(
|
|
15
|
+
parts = PARTS.each_with_index.map do |(css, label), i|
|
|
16
|
+
heading(%( class="#{css}"), 2 + i, 'number', label)
|
|
27
17
|
end
|
|
28
|
-
(fixed +
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# The second heading row: each total's taken, / of and %.
|
|
32
|
-
def self.part_row(names)
|
|
33
|
-
names.each_index.flat_map do |group|
|
|
34
|
-
PARTS.each_with_index.map do |(css, label), i|
|
|
35
|
-
column = 2 + (3 * group) + i
|
|
36
|
-
heading(%( class="#{css}"), column, 'number', label)
|
|
37
|
-
end
|
|
38
|
-
end.join("\n")
|
|
18
|
+
"<tr>\n#{(fixed + parts).join("\n")}\n</tr>"
|
|
39
19
|
end
|
|
40
20
|
|
|
41
21
|
# A sortable heading, attrs its th's, sorting the column-th
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require_relative 'condition'
|
|
2
|
+
require_relative 'html_syntax'
|
|
3
|
+
require_relative 'kinds'
|
|
4
|
+
|
|
5
|
+
module PathCoverage
|
|
6
|
+
# The labels of a site's tree on a file's page, coloured as the
|
|
7
|
+
# code they quote.
|
|
8
|
+
module HtmlLabels
|
|
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))
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module PathCoverage
|
|
2
|
+
# What each line of a file's page shows of the methods around
|
|
3
|
+
# it, from its cards, as Card gives them: a method's lines
|
|
4
|
+
# marked for CSS to draw its stripe and band, its def's number
|
|
5
|
+
# marked to open its card, and its body's rows folded under its
|
|
6
|
+
# def line until then. A top card, of sites outside every def,
|
|
7
|
+
# is no method's.
|
|
8
|
+
module HtmlMethods
|
|
9
|
+
# The cards of cards that are methods'.
|
|
10
|
+
def self.of(cards)
|
|
11
|
+
cards.reject(&:top)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Example: line 3, f's def at column 2, gives
|
|
15
|
+
# class="src in-method def-line" data-method-status="covered"
|
|
16
|
+
# style="--def-col: 2; --def-end: 15".
|
|
17
|
+
# The attributes of the code of line number, its text text:
|
|
18
|
+
# in a method, its innermost one's status and def's column,
|
|
19
|
+
# marked as its def line, with its text's length, or as its
|
|
20
|
+
# last line when it is; plain in none.
|
|
21
|
+
def self.src_attributes(methods, number, text)
|
|
22
|
+
holders = methods.select { |card| card.holds?(number) }
|
|
23
|
+
return 'class="src"' if holders.empty?
|
|
24
|
+
|
|
25
|
+
inner = holders.max_by(&:first)
|
|
26
|
+
css = ['src', 'in-method', *marks(methods, number)].join(' ')
|
|
27
|
+
style = "--def-col: #{inner.column}"
|
|
28
|
+
style += "; --def-end: #{text.length}" if inner.first == number
|
|
29
|
+
%(class="#{css}" data-method-status="#{inner.status}") +
|
|
30
|
+
%( style="#{style}")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# The marks of a line that is some method's first or last.
|
|
34
|
+
def self.marks(methods, number)
|
|
35
|
+
firsts = methods.map(&:first)
|
|
36
|
+
lasts = methods.map(&:last)
|
|
37
|
+
[('def-line' if firsts.include?(number)),
|
|
38
|
+
('method-end' if lasts.include?(number))].compact
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# The attributes a def's number adds, opening its method's
|
|
42
|
+
# card, which starts closed: none on any other line.
|
|
43
|
+
def self.number_attributes(methods, number)
|
|
44
|
+
card = methods.find { |each| each.first == number }
|
|
45
|
+
return 'class="lineno"' unless card
|
|
46
|
+
|
|
47
|
+
closed = 'aria-expanded="false"'
|
|
48
|
+
%(class="lineno mdef" data-status="#{card.status}" #{closed})
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# True when line number's row starts folded: in a method's
|
|
52
|
+
# body, after its def line. A row in a method is one line, so
|
|
53
|
+
# a def line's row is never folded under its own def.
|
|
54
|
+
def self.folded?(methods, number)
|
|
55
|
+
methods.any? do |card|
|
|
56
|
+
((card.first + 1)..card.last).cover?(number)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# True when line number is in no method, so its site's button
|
|
61
|
+
# opens its lines' top card.
|
|
62
|
+
def self.loose?(methods, number)
|
|
63
|
+
methods.none? { |card| card.holds?(number) }
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|