-
Notifications
You must be signed in to change notification settings - Fork 115
/
testable-assertions.js
50 lines (46 loc) · 2.17 KB
/
testable-assertions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function markTestableAssertions() {
const sectionsToIgnore=["#abstract", "#sotd", "#conformance", ".informative", ".appendix"];
const contentToIgnore = [".untestable", ".issue", ".example", ".note", ".informative", ".has-tests", ".needs-tests", ".no-test-needed"];
const contentToIgnoreSelector = contentToIgnore.map(sel => `:not(${sel})`).join('');
[...document.querySelector("body").querySelectorAll(sectionsToIgnore.map(sel => `section:not(${sel})`).join(","))].forEach(
section => {
[...section.querySelectorAll(`p${contentToIgnoreSelector}, ol > li${contentToIgnoreSelector}`)].forEach(
el => {
let parent = el.parentNode;
do {
if (parent.matches(contentToIgnore.join(','))) return;
parent = parent.parentNode;
} while (parent.tagName !== 'SECTION' && parent.matches);
if (el.tagName === "P" && (el.textContent.match(/MUST/) || el.textContent.match(/SHALL/))) {
if (!((el.parentNode.tagName === "DD" && el.parentNode.previousElementSibling.getAttribute("data-tests") && !el.nextElementSibling) || (el.nextElementSibling && el.nextElementSibling.tagName === "OL"))) {
el.classList.add("needs-tests");
}
} else if (el.tagName === "LI" && !el.querySelector('ol')) { // Detect argument assignment cases?
el.classList.add("needs-tests");
}
})
}
);
}
function highlightTests() {
[...document.querySelectorAll("[data-tests]")].forEach(el => {
if (el.dataset['tests'])
el.classList.add("has-tests")
else
el.classList.add("needs-tests");
});
}
function showTestAnnotations() {
if (location.search.match(/viewTests/)) {
toggleTestAnnotations();
}
}
function toggleTestAnnotations() {
if (!document.querySelector("[data-navigable-selector]")) {
const navigationScript = document.createElement("script");
navigationScript.setAttribute("data-navigable-selector", ".needs-tests");
navigationScript.setAttribute("src", "https://w3c.github.io/htmldiff-nav/index.js");
document.querySelector("head").appendChild(navigationScript);
}
document.querySelector("body").classList.toggle("testcoverage");
}