| 1 | | import Foundation |
| 2 | | |
| 3 | | /// Coverage cards and every module, each folding out its files. |
| 4 | | public struct IndexPage: Sendable { |
| 5 | | public static let sitePath = "index.html" |
| 6 | | private let title: String |
| 7 | | private let modules: [ModuleTotals] |
| 8 | | private let tests: TestRun? |
| 9 | | private let run: ReportHeader |
| 10 | | private let comparison: BaselineComparison? |
| 11 | | private let hasRegions: Bool |
| 12 | | private let hasBranches: Bool |
| 13 | | private let trend: CoverageTrend |
| 14 | | private let hasConditions: Bool |
| 15 | | |
| 16 | | /// - Parameters: |
| 17 | | /// - title: the site's name, shown as given in the page's title and heading. |
| 18 | | /// - tests: results add the Tests tab; counts alone do not create a page. |
| 19 | | /// - commit: the commit the report was built from, shortened in the header. |
| 20 | | /// - subject: the commit's first message line. |
| 21 | | /// - historyPath: the History destination relative to the report root, if available. |
| 22 | | /// - trend: the line series shown in the coverage card. |
| 23 | | /// - baseline: an earlier run to compare with; with it, the table gets a change |
| 24 | | /// column. |
| 25 | | public init( |
| 26 | | title: String, files: [FileTotals], tests: TestRun?, commit: String?, |
| 27 | | baseline: RunTotals? = nil, subject: String? = nil, historyPath: String? = nil, |
| 28 | | trend: CoverageTrend = CoverageTrend(runs: []) |
| 29 | 81 | ) { |
| 30 | 81 | self.trend = trend |
| 31 | 81 | self.comparison = baseline.map(BaselineComparison.init) |
| 32 | 81 | self.title = title |
| 33 | 81 | self.modules = ModuleTotals.grouping(files) |
| 34 | 169 | self.hasRegions = files.contains { $0.regions != nil } |
| 35 | 172 | self.hasBranches = files.contains { $0.branches != nil } |
| 36 | 174 | self.hasConditions = files.contains { $0.conditions != nil } |
| 37 | 81 | self.tests = tests |
| 38 | 81 | self.run = ReportHeader(commit: commit, subject: subject, historyPath: historyPath) |
| 39 | 81 | } |
| 40 | | |
| 41 | 81 | public var html: String { |
| 42 | 81 | """ |
| 43 | 81 | <!doctype html> |
| 44 | 81 | <html lang="en"> |
| 45 | 81 | <head> |
| 46 | 81 | <meta charset="utf-8"> |
| 47 | 81 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 48 | 81 | <title>\(escapingHTML(title))</title> |
| 49 | 81 | <link rel="stylesheet" href="\(SiteStylesheet.fileName)"> |
| 50 | 81 | </head> |
| 51 | 81 | <body class="\(bodyClasses)"> |
| 52 | 81 | <header class="page-header"> |
| 53 | 81 | \(SiteHeader(title: title, currentTab: .coverage, hasTestsPage: hasTestsPage, rootPath: "", run: run).html) |
| 54 | 81 | </header> |
| 55 | 81 | <main> |
| 56 | 81 | \(cardsMarkup) |
| 57 | 81 | <p class="legend"><span class="key high"></span>90% and up \ |
| 58 | 81 | <span class="key medium"></span>75% and up <span class="key low"></span>below 75%</p> |
| 59 | 81 | <div class="toolbar" data-needs-script hidden> |
| 60 | 81 | <input id="filter" type="search" placeholder="Filter files" aria-label="Filter files">\(compactToggle) |
| 61 | 81 | </div> |
| 62 | 81 | <div class="row columns" data-needs-script hidden>\ |
| 63 | 81 | <button type="button" data-sort="name" data-first="ascending">File</button>\(barHeading)\ |
| 64 | 81 | <button type="button" data-sort="percent" data-first="ascending">Lines</button>\ |
| 65 | 81 | <button type="button" data-sort="missed" data-first="descending">Missed</button>\ |
| 66 | 81 | \(comparison == nil ? "" : Self.sortButton("change", title: "Change", cell: "change"))\ |
| 67 | 81 | \(regionHeadings)\ |
| 68 | 81 | \(hasBranches ? #"<span class="branches">Branches</span>"# : "")\ |
| 69 | 81 | \(hasConditions ? #"<span class="conditions">Conditions</span>"# : "")</div> |
| 70 | 81 | <div class="modules"> |
| 71 | 204 | \(modules.map(moduleMarkup).joined(separator: "\n")) |
| 72 | 81 | </div> |
| 73 | 81 | </main> |
| 74 | 81 | <script>\(Self.sortAndFilterScript)</script> |
| 75 | 81 | </body> |
| 76 | 81 | </html> |
| 77 | 81 | |
| 78 | 81 | """ |
| 79 | 81 | } |
| 80 | | |
| 81 | | /// Whether rows have more to sum up than their lines. |
| 82 | 675 | private var hasOtherMetrics: Bool { hasRegions || hasBranches || hasConditions } |
| 83 | | |
| 84 | 81 | private var barHeading: String { |
| 85 | 81 | hasOtherMetrics |
| 86 | 81 | ? Self.sortButton("overall", title: "Overall", cell: "bar") |
| 87 | 81 | : #"<span class="bar"></span>"# |
| 88 | 81 | } |
| 89 | | |
| 90 | | /// Switches the table to one column per metric. Lines alone already have just one. |
| 91 | 81 | private var compactToggle: String { |
| 92 | 81 | guard hasRegions else { return "" } |
| 93 | 28 | return "\n" |
| 94 | 28 | + #"<label class="compact-toggle"><input id="compact" type="checkbox"> Compact</label>"# |
| 95 | 81 | } |
| 96 | | |
| 97 | 81 | private var regionHeadings: String { |
| 98 | 81 | guard hasRegions else { return "" } |
| 99 | 28 | let change = |
| 100 | 28 | comparison == nil |
| 101 | 28 | ? "" : Self.sortButton("regionChange", title: "Change", cell: "regions-change") |
| 102 | 28 | return Self.sortButton("regionPercent", title: "Regions", cell: "regions") |
| 103 | 28 | + #"<button type="button" class="regions-missed" data-sort="regionMissed" data-first="descending">Missed</button>"# |
| 104 | 28 | + change |
| 105 | 81 | } |
| 106 | | |
| 107 | | /// A heading that sorts by a share or change, the worst rows first. |
| 108 | 87 | private static func sortButton(_ key: String, title: String, cell: String) -> String { |
| 109 | 87 | #"<button type="button" class="\#(cell)" data-sort="\#(key)" data-first="ascending">\#(title)</button>"# |
| 110 | 87 | } |
| 111 | | |
| 112 | | /// The classes the stylesheet keys its extra columns on. |
| 113 | 81 | private var bodyClasses: String { |
| 114 | 81 | var classes = ["index-page"] |
| 115 | 81 | if comparison != nil { classes.append("has-baseline") } |
| 116 | 81 | if hasRegions { classes.append("has-regions") } |
| 117 | 81 | if hasBranches { classes.append("has-branches") } |
| 118 | 81 | if hasConditions { classes.append("has-conditions") } |
| 119 | 81 | return classes.joined(separator: " ") |
| 120 | 81 | } |
| 121 | | |
| 122 | 81 | private var hasTestsPage: Bool { |
| 123 | 81 | if case .results = tests { true } else { false } |
| 124 | 81 | } |
| 125 | | |
| 126 | | /// Lines alone fill one row of cards. With regions, the two coverage cards share |
| 127 | | /// the first row and their missed counts the second, so neither metric leads. |
| 128 | 81 | private var cardsMarkup: String { |
| 129 | 123 | let total = LineSummary(adding: modules.map(\.lines)) |
| 130 | 123 | let files = modules.flatMap(\.files) |
| 131 | 81 | let lineCard = lineCard(total) |
| 132 | 81 | let missedLines = Self.card( |
| 133 | 81 | title: "Missed lines", value: groupingDigits(total.count - total.covered), |
| 134 | 81 | detail: comparison.map { Self.missedChangeSpan($0.missedLineChange(now: total)) } ?? "") |
| 135 | 81 | let newFiles = comparison.map { "\($0.newFileCount(in: files)) new since baseline" } ?? "" |
| 136 | 81 | let fileCard = Self.card( |
| 137 | 81 | title: "Files", value: groupingDigits(files.count), detail: newFiles) |
| 138 | 81 | let rows = |
| 139 | 174 | if let regions = CoverageCount(addingPresent: files.map(\.regions)) { |
| 140 | 28 | Self.cardRow( |
| 141 | 28 | [lineCard, regionCard(regions)], classes: "cards pair", |
| 142 | 28 | label: "Coverage summary") |
| 143 | 28 | + Self.cardRow( |
| 144 | 28 | [missedLines, missedRegionCard(regions), fileCard], classes: "cards counts", |
| 145 | 28 | label: "Coverage counts") |
| 146 | 53 | } else { |
| 147 | 53 | Self.cardRow( |
| 148 | 53 | [lineCard, missedLines, fileCard], classes: "cards", label: "Coverage summary") |
| 149 | 53 | } |
| 150 | 81 | return rows + otherMetricCards(files) |
| 151 | 81 | } |
| 152 | | |
| 153 | 81 | private func lineCard(_ total: LineSummary) -> String { |
| 154 | 81 | let change = |
| 155 | 81 | comparison.map { Self.changeSpan($0.changeOfTotal(now: total)) + " since baseline · " } |
| 156 | 81 | ?? "" |
| 157 | 81 | return Self.card( |
| 158 | 81 | title: "Line coverage", value: total.percentText, |
| 159 | 81 | detail: change |
| 160 | 81 | + "\(groupingDigits(total.covered)) of \(groupingDigits(total.count)) lines" |
| 161 | 81 | + trend.sparkline) |
| 162 | 81 | } |
| 163 | | |
| 164 | 28 | private func regionCard(_ regions: CoverageCount) -> String { |
| 165 | 28 | Self.card( |
| 166 | 28 | title: "Region coverage", value: regions.percentText, |
| 167 | 28 | detail: metricDetail( |
| 168 | 28 | regions, noun: "regions", change: comparison?.regionChange(now: regions)) |
| 169 | 28 | + trend.regionSparkline) |
| 170 | 28 | } |
| 171 | | |
| 172 | 28 | private func missedRegionCard(_ regions: CoverageCount) -> String { |
| 173 | 28 | let detail = |
| 174 | 28 | comparison.map { baseline in |
| 175 | 10 | baseline.missedRegionChange(now: regions).map(Self.missedChangeSpan) |
| 176 | 10 | ?? Self.changeSpan(.new) + " since baseline" |
| 177 | 18 | } ?? "" |
| 178 | 28 | return Self.card( |
| 179 | 28 | title: "Missed regions", value: groupingDigits(regions.total - regions.covered), |
| 180 | 28 | detail: detail) |
| 181 | 28 | } |
| 182 | | |
| 183 | | /// Fewer missed is the improvement, so a fall is styled as `up`. |
| 184 | 23 | private static func missedChangeSpan(_ difference: Int) -> String { |
| 185 | 23 | let style = difference < 0 ? "up" : difference > 0 ? "down" : "flat" |
| 186 | 23 | let sign = difference > 0 ? "+" : "" |
| 187 | 23 | return |
| 188 | 23 | #"<span class="change \#(style)">\#(sign)\#(groupingDigits(difference)) since baseline</span>"# |
| 189 | 23 | } |
| 190 | | |
| 191 | | /// Branch and condition cards, for the exports that count them. |
| 192 | 81 | private func otherMetricCards(_ files: [FileTotals]) -> String { |
| 193 | 81 | var cards = [String]() |
| 194 | 174 | if let branches = CoverageCount(addingPresent: files.map(\.branches)) { |
| 195 | 5 | cards.append( |
| 196 | 5 | Self.card( |
| 197 | 5 | title: "Branch coverage", value: branches.percentText, |
| 198 | 5 | detail: metricDetail( |
| 199 | 5 | branches, noun: "outcomes", change: comparison?.branchChange(now: branches)) |
| 200 | 5 | )) |
| 201 | 5 | } |
| 202 | 174 | if let conditions = CoverageCount(addingPresent: files.map(\.conditions)) { |
| 203 | 3 | cards.append( |
| 204 | 3 | Self.card( |
| 205 | 3 | title: "Condition coverage", value: conditions.percentText, |
| 206 | 3 | detail: metricDetail( |
| 207 | 3 | conditions, noun: "conditions", |
| 208 | 3 | change: comparison?.conditionChange(now: conditions)))) |
| 209 | 3 | } |
| 210 | 81 | return cards.isEmpty |
| 211 | 81 | ? "" : Self.cardRow(cards, classes: "cards secondary", label: "Additional coverage") |
| 212 | 81 | } |
| 213 | | |
| 214 | 114 | private static func cardRow(_ cards: [String], classes: String, label: String) -> String { |
| 215 | 114 | #"<section class="\#(classes)" aria-label="\#(label)">"# + cards.joined() + "</section>" |
| 216 | 114 | } |
| 217 | | |
| 218 | 307 | private static func card(title: String, value: String, detail: String) -> String { |
| 219 | 307 | #"<article class="card"><h2>\#(title)</h2><p class="value">\#(value)</p><p class="detail">\#(detail)</p></article>"# |
| 220 | 307 | } |
| 221 | | |
| 222 | | private func metricDetail( |
| 223 | | _ count: CoverageCount, noun: String, change: CoverageChange? |
| 224 | 36 | ) -> String { |
| 225 | 36 | let delta = change.map { Self.changeSpan($0) + " since baseline · " } ?? "" |
| 226 | 36 | return delta + "\(groupingDigits(count.covered)) of \(groupingDigits(count.total)) \(noun)" |
| 227 | 36 | } |
| 228 | | |
| 229 | | /// Shows the controls, sorts modules and the files inside each by the clicked column |
| 230 | | /// (a second click reverses it), and filters files by path, opening the modules |
| 231 | | /// that still have matches. Without scripts the modules still fold out by hand. |
| 232 | | private static let sortAndFilterScript = """ |
| 233 | | (() => { |
| 234 | | const list = document.querySelector(".modules"); |
| 235 | | const modules = [...list.querySelectorAll("details.module")]; |
| 236 | | const buttons = [...document.querySelectorAll("button[data-sort]")]; |
| 237 | | const filter = document.getElementById("filter"); |
| 238 | | document.querySelectorAll("[data-needs-script]").forEach(element => element.hidden = false); |
| 239 | | let key = "name"; |
| 240 | | let ascending = true; |
| 241 | | const value = row => key === "name" ? row.dataset.name.toLowerCase() : parseFloat(row.dataset[key]); |
| 242 | | const order = (a, b) => { |
| 243 | | const [x, y] = [value(a), value(b)]; |
| 244 | | // Rows without the value go last, whichever way the rest are sorted. |
| 245 | | if (Number.isNaN(x) || Number.isNaN(y)) return Number.isNaN(x) - Number.isNaN(y); |
| 246 | | return (x < y ? -1 : x > y ? 1 : 0) * (ascending ? 1 : -1); |
| 247 | | }; |
| 248 | | const sort = () => { |
| 249 | | for (const module of modules.sort(order)) { |
| 250 | | module.append(...[...module.querySelectorAll("a.file")].sort(order)); |
| 251 | | list.append(module); |
| 252 | | } |
| 253 | | for (const button of buttons) { |
| 254 | | button.dataset.direction = button.dataset.sort === key ? (ascending ? "ascending" : "descending") : ""; |
| 255 | | } |
| 256 | | }; |
| 257 | | for (const button of buttons) { |
| 258 | | button.addEventListener("click", () => { |
| 259 | | ascending = button.dataset.sort === key ? !ascending : button.dataset.first === "ascending"; |
| 260 | | key = button.dataset.sort; |
| 261 | | sort(); |
| 262 | | }); |
| 263 | | } |
| 264 | | filter.addEventListener("input", () => { |
| 265 | | const query = filter.value.trim().toLowerCase(); |
| 266 | | for (const module of modules) { |
| 267 | | let hasMatch = false; |
| 268 | | for (const file of module.querySelectorAll("a.file")) { |
| 269 | | const path = (module.dataset.name + "/" + file.dataset.name).toLowerCase(); |
| 270 | | file.hidden = query !== "" && !path.includes(query); |
| 271 | | hasMatch = hasMatch || !file.hidden; |
| 272 | | } |
| 273 | | module.hidden = !hasMatch; |
| 274 | | module.open = query !== "" && hasMatch; |
| 275 | | } |
| 276 | | }); |
| 277 | | const compact = document.getElementById("compact"); |
| 278 | | if (compact) { |
| 279 | | const storageKey = "covane.compact"; |
| 280 | | // Browsers may refuse storage; the view then just starts out normal. |
| 281 | | try { compact.checked = localStorage.getItem(storageKey) === "true"; } catch {} |
| 282 | | const shareColumns = { missed: "percent", change: "percent", regionMissed: "regionPercent", regionChange: "regionPercent" }; |
| 283 | | const apply = () => { |
| 284 | | document.body.classList.toggle("compact", compact.checked); |
| 285 | | // Never leave the rows ordered by a column the compact view hides. |
| 286 | | if (compact.checked && key in shareColumns) { |
| 287 | | key = shareColumns[key]; |
| 288 | | ascending = true; |
| 289 | | } |
| 290 | | sort(); |
| 291 | | }; |
| 292 | | compact.addEventListener("change", () => { |
| 293 | | try { localStorage.setItem(storageKey, compact.checked); } catch {} |
| 294 | | apply(); |
| 295 | | }); |
| 296 | | apply(); |
| 297 | | } else { |
| 298 | | sort(); |
| 299 | | } |
| 300 | | })(); |
| 301 | | """ |
| 302 | | |
| 303 | | /// A `<details>` per module, so its files fold out without any script. |
| 304 | 123 | private func moduleMarkup(_ module: ModuleTotals) -> String { |
| 305 | 174 | let files = module.files.map { file in |
| 306 | 174 | let values = RowValues( |
| 307 | 174 | name: String(file.relativePath.dropFirst(module.name.count + 1)), |
| 308 | 174 | lines: file.lines, |
| 309 | 174 | change: comparison?.change(ofFile: file.relativePath, now: file.lines), |
| 310 | 174 | regions: file.regions, |
| 311 | 174 | regionChange: file.regions.flatMap { now in |
| 312 | 30 | comparison?.regionChange(ofFile: file.relativePath, now: now) |
| 313 | 30 | }, |
| 314 | 174 | branches: file.branches, conditions: file.conditions) |
| 315 | 174 | return |
| 316 | 174 | #"<a class="row file" href="\#(escapingHTML(SourcePage.sitePath(for: file.relativePath)))""# |
| 317 | 174 | + "\(sortKeys(values))>\(cells(values))</a>" |
| 318 | 174 | } |
| 319 | 123 | let values = RowValues( |
| 320 | 123 | name: module.name, lines: module.lines, |
| 321 | 123 | change: comparison?.change(ofModule: module.name, now: module.lines), |
| 322 | 123 | regions: module.regions, |
| 323 | 123 | regionChange: module.regions.flatMap { now in |
| 324 | 28 | comparison?.regionChange(ofModule: module.name, now: now) |
| 325 | 28 | }, |
| 326 | 123 | branches: module.branches, conditions: module.conditions) |
| 327 | 123 | return """ |
| 328 | 123 | <details class="module"\(sortKeys(values))> |
| 329 | 123 | <summary class="row">\(cells(values))</summary> |
| 330 | 123 | \(files.joined(separator: "\n")) |
| 331 | 123 | </details> |
| 332 | 123 | """ |
| 333 | 123 | } |
| 334 | | |
| 335 | | /// The values the index's sort script orders rows by, unformatted, so it compares |
| 336 | | /// numbers rather than the text shown. A value a row lacks, or a change from |
| 337 | | /// nothing, has no key. |
| 338 | 297 | private func sortKeys(_ row: RowValues) -> String { |
| 339 | 297 | var keys = |
| 340 | 297 | #" data-name="\#(escapingHTML(row.name))""# |
| 341 | 297 | + #" data-percent="\#(Self.sortNumber(row.lines.percent))""# |
| 342 | 297 | + #" data-missed="\#(row.lines.count - row.lines.covered)" data-lines="\#(row.lines.count)""# |
| 343 | 297 | if case .points(let points) = row.change { |
| 344 | 34 | keys += #" data-change="\#(Self.sortNumber(points))""# |
| 345 | 34 | } |
| 346 | 297 | if let regions = row.regions { |
| 347 | 58 | let share = LineSummary(count: regions.total, covered: regions.covered) |
| 348 | 58 | keys += |
| 349 | 58 | #" data-region-percent="\#(Self.sortNumber(share.percent))""# |
| 350 | 58 | + #" data-region-missed="\#(regions.total - regions.covered)""# |
| 351 | 58 | } |
| 352 | 297 | if case .points(let points) = row.regionChange { |
| 353 | 12 | keys += #" data-region-change="\#(Self.sortNumber(points))""# |
| 354 | 12 | } |
| 355 | 297 | if let overall = overall(of: row) { |
| 356 | 71 | keys += #" data-overall="\#(Self.sortNumber(overall.percent))""# |
| 357 | 71 | } |
| 358 | 297 | return keys |
| 359 | 297 | } |
| 360 | | |
| 361 | 472 | private static func sortNumber(_ value: Double) -> String { |
| 362 | 472 | String(format: "%.2f", value) |
| 363 | 472 | } |
| 364 | | |
| 365 | 110 | private static func changeSpan(_ change: CoverageChange) -> String { |
| 366 | 110 | #"<span class="change \#(change.styleName)">\#(change.text)</span>"# |
| 367 | 110 | } |
| 368 | | |
| 369 | | /// What one module's or file's row shows. The changes are nil without a baseline. |
| 370 | | private struct RowValues { |
| 371 | | let name: String |
| 372 | | let lines: LineSummary |
| 373 | | let change: CoverageChange? |
| 374 | | let regions: CoverageCount? |
| 375 | | let regionChange: CoverageChange? |
| 376 | | let branches: CoverageCount? |
| 377 | | let conditions: CoverageCount? |
| 378 | | } |
| 379 | | |
| 380 | 297 | private func cells(_ row: RowValues) -> String { |
| 381 | 297 | let tier = row.lines.tier.rawValue |
| 382 | 297 | let changeCell = row.change.map(Self.changeSpan) ?? "" |
| 383 | 297 | let branchCell = hasBranches ? Self.countCell(row.branches, className: "branches") : "" |
| 384 | 297 | let conditionCell = |
| 385 | 297 | hasConditions ? Self.countCell(row.conditions, className: "conditions") : "" |
| 386 | 297 | return #"<span class="name">\#(escapingHTML(row.name))</span>"# |
| 387 | 297 | + barMarkup(row) |
| 388 | 297 | + #"<span class="percent \#(tier)">\#(row.lines.percentText)</span>"# |
| 389 | 297 | + #"<span class="missed">\#(groupingDigits(row.lines.count - row.lines.covered))</span>"# |
| 390 | 297 | + changeCell |
| 391 | 297 | + (hasRegions ? regionCells(row) : "") |
| 392 | 297 | + branchCell + conditionCell |
| 393 | 297 | } |
| 394 | | |
| 395 | | /// The row summed up across its metrics; nil on a page of lines alone, whose bar |
| 396 | | /// needs no summing up. |
| 397 | 594 | private func overall(of row: RowValues) -> OverallCoverage? { |
| 398 | 594 | guard hasOtherMetrics else { return nil } |
| 399 | 142 | return OverallCoverage( |
| 400 | 142 | lines: row.lines, regions: row.regions, branches: row.branches, |
| 401 | 142 | conditions: row.conditions) |
| 402 | 594 | } |
| 403 | | |
| 404 | 297 | private func barMarkup(_ row: RowValues) -> String { |
| 405 | 297 | let overall = overall(of: row) |
| 406 | 297 | let tier = overall?.tier ?? row.lines.tier |
| 407 | 297 | let width = overall?.percentText ?? row.lines.percentText |
| 408 | 297 | let tooltip = overall.map { #" title="\#($0.breakdown)""# } ?? "" |
| 409 | 297 | return |
| 410 | 297 | #"<span class="bar"\#(tooltip)><span class="fill \#(tier.rawValue)" style="width: \#(width)"></span></span>"# |
| 411 | 297 | } |
| 412 | | |
| 413 | | /// Share, missed and, with a baseline, change, as for lines; dashes where this row |
| 414 | | /// has no region data while others do. |
| 415 | 61 | private func regionCells(_ row: RowValues) -> String { |
| 416 | 61 | let share = |
| 417 | 61 | row.regions.map { regions in |
| 418 | 58 | #"<span class="percent \#(regions.tier.rawValue)">\#(regions.percentText)</span>"# |
| 419 | 58 | } ?? "–" |
| 420 | 61 | let missed = row.regions.map { groupingDigits($0.total - $0.covered) } ?? "–" |
| 421 | 61 | let change = |
| 422 | 61 | comparison == nil |
| 423 | 61 | ? "" |
| 424 | 61 | : #"<span class="regions-change">\#(row.regionChange.map(Self.changeSpan) ?? "–")</span>"# |
| 425 | 61 | return #"<span class="regions">\#(share)</span>"# |
| 426 | 61 | + #"<span class="regions-missed">\#(missed)</span>"# + change |
| 427 | 61 | } |
| 428 | | |
| 429 | | /// The share in its tier colour and the counts it comes from; a dash where this |
| 430 | | /// file or module has no data while others do. |
| 431 | 18 | private static func countCell(_ count: CoverageCount?, className: String) -> String { |
| 432 | 18 | guard let count else { return #"<span class="\#(className)">–</span>"# } |
| 433 | 17 | return #"<span class="\#(className)"><span class="percent \#(count.tier.rawValue)">"# |
| 434 | 17 | + "\(count.percentText)</span> \(groupingDigits(count.covered))/" |
| 435 | 17 | + "\(groupingDigits(count.total))</span>" |
| 436 | 18 | } |
| 437 | | } |