2
0

index.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>CodeMirror: Test Suite</title>
  6. <link rel="stylesheet" href="../lib/codemirror.css">
  7. <link rel="stylesheet" href="../doc/docs.css">
  8. <link rel="stylesheet" href="mode_test.css">
  9. <script src="../lib/codemirror.js"></script>
  10. <script src="../addon/mode/overlay.js"></script>
  11. <script src="../addon/search/searchcursor.js"></script>
  12. <script src="../addon/dialog/dialog.js"></script>
  13. <script src="../addon/comment/comment.js"></script>
  14. <script src="../mode/javascript/javascript.js"></script>
  15. <script src="../mode/xml/xml.js"></script>
  16. <script src="../keymap/vim.js"></script>
  17. <style type="text/css">
  18. .ok {color: #090;}
  19. .fail {color: #e00;}
  20. .error {color: #c90;}
  21. .done {font-weight: bold;}
  22. #progress {
  23. background: #45d;
  24. color: white;
  25. text-shadow: 0 0 1px #45d, 0 0 2px #45d, 0 0 3px #45d;
  26. font-weight: bold;
  27. white-space: pre;
  28. }
  29. #testground {
  30. visibility: hidden;
  31. }
  32. #testground.offscreen {
  33. visibility: visible;
  34. position: absolute;
  35. left: -10000px;
  36. top: -10000px;
  37. }
  38. .CodeMirror { border: 1px solid black; }
  39. </style>
  40. </head>
  41. <body>
  42. <h1>CodeMirror: Test Suite</h1>
  43. <p>A limited set of programmatic sanity tests for CodeMirror.</p>
  44. <div style="border: 1px solid black; padding: 1px; max-width: 700px;">
  45. <div style="width: 0px;" id=progress><div style="padding: 3px;">Ran <span id="progress_ran">0</span><span id="progress_total"> of 0</span> tests</div></div>
  46. </div>
  47. <p id=status>Please enable JavaScript...</p>
  48. <div id=output></div>
  49. <div id=testground></div>
  50. <script src="driver.js"></script>
  51. <script src="test.js"></script>
  52. <script src="doc_test.js"></script>
  53. <script src="comment_test.js"></script>
  54. <script src="mode_test.js"></script>
  55. <script src="../mode/css/css.js"></script>
  56. <script src="../mode/css/test.js"></script>
  57. <script src="../mode/css/scss_test.js"></script>
  58. <script src="../mode/xml/xml.js"></script>
  59. <script src="../mode/htmlmixed/htmlmixed.js"></script>
  60. <script src="../mode/ruby/ruby.js"></script>
  61. <script src="../mode/haml/haml.js"></script>
  62. <script src="../mode/haml/test.js"></script>
  63. <script src="../mode/markdown/markdown.js"></script>
  64. <script src="../mode/markdown/test.js"></script>
  65. <script src="../mode/gfm/gfm.js"></script>
  66. <script src="../mode/gfm/test.js"></script>
  67. <script src="../mode/stex/stex.js"></script>
  68. <script src="../mode/stex/test.js"></script>
  69. <script src="../mode/xquery/xquery.js"></script>
  70. <script src="../mode/xquery/test.js"></script>
  71. <script src="vim_test.js"></script>
  72. <script>
  73. window.onload = runHarness;
  74. CodeMirror.on(window, 'hashchange', runHarness);
  75. function esc(str) {
  76. return str.replace(/[<&]/, function(ch) { return ch == "<" ? "&lt;" : "&amp;"; });
  77. }
  78. var output = document.getElementById("output"),
  79. progress = document.getElementById("progress"),
  80. progressRan = document.getElementById("progress_ran").childNodes[0],
  81. progressTotal = document.getElementById("progress_total").childNodes[0];
  82. var count = 0,
  83. failed = 0,
  84. bad = "",
  85. running = false, // Flag that states tests are running
  86. quit = false, // Flag to quit tests ASAP
  87. verbose = false; // Adds message for *every* test to output
  88. function runHarness(){
  89. if (running) {
  90. quit = true;
  91. setStatus("Restarting tests...", '', true);
  92. setTimeout(function(){runHarness();}, 500);
  93. return;
  94. }
  95. if (window.location.hash.substr(1)){
  96. debug = window.location.hash.substr(1).split(",");
  97. } else {
  98. debug = null;
  99. }
  100. quit = false;
  101. running = true;
  102. setStatus("Loading tests...");
  103. count = 0;
  104. failed = 0;
  105. bad = "";
  106. verbose = false;
  107. debugUsed = Array();
  108. totalTests = countTests();
  109. progressTotal.nodeValue = " of " + totalTests;
  110. progressRan.nodeValue = count;
  111. output.innerHTML = '';
  112. document.getElementById("testground").innerHTML = "<form>" +
  113. "<textarea id=\"code\" name=\"code\"></textarea>" +
  114. "<input type=submit value=ok name=submit>" +
  115. "</form>";
  116. runTests(displayTest);
  117. }
  118. function setStatus(message, className, force){
  119. if (quit && !force) return;
  120. if (!message) throw("must provide message");
  121. var status = document.getElementById("status").childNodes[0];
  122. status.nodeValue = message;
  123. status.parentNode.className = className;
  124. }
  125. function addOutput(name, className, code){
  126. var newOutput = document.createElement("dl");
  127. var newTitle = document.createElement("dt");
  128. newTitle.className = className;
  129. newTitle.appendChild(document.createTextNode(name));
  130. newOutput.appendChild(newTitle);
  131. var newMessage = document.createElement("dd");
  132. newMessage.innerHTML = code;
  133. newOutput.appendChild(newTitle);
  134. newOutput.appendChild(newMessage);
  135. output.appendChild(newOutput);
  136. }
  137. function displayTest(type, name, customMessage) {
  138. var message = "???";
  139. if (type != "done") ++count;
  140. progress.style.width = (count * (progress.parentNode.clientWidth - 2) / totalTests) + "px";
  141. progressRan.nodeValue = count;
  142. if (type == "ok") {
  143. message = "Test '" + name + "' succeeded";
  144. if (!verbose) customMessage = false;
  145. } else if (type == "expected") {
  146. message = "Test '" + name + "' failed as expected";
  147. if (!verbose) customMessage = false;
  148. } else if (type == "error" || type == "fail") {
  149. ++failed;
  150. message = "Test '" + name + "' failed";
  151. } else if (type == "done") {
  152. if (failed) {
  153. type += " fail";
  154. message = failed + " failure" + (failed > 1 ? "s" : "");
  155. } else if (count < totalTests) {
  156. failed = totalTests - count;
  157. type += " fail";
  158. message = failed + " failure" + (failed > 1 ? "s" : "");
  159. } else {
  160. type += " ok";
  161. message = "All passed";
  162. }
  163. if (debug && debug.length) {
  164. var bogusTests = totalTests - count;
  165. message += " — " + bogusTests + " nonexistent test" +
  166. (bogusTests > 1 ? "s" : "") + " requested by location.hash: " +
  167. "`" + debug.join("`, `") + "`";
  168. } else {
  169. progressTotal.nodeValue = '';
  170. }
  171. customMessage = true; // Hack to avoid adding to output
  172. }
  173. if (verbose && !customMessage) customMessage = message;
  174. setStatus(message, type);
  175. if (customMessage && customMessage.length > 0) {
  176. addOutput(name, type, customMessage);
  177. }
  178. }
  179. </script>
  180. </body>
  181. </html>