path_coverage 0.1.0 → 0.3.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 +315 -107
- data/lib/path_coverage/calls.rb +55 -23
- data/lib/path_coverage/card.rb +14 -0
- data/lib/path_coverage/condition.rb +33 -3
- data/lib/path_coverage/configuration.rb +43 -22
- data/lib/path_coverage/configuration_paths.rb +58 -0
- data/lib/path_coverage/console_summary.rb +75 -0
- data/lib/path_coverage/gaps.rb +32 -13
- data/lib/path_coverage/html/file.html +5 -5
- data/lib/path_coverage/html/index.html +6 -18
- data/lib/path_coverage/html/settings.js +50 -0
- data/lib/path_coverage/html/side.js +341 -413
- data/lib/path_coverage/html/sort.js +24 -21
- data/lib/path_coverage/html/style.css +339 -207
- data/lib/path_coverage/html/tabs.js +15 -0
- 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 +111 -0
- data/lib/path_coverage/html_cells.rb +66 -0
- data/lib/path_coverage/html_file.rb +82 -68
- data/lib/path_coverage/html_index.rb +95 -41
- data/lib/path_coverage/html_index_head.rb +29 -0
- data/lib/path_coverage/html_labels.rb +23 -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 +69 -56
- data/lib/path_coverage/html_statements.rb +166 -0
- data/lib/path_coverage/html_syntax.rb +156 -0
- data/lib/path_coverage/html_tabs.rb +26 -0
- data/lib/path_coverage/html_template.rb +6 -0
- data/lib/path_coverage/html_tree.rb +59 -74
- data/lib/path_coverage/json_reader.rb +101 -0
- data/lib/path_coverage/json_writer.rb +52 -7
- data/lib/path_coverage/kernel.rb +55 -53
- data/lib/path_coverage/kinds/base.rb +71 -0
- data/lib/path_coverage/kinds/block.rb +137 -0
- data/lib/path_coverage/kinds/case.rb +92 -0
- data/lib/path_coverage/kinds/chain.rb +45 -0
- data/lib/path_coverage/kinds/choice.rb +68 -0
- data/lib/path_coverage/kinds/contains.rb +113 -0
- data/lib/path_coverage/kinds/safe.rb +153 -0
- data/lib/path_coverage/kinds/write.rb +54 -0
- data/lib/path_coverage/kinds.rb +37 -0
- data/lib/path_coverage/manifest.rb +60 -20
- data/lib/path_coverage/manifest_blocks.rb +48 -10
- data/lib/path_coverage/manifest_case.rb +2 -3
- data/lib/path_coverage/manifest_chains.rb +76 -0
- data/lib/path_coverage/manifest_choices.rb +32 -18
- data/lib/path_coverage/manifest_folding.rb +91 -0
- data/lib/path_coverage/manifest_ignoring.rb +35 -0
- data/lib/path_coverage/manifest_writes.rb +67 -0
- data/lib/path_coverage/merge.rb +19 -3
- data/lib/path_coverage/method_statements.rb +300 -0
- data/lib/path_coverage/post.rb +8 -8
- data/lib/path_coverage/recorder.rb +20 -79
- data/lib/path_coverage/recorder_blocks.rb +68 -0
- data/lib/path_coverage/recorder_cases.rb +23 -0
- data/lib/path_coverage/recorder_chains.rb +40 -0
- data/lib/path_coverage/recorder_writes.rb +26 -0
- data/lib/path_coverage/render.rb +56 -47
- data/lib/path_coverage/result.rb +19 -0
- data/lib/path_coverage/rewriter.rb +69 -107
- data/lib/path_coverage/rewriter_nested.rb +62 -0
- data/lib/path_coverage/site_paths.rb +9 -58
- data/lib/path_coverage/site_tree.rb +21 -57
- data/lib/path_coverage/statement_arms.rb +161 -0
- data/lib/path_coverage/summary.rb +41 -17
- data/lib/path_coverage/totals.rb +6 -12
- data/lib/path_coverage/version.rb +1 -1
- data/lib/path_coverage/within_methods.rb +92 -0
- metadata +40 -11
- 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,15 @@
|
|
|
1
|
+
// Switches the index page's tabs: a click on a tab selects it and
|
|
2
|
+
// shows the table it controls, hiding every other tab's table.
|
|
3
|
+
(function () {
|
|
4
|
+
var tabs = Array.from(document.querySelectorAll('[role="tab"]'));
|
|
5
|
+
tabs.forEach(function (tab) {
|
|
6
|
+
tab.addEventListener('click', function () {
|
|
7
|
+
tabs.forEach(function (other) {
|
|
8
|
+
var selected = other === tab;
|
|
9
|
+
other.setAttribute('aria-selected', selected ? 'true' : 'false');
|
|
10
|
+
var table = document.getElementById(other.getAttribute('aria-controls'));
|
|
11
|
+
table.hidden = !selected;
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
})();
|
|
@@ -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,111 @@
|
|
|
1
|
+
require_relative 'card'
|
|
2
|
+
require_relative 'html_statements'
|
|
3
|
+
require_relative 'html_tree'
|
|
4
|
+
require_relative 'method_statements'
|
|
5
|
+
require_relative 'site_tree'
|
|
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
|
+
# site's row with its tree folded under it. It relies on
|
|
12
|
+
# HtmlReport.located to place each tree's rows in the source.
|
|
13
|
+
module HtmlCards
|
|
14
|
+
# The cards of each method of the file at path, parsed as
|
|
15
|
+
# Manifest.parse gives it; site_paths as Result#paths gives
|
|
16
|
+
# them, reached as Recorder#reached does.
|
|
17
|
+
def self.methods(path, parsed, (site_paths, reached))
|
|
18
|
+
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
|
|
27
|
+
end
|
|
28
|
+
|
|
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, &)
|
|
33
|
+
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:)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# A top card for each span of lines holding sites at the top
|
|
40
|
+
# 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)
|
|
44
|
+
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
|
|
50
|
+
end
|
|
51
|
+
|
|
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:)
|
|
62
|
+
end
|
|
63
|
+
|
|
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) }
|
|
69
|
+
end
|
|
70
|
+
|
|
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
|
|
83
|
+
|
|
84
|
+
# The kinds of node that are a top card's scope.
|
|
85
|
+
HOLDERS = [Prism::ModuleNode, Prism::ClassNode].freeze
|
|
86
|
+
|
|
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
|
|
93
|
+
|
|
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
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
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 an arm's cell, or of one only called: taken
|
|
22
|
+
# on a path that took it or called it, else blank.
|
|
23
|
+
TAKEN = { true => ['', 'taken'], false => [''] }.freeze
|
|
24
|
+
|
|
25
|
+
# The cells of values, each named as names gives it.
|
|
26
|
+
def self.of(values, names = OUTCOMES)
|
|
27
|
+
values.map { |value| cell(*names[value]) }.join
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# One cell: text, and its mark and its hover, when it has
|
|
31
|
+
# them.
|
|
32
|
+
def self.cell(text, mark = nil, hover = nil)
|
|
33
|
+
attrs = +'class="cell" data-cell=""'
|
|
34
|
+
attrs << %( data-mark="#{mark}") if mark
|
|
35
|
+
attrs << %( data-hover="#{hover}") if hover
|
|
36
|
+
%(<span #{attrs}>#{text}</span>)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Example: counts 0, 2 and 1284 give 0, * and *.
|
|
40
|
+
# One cell per path: 0 for a path never taken, marked as a
|
|
41
|
+
# gap, * for one taken any number of times, as whether it
|
|
42
|
+
# was taken is what counts; how many times shows on hover,
|
|
43
|
+
# so a count in the thousands never widens the cell.
|
|
44
|
+
def self.counts(counts)
|
|
45
|
+
counts.map do |count|
|
|
46
|
+
css, mark = MARKS[count.zero?]
|
|
47
|
+
hover = times(count)
|
|
48
|
+
%(<span class="#{css}" data-count="" data-hover="#{hover}">) +
|
|
49
|
+
%(#{mark}</span>)
|
|
50
|
+
end.join
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# [class, mark] of a path's count cell, by whether its count
|
|
54
|
+
# is zero.
|
|
55
|
+
MARKS = { true => ['count never', '0'],
|
|
56
|
+
false => ['count', '*'] }.freeze
|
|
57
|
+
|
|
58
|
+
# Example: 1 gives 1 time, 1284 gives 1,284 times.
|
|
59
|
+
# How many times a path was taken, as its mark's hover reads
|
|
60
|
+
# it, its thousands apart, so a big count still reads.
|
|
61
|
+
def self.times(count)
|
|
62
|
+
digits = count.to_s.reverse.scan(/\d{1,3}/).join(',').reverse
|
|
63
|
+
"#{digits} #{count == 1 ? 'time' : 'times'}"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
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
|
|
@@ -1,74 +1,128 @@
|
|
|
1
1
|
require 'cgi/escape'
|
|
2
|
+
require_relative 'html_index_head'
|
|
3
|
+
require_relative 'html_tabs'
|
|
2
4
|
require_relative 'html_template'
|
|
3
5
|
|
|
4
6
|
module PathCoverage
|
|
5
7
|
# The HTML index page: one sortable row per covered file,
|
|
6
|
-
# each linking to that file's own page, then a Total row
|
|
8
|
+
# each linking to that file's own page, then a Total row; with
|
|
9
|
+
# groups, one such table per tab.
|
|
7
10
|
module HtmlIndex
|
|
8
|
-
# The whole index page
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
'
|
|
18
|
-
'
|
|
11
|
+
# The whole index page. rows are Summary.files rows and total
|
|
12
|
+
# their Summary.total. groups are [name, rows, total] for
|
|
13
|
+
# each group, each given a tab after All files; with none
|
|
14
|
+
# there is no tab bar, just the one table. Any operators
|
|
15
|
+
# ignored are named after the tables.
|
|
16
|
+
def self.page(rows, total, groups = [], ignored: [])
|
|
17
|
+
tables = [['All files', rows, total], *groups]
|
|
18
|
+
names = tables.map(&:first)
|
|
19
|
+
HtmlTemplate.page(
|
|
20
|
+
'index.html',
|
|
21
|
+
'script' => script(groups),
|
|
22
|
+
'tabs' => groups.empty? ? '' : HtmlTabs.bar(names),
|
|
23
|
+
'tables' => tables_of(tables),
|
|
24
|
+
'ignored' => ignored_line(ignored)
|
|
19
25
|
)
|
|
20
26
|
end
|
|
21
27
|
|
|
22
|
-
# The
|
|
23
|
-
# are
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
# The paragraph naming the operators ignored, eg
|
|
29
|
+
# "Ignored: &&="; empty when none are.
|
|
30
|
+
def self.ignored_line(ignored)
|
|
31
|
+
return '' if ignored.empty?
|
|
32
|
+
|
|
33
|
+
text = CGI.escapeHTML("Ignored: #{ignored.join(', ')}")
|
|
34
|
+
%(<p class="ignored" data-ignored="">#{text}</p>)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Each of tables, [name, rows, total], as the table of its
|
|
38
|
+
# tab.
|
|
39
|
+
def self.tables_of(tables)
|
|
40
|
+
tables.each_with_index.map do |(_, rows, total), index|
|
|
41
|
+
table(index, rows, total)
|
|
42
|
+
end.join("\n")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# The page's script: its column sorting, with groups its tab
|
|
46
|
+
# switching, then its settings and its theme button.
|
|
47
|
+
def self.script(groups)
|
|
48
|
+
names = ['sort.js', *('tabs.js' unless groups.empty?),
|
|
49
|
+
'settings.js', 'theme.js']
|
|
50
|
+
names.map { |name| HtmlTemplate.asset(name) }.join
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# The index-th tab's table of rows, total as its footer; any
|
|
54
|
+
# but the first starts hidden. Only the first, All files,
|
|
55
|
+
# gives its rows ids, as the others repeat its rows.
|
|
56
|
+
def self.table(index, rows, total)
|
|
57
|
+
anchored = index.zero?
|
|
58
|
+
body = rows.map { |row| row(row, anchored:) }.join("\n")
|
|
59
|
+
head = HtmlIndexHead.row
|
|
60
|
+
[
|
|
61
|
+
open_tag(index),
|
|
62
|
+
"<thead>\n#{head}\n</thead>",
|
|
63
|
+
"<tbody>\n#{body}\n</tbody>",
|
|
64
|
+
"<tfoot>\n#{total_row(total)}\n</tfoot>",
|
|
65
|
+
'</table>'
|
|
66
|
+
].join("\n")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# The opening tag of the index-th tab's table, which the tab
|
|
70
|
+
# of the same index controls; any but the first is hidden.
|
|
71
|
+
def self.open_tag(index)
|
|
72
|
+
hidden = index.zero? ? '' : ' hidden="hidden"'
|
|
73
|
+
id = %(id="files-#{index}")
|
|
74
|
+
%(<table class="files" #{id} role="tabpanel"#{hidden}>)
|
|
75
|
+
end
|
|
27
76
|
|
|
28
77
|
# The table row of one Summary.files row; each cell has a
|
|
29
|
-
# data-sort value for the page's column sorting.
|
|
30
|
-
|
|
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)
|
|
31
81
|
path = CGI.escapeHTML(row[:path])
|
|
32
82
|
link = %(<a href="files/#{path}.html">#{path}</a>)
|
|
33
|
-
"
|
|
83
|
+
id = anchored ? %( id="row-#{path}") : ''
|
|
84
|
+
"<tr#{id}>#{cell(path, link)}#{counts(row).join}</tr>"
|
|
34
85
|
end
|
|
35
86
|
|
|
36
|
-
# The footer row: the sums over
|
|
87
|
+
# The footer row: the sums over the table's files.
|
|
37
88
|
def self.total_row(total)
|
|
38
89
|
"<tr>#{cell('Total', 'Total')}#{counts(total).join}</tr>"
|
|
39
90
|
end
|
|
40
91
|
|
|
41
92
|
# The cells after the file's: its sites, then its total
|
|
42
|
-
# within each
|
|
43
|
-
# total across a method's decisions.
|
|
93
|
+
# within each method.
|
|
44
94
|
def self.counts(row)
|
|
45
|
-
|
|
46
|
-
cell(row[:sites], row[:sites]),
|
|
47
|
-
paths_cell(row[:decisions])
|
|
48
|
-
]
|
|
49
|
-
row[:methods] ? cells + [paths_cell(row[:methods])] : cells
|
|
95
|
+
[cell(row[:sites], row[:sites]), *paths_cells(row[:methods])]
|
|
50
96
|
end
|
|
51
97
|
|
|
52
|
-
#
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
|
|
98
|
+
# Why a total of no paths shows no percent.
|
|
99
|
+
NONE = 'no method with two or more decisions'.freeze
|
|
100
|
+
|
|
101
|
+
# Three cells showing [taken, possible] paths, eg 3, / 6 and
|
|
102
|
+
# 50%, each sorted by its number, so they read 3 / 6 50%.
|
|
103
|
+
# With no paths to take, as in a group no file is in, or a
|
|
104
|
+
# file with no method of two or more decisions, the percent
|
|
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)
|
|
58
109
|
taken, possible = pair
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
110
|
+
counts = [cell(taken, taken, css: 'taken'),
|
|
111
|
+
cell(possible, "/ #{possible}", css: 'of')]
|
|
112
|
+
none = cell('', '-', NONE, css: 'percent')
|
|
113
|
+
return [*counts, none] if possible.zero?
|
|
62
114
|
|
|
63
115
|
percent = (100.0 * taken / possible).round
|
|
64
|
-
cell(percent, "#{
|
|
116
|
+
[*counts, cell(percent, "#{percent}%", css: 'percent')]
|
|
65
117
|
end
|
|
66
118
|
|
|
67
119
|
# One table cell, sorted by sort_value, showing content,
|
|
68
|
-
# with title as its hover text
|
|
69
|
-
|
|
120
|
+
# with title as its hover text and css as its class, each
|
|
121
|
+
# when there is one.
|
|
122
|
+
def self.cell(sort_value, content, title = nil, css: nil)
|
|
70
123
|
hover = title ? %( title="#{title}") : ''
|
|
71
|
-
%(
|
|
124
|
+
klass = css ? %( class="#{css}") : ''
|
|
125
|
+
%(<td#{klass} data-sort="#{sort_value}"#{hover}>#{content}</td>)
|
|
72
126
|
end
|
|
73
127
|
end
|
|
74
128
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module PathCoverage
|
|
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
|
+
module HtmlIndexHead
|
|
6
|
+
# The class and label of each of a total's three columns.
|
|
7
|
+
PARTS = [%w[taken taken], ['of', '/ of'], %w[percent %]].freeze
|
|
8
|
+
|
|
9
|
+
# The heading row.
|
|
10
|
+
def self.row
|
|
11
|
+
fixed = [
|
|
12
|
+
heading('', 0, 'text', 'File'),
|
|
13
|
+
heading(' class="num"', 1, 'number', 'Sites')
|
|
14
|
+
]
|
|
15
|
+
parts = PARTS.each_with_index.map do |(css, label), i|
|
|
16
|
+
heading(%( class="#{css}"), 2 + i, 'number', label)
|
|
17
|
+
end
|
|
18
|
+
"<tr>\n#{(fixed + parts).join("\n")}\n</tr>"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# A sortable heading, attrs its th's, sorting the column-th
|
|
22
|
+
# column as type, its button showing label.
|
|
23
|
+
def self.heading(attrs, column, type, label)
|
|
24
|
+
data = %(data-column="#{column}" data-type="#{type}")
|
|
25
|
+
button = %(<button type="button" #{data}>#{label}</button>)
|
|
26
|
+
%(<th#{attrs} aria-sort="none">#{button}</th>)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|