Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/test/driver.js
1293 views
1
var tests = [], filters = [], allNames = [];
2
3
function Failure(why) {this.message = why;}
4
Failure.prototype.toString = function() { return this.message; };
5
6
function indexOf(collection, elt) {
7
if (collection.indexOf) return collection.indexOf(elt);
8
for (var i = 0, e = collection.length; i < e; ++i)
9
if (collection[i] == elt) return i;
10
return -1;
11
}
12
13
function test(name, run, expectedFail) {
14
// Force unique names
15
var originalName = name;
16
var i = 2; // Second function would be NAME_2
17
while (indexOf(allNames, name) !== -1){
18
name = originalName + "_" + i;
19
i++;
20
}
21
allNames.push(name);
22
// Add test
23
tests.push({name: name, func: run, expectedFail: expectedFail});
24
return name;
25
}
26
var namespace = "";
27
function testCM(name, run, opts, expectedFail) {
28
return test(namespace + name, function() {
29
var place = document.getElementById("testground"), cm = window.cm = CodeMirror(place, opts);
30
var successful = false;
31
try {
32
run(cm);
33
successful = true;
34
} finally {
35
if (!successful || verbose) {
36
place.style.visibility = "visible";
37
} else {
38
place.removeChild(cm.getWrapperElement());
39
}
40
}
41
}, expectedFail);
42
}
43
44
function runTests(callback) {
45
var totalTime = 0;
46
function step(i) {
47
if (i === tests.length){
48
running = false;
49
return callback("done");
50
}
51
var test = tests[i], expFail = test.expectedFail, startTime = +new Date;
52
if (filters.length) {
53
for (var j = 0; j < filters.length; j++) {
54
if (test.name.match(filters[j])) {
55
break;
56
}
57
}
58
if (j == filters.length) {
59
callback("skipped", test.name, message);
60
return step(i + 1);
61
}
62
}
63
var threw = false;
64
try {
65
var message = test.func();
66
} catch(e) {
67
threw = true;
68
if (expFail) callback("expected", test.name);
69
else if (e instanceof Failure) callback("fail", test.name, e.message);
70
else {
71
var pos = /(?:\bat |@).*?([^\/:]+):(\d+)/.exec(e.stack);
72
callback("error", test.name, e.toString() + (pos ? " (" + pos[1] + ":" + pos[2] + ")" : ""));
73
}
74
}
75
if (!threw) {
76
if (expFail) callback("fail", test.name, message || "expected failure, but succeeded");
77
else callback("ok", test.name, message);
78
}
79
if (!quit) { // Run next test
80
var delay = 0;
81
totalTime += (+new Date) - startTime;
82
if (totalTime > 500){
83
totalTime = 0;
84
delay = 50;
85
}
86
setTimeout(function(){step(i + 1);}, delay);
87
} else { // Quit tests
88
running = false;
89
return null;
90
}
91
}
92
step(0);
93
}
94
95
function label(str, msg) {
96
if (msg) return str + " (" + msg + ")";
97
return str;
98
}
99
function eq(a, b, msg) {
100
if (a != b) throw new Failure(label(a + " != " + b, msg));
101
}
102
function eqPos(a, b, msg) {
103
function str(p) { return "{line:" + p.line + ",ch:" + p.ch + "}"; }
104
if (a == b) return;
105
if (a == null) throw new Failure(label("comparing null to " + str(b), msg));
106
if (b == null) throw new Failure(label("comparing " + str(a) + " to null", msg));
107
if (a.line != b.line || a.ch != b.ch) throw new Failure(label(str(a) + " != " + str(b), msg));
108
}
109
function is(a, msg) {
110
if (!a) throw new Failure(label("assertion failed", msg));
111
}
112
113
function countTests() {
114
if (!filters.length) return tests.length;
115
var sum = 0;
116
for (var i = 0; i < tests.length; ++i) {
117
var name = tests[i].name;
118
for (var j = 0; j < filters.length; j++) {
119
if (name.match(filters[j])) {
120
++sum;
121
break;
122
}
123
}
124
}
125
return sum;
126
}
127
128
function parseTestFilter(s) {
129
if (/_\*$/.test(s)) return new RegExp("^" + s.slice(0, s.length - 2), "i");
130
else return new RegExp(s, "i");
131
}
132
133