summaryrefslogtreecommitdiff
path: root/toolkit/devtools/sourceeditor/test/vimemacs.html
blob: 3d14507b6c24a6b467243a7013f8c5e86d5fb146 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>CodeMirror: VIM/Emacs tests</title>
    <link rel="stylesheet" href="chrome://browser/content/devtools/codemirror/codemirror.css">
    <link rel="stylesheet" href="cm_mode_test.css">
    <!--<link rel="stylesheet" href="../doc/docs.css">-->

    <script src="chrome://browser/content/devtools/codemirror/codemirror.js"></script>
    <script src="chrome://browser/content/devtools/codemirror/searchcursor.js"></script>
    <script src="chrome://browser/content/devtools/codemirror/dialog.js"></script>
    <script src="chrome://browser/content/devtools/codemirror/matchbrackets.js"></script>
    <script src="chrome://browser/content/devtools/codemirror/comment.js"></script>
    <script src="chrome://browser/content/devtools/codemirror/javascript.js"></script>
    <script src="chrome://browser/content/devtools/codemirror/vim.js"></script>
    <script src="chrome://browser/content/devtools/codemirror/sublime.js"></script>
    <script src="chrome://browser/content/devtools/codemirror/emacs.js"></script>

    <!--<script src="../addon/mode/overlay.js"></script>
    <script src="../addon/mode/multiplex.js"></script>
    <script src="../mode/xml/xml.js"></script>-->

    <style type="text/css">
      .ok {color: #090;}
      .fail {color: #e00;}
      .error {color: #c90;}
      .done {font-weight: bold;}
      #progress {
        background: #45d;
        color: white;
        text-shadow: 0 0 1px #45d, 0 0 2px #45d, 0 0 3px #45d;
        font-weight: bold;
        white-space: pre;
      }
      #testground {
        visibility: hidden;
      }
      #testground.offscreen {
        visibility: visible;
        position: absolute;
        left: -10000px;
        top: -10000px;
      }
      .CodeMirror { border: 1px solid black; }
    </style>
  </head>
  <body>
    <h1>CodeMirror: VIM/Emacs tests</h1>

    <p>A limited set of programmatic sanity tests for CodeMirror.</p>

    <div style="border: 1px solid black; padding: 1px; max-width: 700px;">
      <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>
    </div>
    <p id=status>Please enable JavaScript...</p>
    <div id=output></div>

    <div id=testground></div>

    <script src="cm_driver.js"></script>
    <script src="cm_sublime_test.js"></script>
    <script src="cm_vim_test.js"></script>
    <script src="cm_emacs_test.js"></script>

    <!-- Basic tests are in codemirror.html
    <script src="cm_driver.js"></script>
    <script src="cm_test.js"></script>
    <script src="cm_comment_test.js"></script>
    <script src="cm_doc_test.js"></script>
    <script src="cm_driver.js"></script>
    <script src="cm_emacs_test.js"></script>
    <script src="cm_mode_test.js"></script>
    <script src="cm_mode_javascript_test.js"></script>
    <script src="cm_multi_test.js"></script>
    <script src="cm_search_test.js"></script>
    -->

    <!-- These modes/addons are not used by Editor
    <script src="doc_test.js"></script>
    <script src="../mode/css/css.js"></script>
    <script src="../mode/css/test.js"></script>
    <script src="../mode/css/scss_test.js"></script>
    <script src="../mode/xml/xml.js"></script>
    <script src="../mode/htmlmixed/htmlmixed.js"></script>
    <script src="../mode/ruby/ruby.js"></script>
    <script src="../mode/haml/haml.js"></script>
    <script src="../mode/haml/test.js"></script>
    <script src="../mode/markdown/markdown.js"></script>
    <script src="../mode/markdown/test.js"></script>
    <script src="../mode/gfm/gfm.js"></script>
    <script src="../mode/gfm/test.js"></script>
    <script src="../mode/stex/stex.js"></script>
    <script src="../mode/stex/test.js"></script>
    <script src="../mode/xquery/xquery.js"></script>
    <script src="../mode/xquery/test.js"></script>
    <script src="../addon/mode/multiplex_test.js"></script>-->

    <script>
      window.onload = runHarness;
      CodeMirror.on(window, 'hashchange', runHarness);

      function esc(str) {
        return str.replace(/[<&]/, function(ch) { return ch == "<" ? "&lt;" : "&amp;"; });
      }

      var output = document.getElementById("output"),
          progress = document.getElementById("progress"),
          progressRan = document.getElementById("progress_ran").childNodes[0],
          progressTotal = document.getElementById("progress_total").childNodes[0];

      var count = 0,
          failed = 0,
          skipped = 0,
          bad = "",
          running = false, // Flag that states tests are running
          quit = false, // Flag to quit tests ASAP
          verbose = false, // Adds message for *every* test to output
          phantom = false;

      function runHarness(){
        if (running) {
          quit = true;
          setStatus("Restarting tests...", '', true);
          setTimeout(function(){runHarness();}, 500);
          return;
        }
        filters = [];
        verbose = false;
        if (window.location.hash.substr(1)){
          var strings = window.location.hash.substr(1).split(",");
          while (strings.length) {
            var s = strings.shift();
            if (s === "verbose")
              verbose = true;
            else
              filters.push(parseTestFilter(decodeURIComponent(s)));
          }
        }
        quit = false;
        running = true;
        setStatus("Loading tests...");
        count = 0;
        failed = 0;
        skipped = 0;
        bad = "";
        totalTests = countTests();
        progressTotal.nodeValue = " of " + totalTests;
        progressRan.nodeValue = count;
        output.innerHTML = '';
        document.getElementById("testground").innerHTML = "<form>" +
          "<textarea id=\"code\" name=\"code\"></textarea>" +
          "<input type=submit value=ok name=submit>" +
          "</form>";
        runTests(displayTest);
      }

      function setStatus(message, className, force){
        if (quit && !force) return;
        if (!message) throw("must provide message");
        var status = document.getElementById("status").childNodes[0];
        status.nodeValue = message;
        status.parentNode.className = className;
      }
      function addOutput(name, className, code){
        var newOutput = document.createElement("dl");
        var newTitle = document.createElement("dt");
        newTitle.className = className;
        newTitle.appendChild(document.createTextNode(name));
        newOutput.appendChild(newTitle);
        var newMessage = document.createElement("dd");
        newMessage.innerHTML = code;
        newOutput.appendChild(newTitle);
        newOutput.appendChild(newMessage);
        output.appendChild(newOutput);
      }
      function displayTest(type, name, customMessage) {
        var message = "???";
        if (type != "done" && type != "skipped") ++count;
        progress.style.width = (count * (progress.parentNode.clientWidth - 2) / totalTests) + "px";
        progressRan.nodeValue = count;
        if (type == "ok") {
          message = "Test '" + name + "' succeeded";
          if (!verbose) customMessage = false;
        } else if (type == "skipped") {
          message = "Test '" + name + "' skipped";
          ++skipped;
          if (!verbose) customMessage = false;
        } else if (type == "expected") {
          message = "Test '" + name + "' failed as expected";
          if (!verbose) customMessage = false;
        } else if (type == "error" || type == "fail") {
          ++failed;
          message = "Test '" + name + "' failed";
        } else if (type == "done") {
          if (failed) {
            type += " fail";
            message = failed + " failure" + (failed > 1 ? "s" : "");
          } else if (count < totalTests) {
            failed = totalTests - count;
            type += " fail";
            message = failed + " failure" + (failed > 1 ? "s" : "");
          } else {
            type += " ok";
            message = "All passed";
            if (skipped) {
              message += " (" + skipped + " skipped)";
            }
          }
          progressTotal.nodeValue = '';
          customMessage = true; // Hack to avoid adding to output
        }
        if (window.mozilla_setStatus)
          mozilla_setStatus(message, type, customMessage);
        if (verbose && !customMessage)  customMessage = message;
        setStatus(message, type);
        if (customMessage && customMessage.length > 0) {
          addOutput(name, type, customMessage);
        }
      }
    </script>
  </body>
</html>