| 1 |
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 2 |
<html> <head> |
| 3 |
<title>Number Lines Test</title> |
| 4 |
<script src="numberLines.js"></script> |
| 5 |
<script src="http://github.com/douglascrockford/JSON-js/raw/master/json2.js"></script> |
| 6 |
<style> |
| 7 |
.ok { background: #dfd } |
| 8 |
.error, .failure { background: #fdd } |
| 9 |
td { font-family: monospace } |
| 10 |
tr { vertical-align: top } |
| 11 |
</style> |
| 12 |
</head> |
| 13 |
|
| 14 |
<body> |
| 15 |
<h1>Number Lines Test</h1> |
| 16 |
|
| 17 |
<table> |
| 18 |
<tr><th colspan=3>Test Nothing to Split</th></tr> |
| 19 |
<tr> |
| 20 |
<td><code class="testinput">Hello, World!</code></td> |
| 21 |
<td><code><ol class="linenums"><li class="L0">Hello, World!</li></ol></code></td> |
| 22 |
</tr> |
| 23 |
<tr><th colspan=3>Test Normalized Spaces</th></tr> |
| 24 |
<tr> |
| 25 |
<td><code class="testinput">Hello, World!</code></td> |
| 26 |
<td><code><ol class="linenums"><li class="L0">Hello, World!</li></ol></code></td> |
| 27 |
</tr> |
| 28 |
<tr><th colspan=3>Test BR</th></tr> |
| 29 |
<tr> |
| 30 |
<td><pre class="testinput">Hello,<br>World!</pre></td> |
| 31 |
<td><pre><ol class="linenums"><li class="L0">Hello,</li><li class="L1">World!</li></ol></pre></td> |
| 32 |
</tr> |
| 33 |
<tr><th colspan=3>Test line breaks</th></tr> |
| 34 |
<tr> |
| 35 |
<td><pre class="testinput">Hello, there World!</pre></td> |
| 36 |
<td><pre><ol class="linenums"><li class="L0">Hello,</li><li class="L1">there</li><li class="L2">World!</li></ol></pre></td> |
| 37 |
</tr> |
| 38 |
<tr><th colspan=3>Test line breaks with followers</th></tr> |
| 39 |
<tr> |
| 40 |
<td><pre class="testinput"><b>Hello, there World! </b><button>OK</button></pre></td> |
| 41 |
<td><pre><ol class="linenums"><li class="L0"><b>Hello,</b></li><li class="L1"><b>there</b></li><li class="L2"><b>World!</b></li><li class="L3"><button>OK</button></ol></pre></td> |
| 42 |
</tr> |
| 43 |
<tr><th colspan=3>Test nocode</th></tr> |
| 44 |
<tr> |
| 45 |
<td><pre class="testinput">Hello, the<span class="nocode">re World!</span></pre></td> |
| 46 |
<td><pre><ol class="linenums"><li class="L0">Hello,</li><li class="L1">the<span class="nocode">re World!</span></li></ol></pre></td> |
| 47 |
</tr> |
| 48 |
<tr><th colspan=3>Test link</th></tr> |
| 49 |
<tr> |
| 50 |
<td><pre class="testinput">Hello, the<a href="#" style="font-weight: bold">re Wor</a>ld!</pre></td> |
| 51 |
<td><pre><ol class="linenums"><li class="L0">Hello,</li><li class="L1">the<a href="#" style="font-weight: bold">re</a></li><li class="L2"><a href="#" style="font-weight: bold">Wor</a>ld!</li></ol></pre></td> |
| 52 |
</tr> |
| 53 |
<tr><th colspan=3>Test blank lines</th></tr> |
| 54 |
<tr> |
| 55 |
<td><pre class="testinput">One Three</pre></td> |
| 56 |
<td><pre><ol class="linenums"><li class="L0">One</li><li class="L1"> </li><li class="L2">Three</li></ol></pre></td> |
| 57 |
</tr> |
| 58 |
</table> |
| 59 |
|
| 60 |
<script> |
| 61 |
if (!document.body.getElementsByClassName) { |
| 62 |
document.body.getElementsByClassName = function (className) { |
| 63 |
className = className.replace(/\s+/g, ' ').replace(/^\s*|\s*$/g, ' '); |
| 64 |
var results = []; |
| 65 |
function walk(node) { |
| 66 |
if (node.nodeType !== 1) { return; } |
| 67 |
// This test should be order-insensitive. |
| 68 |
if ((' ' + node.className + ' ').indexOf(className) >= 0) { |
| 69 |
results[results.length] = node; |
| 70 |
} |
| 71 |
for (var child = node.firstChild; child; child = child.nextSibling) { |
| 72 |
walk(child); |
| 73 |
} |
| 74 |
} |
| 75 |
walk(document.body); |
| 76 |
return results; |
| 77 |
}; |
| 78 |
} |
| 79 |
|
| 80 |
setTimeout(function () { |
| 81 |
function normListItems(html) { |
| 82 |
// IE likes to leave out </li>s before <li>s. |
| 83 |
return html.replace(/<\/li>(<li\b)/gi, '$1'); |
| 84 |
} |
| 85 |
|
| 86 |
var testInputs = Array.prototype.slice.call( |
| 87 |
document.body.getElementsByClassName('testinput'), 0); |
| 88 |
for (var i = 0, n = testInputs.length; i < n; ++i) { |
| 89 |
var testInput = testInputs[i]; |
| 90 |
var testResult = testInput.parentNode.nextSibling; |
| 91 |
while (testResult.nodeType !== 1) { testResult = testResult.nextSibling; } |
| 92 |
var actual = document.createElement('TD'); |
| 93 |
testResult.parentNode.appendChild(actual); |
| 94 |
try { |
| 95 |
var testInputClone = testInput.cloneNode(true); |
| 96 |
testInputClone.className = ''; // IE |
| 97 |
testInputClone.removeAttribute('class'); // Not IE. |
| 98 |
actual.appendChild(testInputClone); |
| 99 |
numberLines(testInputClone); |
| 100 |
var goldenNorm = normListItems(testResult.innerHTML); |
| 101 |
var actualNorm = normListItems(actual.innerHTML); |
| 102 |
var passed = goldenNorm === actualNorm; |
| 103 |
if (!passed) { |
| 104 |
console.log(JSON.stringify(goldenNorm) |
| 105 |
+ ' !==\n' + JSON.stringify(actualNorm)); |
| 106 |
} |
| 107 |
actual.className = passed ? 'ok' : 'failure'; |
| 108 |
} catch (ex) { |
| 109 |
actual.className = 'error'; |
| 110 |
actual.appendChild(document.createTextNode('Error: ' + (ex.message || ex))); |
| 111 |
} |
| 112 |
actual.className += ' actual'; |
| 113 |
} |
| 114 |
}, 0)</script> |
| 115 |
|
| 116 |
<hr> |
| 117 |
<address></address> |
| 118 |
<!-- hhmts start --> Last modified: Tue Mar 29 16:44:05 PDT 2011 <!-- hhmts end --> |
| 119 |
</body> </html> |