Skip to content

Commit fafaeea

Browse files
amroamroamromikesamuel
authored andcommitted
modules_tests: comments + minor edits
1 parent 72fb21c commit fafaeea

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

tests/extractSourceSpans_test.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,40 @@ <h1>Extract Source Spans Test</h1>
6060
var testInputs = Array.prototype.slice.call(
6161
document.getElementsByClassName('testinput'), 0);
6262
for (var i = 0, n = testInputs.length; i < n; ++i) {
63+
// td.input > .testinput
6364
var testInput = testInputs[i];
65+
// td.golden
6466
var testResult = testInput.parentNode.nextSibling;
6567
while (testResult.nodeType !== 1) { testResult = testResult.nextSibling; }
68+
// td.actual
6669
var actual = document.createElement('TD');
6770
actual.className = 'actual';
6871
testResult.parentNode.appendChild(actual);
6972
try {
73+
// run function
7074
var isPreformatted = /pre|xmp/i.test(testInput.tagName);
7175
var sourceAndSpans = extractSourceSpans(testInput, isPreformatted);
76+
// build result
7277
var source = sourceAndSpans.sourceCode;
7378
var spans = sourceAndSpans.spans;
7479
var actualText = '^';
7580
var actualHtml = '';
7681
for (var j = 0, m = spans.length; j < m; j += 2) {
82+
// extract span text
7783
var start = spans[j], end = spans[j + 2] || source.length;
7884
var span = source.substring(start, end);
7985
actualText += span + '^';
86+
// determine span class name
8087
var spanClass = ((j & 2) ? 'odd' : 'even');
8188
if (spans[j + 1].nodeName === 'BR') {
8289
spanClass += ' break';
8390
}
91+
// html formatted
8492
actualHtml += '<span class="' + spanClass+ '">' +
8593
span.replace(/&/g, '&amp;').replace(/</g, '&lt;') + '<\/span>';
8694
}
8795
actual.innerHTML = '<pre>' + actualHtml + '<\/pre>';
96+
// compare result against expected
8897
var goldenText = testResult.innerText || testResult.textContent;
8998
var goldenNormalized = '"' + goldenText.replace(/(?:\r\n?|\n)$/, '') + '"';
9099
var actualNormalized = stringify(actualText);

tests/numberLines_test.html

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,31 @@ <h1>Number Lines Test</h1>
6565
var testInputs = Array.prototype.slice.call(
6666
document.getElementsByClassName('testinput'), 0);
6767
for (var i = 0, n = testInputs.length; i < n; ++i) {
68+
// td.input > .testinput
6869
var testInput = testInputs[i];
70+
// td.golden
6971
var testResult = testInput.parentNode.nextSibling;
7072
while (testResult.nodeType !== 1) { testResult = testResult.nextSibling; }
73+
// td.actual
7174
var actual = document.createElement('TD');
7275
testResult.parentNode.appendChild(actual);
7376
try {
74-
var testInputClone = testInput.cloneNode(true);
75-
testInputClone.className = ''; // IE
76-
testInputClone.removeAttribute('class'); // Not IE.
77-
actual.appendChild(testInputClone);
77+
// make a copy of input node (modified in-place)
78+
var clone = testInput.cloneNode(true);
79+
clone.className = ''; // IE
80+
clone.removeAttribute('class'); // Not IE.
81+
actual.appendChild(clone);
82+
// run function
7883
var startLineNum = true;
79-
var isPreformatted = /pre|xmp/i.test(testInputClone.tagName);
80-
numberLines(testInputClone, startLineNum, isPreformatted);
81-
var goldenNorm = normListItems(testResult.innerHTML);
82-
var actualNorm = normListItems(actual.innerHTML);
83-
var passed = goldenNorm === actualNorm;
84+
var isPreformatted = /pre|xmp/i.test(clone.tagName);
85+
numberLines(clone, startLineNum, isPreformatted);
86+
// compare result again expected
87+
var goldenNormalized = normListItems(testResult.innerHTML);
88+
var actualNormalized = normListItems(actual.innerHTML);
89+
var passed = goldenNormalized === actualNormalized;
8490
if (!passed) {
85-
console.log(JSON.stringify(goldenNorm) + '\n!==\n' +
86-
JSON.stringify(actualNorm));
91+
console.log(JSON.stringify(goldenNormalized) + '\n!==\n' +
92+
JSON.stringify(actualNormalized));
8793
}
8894
actual.className = passed ? 'ok' : 'failure';
8995
} catch (ex) {

tests/recombineTagsAndDecorations_test.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,29 @@ <h1>Recombine Tags And Decorations Test</h1>
4040
var testInputs = Array.prototype.slice.call(
4141
document.getElementsByClassName('testinput'), 0);
4242
for (var i = 0, n = testInputs.length; i < n; ++i) {
43+
// td.input > .testinput
4344
var testInput = testInputs[i];
45+
// td.decorations (result of language handler function)
4446
var decorationsNode = testInput.parentNode.nextSibling;
4547
while (decorationsNode.nodeType !== 1) { decorationsNode = decorationsNode.nextSibling; }
48+
// td.golden
4649
var testResult = decorationsNode.nextSibling;
4750
while (testResult.nodeType !== 1) { testResult = testResult.nextSibling; }
51+
// td.actual
4852
var actual = document.createElement('TD');
4953
testResult.parentNode.appendChild(actual);
54+
// make a copy of input node (modified in-place)
5055
var clone = testInput.cloneNode(true);
5156
clone.className = ''; // IE
5257
clone.removeAttribute('class'); // Not IE.
5358
actual.appendChild(clone);
59+
// run function
5460
var isPreformatted = /pre|xmp/i.test(clone.tagName);
5561
var job = extractSourceSpans(clone, isPreformatted);
5662
job.decorations = eval(decorationsNode.innerText || decorationsNode.textContent);
5763
try {
5864
recombineTagsAndDecorations(job);
65+
// compare result against expected
5966
var passed = testResult.innerHTML === actual.innerHTML;
6067
if (!passed) {
6168
console.log(JSON.stringify(testResult.innerHTML) + '\n!==\n' +

0 commit comments

Comments
 (0)