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