Update v1.0.6
This commit is contained in:
63
public/filemanager/scripts/CodeMirror/test/comment_test.js
vendored
Normal file
63
public/filemanager/scripts/CodeMirror/test/comment_test.js
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
namespace = "comment_";
|
||||
|
||||
(function() {
|
||||
function test(name, mode, run, before, after) {
|
||||
return testCM(name, function(cm) {
|
||||
run(cm);
|
||||
eq(cm.getValue(), after);
|
||||
}, {value: before, mode: mode});
|
||||
}
|
||||
|
||||
var simpleProg = "function foo() {\n return bar;\n}";
|
||||
|
||||
test("block", "javascript", function(cm) {
|
||||
cm.blockComment(Pos(0, 3), Pos(3, 0), {blockCommentLead: " *"});
|
||||
}, simpleProg + "\n", "/* function foo() {\n * return bar;\n * }\n */");
|
||||
|
||||
test("blockToggle", "javascript", function(cm) {
|
||||
cm.blockComment(Pos(0, 3), Pos(2, 0), {blockCommentLead: " *"});
|
||||
cm.uncomment(Pos(0, 3), Pos(2, 0), {blockCommentLead: " *"});
|
||||
}, simpleProg, simpleProg);
|
||||
|
||||
test("line", "javascript", function(cm) {
|
||||
cm.lineComment(Pos(1, 1), Pos(1, 1));
|
||||
}, simpleProg, "function foo() {\n// return bar;\n}");
|
||||
|
||||
test("lineToggle", "javascript", function(cm) {
|
||||
cm.lineComment(Pos(0, 0), Pos(2, 1));
|
||||
cm.uncomment(Pos(0, 0), Pos(2, 1));
|
||||
}, simpleProg, simpleProg);
|
||||
|
||||
test("fallbackToBlock", "css", function(cm) {
|
||||
cm.lineComment(Pos(0, 0), Pos(2, 1));
|
||||
}, "html {\n border: none;\n}", "/* html {\n border: none;\n} */");
|
||||
|
||||
test("fallbackToLine", "ruby", function(cm) {
|
||||
cm.blockComment(Pos(0, 0), Pos(1));
|
||||
}, "def blah()\n return hah\n", "# def blah()\n# return hah\n");
|
||||
|
||||
test("commentRange", "javascript", function(cm) {
|
||||
cm.blockComment(Pos(1, 2), Pos(1, 13), {fullLines: false});
|
||||
}, simpleProg, "function foo() {\n /*return bar;*/\n}");
|
||||
|
||||
test("indented", "javascript", function(cm) {
|
||||
cm.lineComment(Pos(1, 0), Pos(2), {indent: true});
|
||||
}, simpleProg, "function foo() {\n // return bar;\n // }");
|
||||
|
||||
test("singleEmptyLine", "javascript", function(cm) {
|
||||
cm.setCursor(1);
|
||||
cm.execCommand("toggleComment");
|
||||
}, "a;\n\nb;", "a;\n// \nb;");
|
||||
|
||||
test("dontMessWithStrings", "javascript", function(cm) {
|
||||
cm.execCommand("toggleComment");
|
||||
}, "console.log(\"/*string*/\");", "// console.log(\"/*string*/\");");
|
||||
|
||||
test("dontMessWithStrings2", "javascript", function(cm) {
|
||||
cm.execCommand("toggleComment");
|
||||
}, "console.log(\"// string\");", "// console.log(\"// string\");");
|
||||
|
||||
test("dontMessWithStrings3", "javascript", function(cm) {
|
||||
cm.execCommand("toggleComment");
|
||||
}, "// console.log(\"// string\");", "console.log(\"// string\");");
|
||||
})();
|
371
public/filemanager/scripts/CodeMirror/test/doc_test.js
vendored
Normal file
371
public/filemanager/scripts/CodeMirror/test/doc_test.js
vendored
Normal file
@@ -0,0 +1,371 @@
|
||||
(function() {
|
||||
// A minilanguage for instantiating linked CodeMirror instances and Docs
|
||||
function instantiateSpec(spec, place, opts) {
|
||||
var names = {}, pos = 0, l = spec.length, editors = [];
|
||||
while (spec) {
|
||||
var m = spec.match(/^(\w+)(\*?)(?:='([^\']*)'|<(~?)(\w+)(?:\/(\d+)-(\d+))?)\s*/);
|
||||
var name = m[1], isDoc = m[2], cur;
|
||||
if (m[3]) {
|
||||
cur = isDoc ? CodeMirror.Doc(m[3]) : CodeMirror(place, clone(opts, {value: m[3]}));
|
||||
} else {
|
||||
var other = m[5];
|
||||
if (!names.hasOwnProperty(other)) {
|
||||
names[other] = editors.length;
|
||||
editors.push(CodeMirror(place, opts));
|
||||
}
|
||||
var doc = editors[names[other]].linkedDoc({
|
||||
sharedHist: !m[4],
|
||||
from: m[6] ? Number(m[6]) : null,
|
||||
to: m[7] ? Number(m[7]) : null
|
||||
});
|
||||
cur = isDoc ? doc : CodeMirror(place, clone(opts, {value: doc}));
|
||||
}
|
||||
names[name] = editors.length;
|
||||
editors.push(cur);
|
||||
spec = spec.slice(m[0].length);
|
||||
}
|
||||
return editors;
|
||||
}
|
||||
|
||||
function clone(obj, props) {
|
||||
if (!obj) return;
|
||||
clone.prototype = obj;
|
||||
var inst = new clone();
|
||||
if (props) for (var n in props) if (props.hasOwnProperty(n))
|
||||
inst[n] = props[n];
|
||||
return inst;
|
||||
}
|
||||
|
||||
function eqAll(val) {
|
||||
var end = arguments.length, msg = null;
|
||||
if (typeof arguments[end-1] == "string")
|
||||
msg = arguments[--end];
|
||||
if (i == end) throw new Error("No editors provided to eqAll");
|
||||
for (var i = 1; i < end; ++i)
|
||||
eq(arguments[i].getValue(), val, msg)
|
||||
}
|
||||
|
||||
function testDoc(name, spec, run, opts, expectFail) {
|
||||
if (!opts) opts = {};
|
||||
|
||||
return test("doc_" + name, function() {
|
||||
var place = document.getElementById("testground");
|
||||
var editors = instantiateSpec(spec, place, opts);
|
||||
var successful = false;
|
||||
|
||||
try {
|
||||
run.apply(null, editors);
|
||||
successful = true;
|
||||
} finally {
|
||||
if (!successful || verbose) {
|
||||
place.style.visibility = "visible";
|
||||
} else {
|
||||
for (var i = 0; i < editors.length; ++i)
|
||||
if (editors[i] instanceof CodeMirror)
|
||||
place.removeChild(editors[i].getWrapperElement());
|
||||
}
|
||||
}
|
||||
}, expectFail);
|
||||
}
|
||||
|
||||
var ie_lt8 = /MSIE [1-7]\b/.test(navigator.userAgent);
|
||||
|
||||
function testBasic(a, b) {
|
||||
eqAll("x", a, b);
|
||||
a.setValue("hey");
|
||||
eqAll("hey", a, b);
|
||||
b.setValue("wow");
|
||||
eqAll("wow", a, b);
|
||||
a.replaceRange("u\nv\nw", Pos(0, 3));
|
||||
b.replaceRange("i", Pos(0, 4));
|
||||
b.replaceRange("j", Pos(2, 1));
|
||||
eqAll("wowui\nv\nwj", a, b);
|
||||
}
|
||||
|
||||
testDoc("basic", "A='x' B<A", testBasic);
|
||||
testDoc("basicSeparate", "A='x' B<~A", testBasic);
|
||||
|
||||
testDoc("sharedHist", "A='ab\ncd\nef' B<A", function(a, b) {
|
||||
a.replaceRange("x", Pos(0));
|
||||
b.replaceRange("y", Pos(1));
|
||||
a.replaceRange("z", Pos(2));
|
||||
eqAll("abx\ncdy\nefz", a, b);
|
||||
a.undo();
|
||||
a.undo();
|
||||
eqAll("abx\ncd\nef", a, b);
|
||||
a.redo();
|
||||
eqAll("abx\ncdy\nef", a, b);
|
||||
b.redo();
|
||||
eqAll("abx\ncdy\nefz", a, b);
|
||||
a.undo(); b.undo(); a.undo(); a.undo();
|
||||
eqAll("ab\ncd\nef", a, b);
|
||||
}, null, ie_lt8);
|
||||
|
||||
testDoc("undoIntact", "A='ab\ncd\nef' B<~A", function(a, b) {
|
||||
a.replaceRange("x", Pos(0));
|
||||
b.replaceRange("y", Pos(1));
|
||||
a.replaceRange("z", Pos(2));
|
||||
a.replaceRange("q", Pos(0));
|
||||
eqAll("abxq\ncdy\nefz", a, b);
|
||||
a.undo();
|
||||
a.undo();
|
||||
eqAll("abx\ncdy\nef", a, b);
|
||||
b.undo();
|
||||
eqAll("abx\ncd\nef", a, b);
|
||||
a.redo();
|
||||
eqAll("abx\ncd\nefz", a, b);
|
||||
a.redo();
|
||||
eqAll("abxq\ncd\nefz", a, b);
|
||||
a.undo(); a.undo(); a.undo(); a.undo();
|
||||
eqAll("ab\ncd\nef", a, b);
|
||||
b.redo();
|
||||
eqAll("ab\ncdy\nef", a, b);
|
||||
});
|
||||
|
||||
testDoc("undoConflict", "A='ab\ncd\nef' B<~A", function(a, b) {
|
||||
a.replaceRange("x", Pos(0));
|
||||
a.replaceRange("z", Pos(2));
|
||||
// This should clear the first undo event in a, but not the second
|
||||
b.replaceRange("y", Pos(0));
|
||||
a.undo(); a.undo();
|
||||
eqAll("abxy\ncd\nef", a, b);
|
||||
a.replaceRange("u", Pos(2));
|
||||
a.replaceRange("v", Pos(0));
|
||||
// This should clear both events in a
|
||||
b.replaceRange("w", Pos(0));
|
||||
a.undo(); a.undo();
|
||||
eqAll("abxyvw\ncd\nefu", a, b);
|
||||
});
|
||||
|
||||
testDoc("doubleRebase", "A='ab\ncd\nef\ng' B<~A C<B", function(a, b, c) {
|
||||
c.replaceRange("u", Pos(3));
|
||||
a.replaceRange("", Pos(0, 0), Pos(1, 0));
|
||||
c.undo();
|
||||
eqAll("cd\nef\ng", a, b, c);
|
||||
});
|
||||
|
||||
testDoc("undoUpdate", "A='ab\ncd\nef' B<~A", function(a, b) {
|
||||
a.replaceRange("x", Pos(2));
|
||||
b.replaceRange("u\nv\nw\n", Pos(0, 0));
|
||||
a.undo();
|
||||
eqAll("u\nv\nw\nab\ncd\nef", a, b);
|
||||
a.redo();
|
||||
eqAll("u\nv\nw\nab\ncd\nefx", a, b);
|
||||
a.undo();
|
||||
eqAll("u\nv\nw\nab\ncd\nef", a, b);
|
||||
b.undo();
|
||||
a.redo();
|
||||
eqAll("ab\ncd\nefx", a, b);
|
||||
a.undo();
|
||||
eqAll("ab\ncd\nef", a, b);
|
||||
});
|
||||
|
||||
testDoc("undoKeepRanges", "A='abcdefg' B<A", function(a, b) {
|
||||
var m = a.markText(Pos(0, 1), Pos(0, 3), {className: "foo"});
|
||||
b.replaceRange("x", Pos(0, 0));
|
||||
eqPos(m.find().from, Pos(0, 2));
|
||||
b.replaceRange("yzzy", Pos(0, 1), Pos(0));
|
||||
eq(m.find(), null);
|
||||
b.undo();
|
||||
eqPos(m.find().from, Pos(0, 2));
|
||||
b.undo();
|
||||
eqPos(m.find().from, Pos(0, 1));
|
||||
});
|
||||
|
||||
testDoc("longChain", "A='uv' B<A C<B D<C", function(a, b, c, d) {
|
||||
a.replaceSelection("X");
|
||||
eqAll("Xuv", a, b, c, d);
|
||||
d.replaceRange("Y", Pos(0));
|
||||
eqAll("XuvY", a, b, c, d);
|
||||
});
|
||||
|
||||
testDoc("broadCast", "B<A C<A D<A E<A", function(a, b, c, d, e) {
|
||||
b.setValue("uu");
|
||||
eqAll("uu", a, b, c, d, e);
|
||||
a.replaceRange("v", Pos(0, 1));
|
||||
eqAll("uvu", a, b, c, d, e);
|
||||
});
|
||||
|
||||
// A and B share a history, C and D share a separate one
|
||||
testDoc("islands", "A='x\ny\nz' B<A C<~A D<C", function(a, b, c, d) {
|
||||
a.replaceRange("u", Pos(0));
|
||||
d.replaceRange("v", Pos(2));
|
||||
b.undo();
|
||||
eqAll("x\ny\nzv", a, b, c, d);
|
||||
c.undo();
|
||||
eqAll("x\ny\nz", a, b, c, d);
|
||||
a.redo();
|
||||
eqAll("xu\ny\nz", a, b, c, d);
|
||||
d.redo();
|
||||
eqAll("xu\ny\nzv", a, b, c, d);
|
||||
});
|
||||
|
||||
testDoc("unlink", "B<A C<A D<B", function(a, b, c, d) {
|
||||
a.setValue("hi");
|
||||
b.unlinkDoc(a);
|
||||
d.setValue("aye");
|
||||
eqAll("hi", a, c);
|
||||
eqAll("aye", b, d);
|
||||
a.setValue("oo");
|
||||
eqAll("oo", a, c);
|
||||
eqAll("aye", b, d);
|
||||
});
|
||||
|
||||
testDoc("bareDoc", "A*='foo' B*<A C<B", function(a, b, c) {
|
||||
is(a instanceof CodeMirror.Doc);
|
||||
is(b instanceof CodeMirror.Doc);
|
||||
is(c instanceof CodeMirror);
|
||||
eqAll("foo", a, b, c);
|
||||
a.replaceRange("hey", Pos(0, 0), Pos(0));
|
||||
c.replaceRange("!", Pos(0));
|
||||
eqAll("hey!", a, b, c);
|
||||
b.unlinkDoc(a);
|
||||
b.setValue("x");
|
||||
eqAll("x", b, c);
|
||||
eqAll("hey!", a);
|
||||
});
|
||||
|
||||
testDoc("swapDoc", "A='a' B*='b' C<A", function(a, b, c) {
|
||||
var d = a.swapDoc(b);
|
||||
d.setValue("x");
|
||||
eqAll("x", c, d);
|
||||
eqAll("b", a, b);
|
||||
});
|
||||
|
||||
testDoc("docKeepsScroll", "A='x' B*='y'", function(a, b) {
|
||||
addDoc(a, 200, 200);
|
||||
a.scrollIntoView(Pos(199, 200));
|
||||
var c = a.swapDoc(b);
|
||||
a.swapDoc(c);
|
||||
var pos = a.getScrollInfo();
|
||||
is(pos.left > 0, "not at left");
|
||||
is(pos.top > 0, "not at top");
|
||||
});
|
||||
|
||||
testDoc("copyDoc", "A='u'", function(a) {
|
||||
var copy = a.getDoc().copy(true);
|
||||
a.setValue("foo");
|
||||
copy.setValue("bar");
|
||||
var old = a.swapDoc(copy);
|
||||
eq(a.getValue(), "bar");
|
||||
a.undo();
|
||||
eq(a.getValue(), "u");
|
||||
a.swapDoc(old);
|
||||
eq(a.getValue(), "foo");
|
||||
eq(old.historySize().undo, 1);
|
||||
eq(old.copy(false).historySize().undo, 0);
|
||||
});
|
||||
|
||||
testDoc("docKeepsMode", "A='1+1'", function(a) {
|
||||
var other = CodeMirror.Doc("hi", "text/x-markdown");
|
||||
a.setOption("mode", "text/javascript");
|
||||
var old = a.swapDoc(other);
|
||||
eq(a.getOption("mode"), "text/x-markdown");
|
||||
eq(a.getMode().name, "markdown");
|
||||
a.swapDoc(old);
|
||||
eq(a.getOption("mode"), "text/javascript");
|
||||
eq(a.getMode().name, "javascript");
|
||||
});
|
||||
|
||||
testDoc("subview", "A='1\n2\n3\n4\n5' B<~A/1-3", function(a, b) {
|
||||
eq(b.getValue(), "2\n3");
|
||||
eq(b.firstLine(), 1);
|
||||
b.setCursor(Pos(4));
|
||||
eqPos(b.getCursor(), Pos(2, 1));
|
||||
a.replaceRange("-1\n0\n", Pos(0, 0));
|
||||
eq(b.firstLine(), 3);
|
||||
eqPos(b.getCursor(), Pos(4, 1));
|
||||
a.undo();
|
||||
eqPos(b.getCursor(), Pos(2, 1));
|
||||
b.replaceRange("oyoy\n", Pos(2, 0));
|
||||
eq(a.getValue(), "1\n2\noyoy\n3\n4\n5");
|
||||
b.undo();
|
||||
eq(a.getValue(), "1\n2\n3\n4\n5");
|
||||
});
|
||||
|
||||
testDoc("subviewEditOnBoundary", "A='11\n22\n33\n44\n55' B<~A/1-4", function(a, b) {
|
||||
a.replaceRange("x\nyy\nz", Pos(0, 1), Pos(2, 1));
|
||||
eq(b.firstLine(), 2);
|
||||
eq(b.lineCount(), 2);
|
||||
eq(b.getValue(), "z3\n44");
|
||||
a.replaceRange("q\nrr\ns", Pos(3, 1), Pos(4, 1));
|
||||
eq(b.firstLine(), 2);
|
||||
eq(b.getValue(), "z3\n4q");
|
||||
eq(a.getValue(), "1x\nyy\nz3\n4q\nrr\ns5");
|
||||
a.execCommand("selectAll");
|
||||
a.replaceSelection("!");
|
||||
eqAll("!", a, b);
|
||||
});
|
||||
|
||||
|
||||
testDoc("sharedMarker", "A='ab\ncd\nef\ngh' B<A C<~A/1-2", function(a, b, c) {
|
||||
var mark = b.markText(Pos(0, 1), Pos(3, 1),
|
||||
{className: "cm-searching", shared: true});
|
||||
var found = a.findMarksAt(Pos(0, 2));
|
||||
eq(found.length, 1);
|
||||
eq(found[0], mark);
|
||||
eq(c.findMarksAt(Pos(1, 1)).length, 1);
|
||||
eqPos(mark.find().from, Pos(0, 1));
|
||||
eqPos(mark.find().to, Pos(3, 1));
|
||||
b.replaceRange("x\ny\n", Pos(0, 0));
|
||||
eqPos(mark.find().from, Pos(2, 1));
|
||||
eqPos(mark.find().to, Pos(5, 1));
|
||||
var cleared = 0;
|
||||
CodeMirror.on(mark, "clear", function() {++cleared;});
|
||||
b.operation(function(){mark.clear();});
|
||||
eq(a.findMarksAt(Pos(3, 1)).length, 0);
|
||||
eq(b.findMarksAt(Pos(3, 1)).length, 0);
|
||||
eq(c.findMarksAt(Pos(3, 1)).length, 0);
|
||||
eq(mark.find(), null);
|
||||
eq(cleared, 1);
|
||||
});
|
||||
|
||||
testDoc("sharedMarkerCopy", "A='abcde'", function(a) {
|
||||
var shared = a.markText(Pos(0, 1), Pos(0, 3), {shared: true});
|
||||
var b = a.linkedDoc();
|
||||
var found = b.findMarksAt(Pos(0, 2));
|
||||
eq(found.length, 1);
|
||||
eq(found[0], shared);
|
||||
shared.clear();
|
||||
eq(b.findMarksAt(Pos(0, 2)), 0);
|
||||
});
|
||||
|
||||
testDoc("sharedMarkerDetach", "A='abcde' B<A C<B", function(a, b, c) {
|
||||
var shared = a.markText(Pos(0, 1), Pos(0, 3), {shared: true});
|
||||
a.unlinkDoc(b);
|
||||
var inB = b.findMarksAt(Pos(0, 2));
|
||||
eq(inB.length, 1);
|
||||
is(inB[0] != shared);
|
||||
var inC = c.findMarksAt(Pos(0, 2));
|
||||
eq(inC.length, 1);
|
||||
is(inC[0] != shared);
|
||||
inC[0].clear();
|
||||
is(shared.find());
|
||||
});
|
||||
|
||||
testDoc("sharedBookmark", "A='ab\ncd\nef\ngh' B<A C<~A/1-2", function(a, b, c) {
|
||||
var mark = b.setBookmark(Pos(1, 1), {shared: true});
|
||||
var found = a.findMarksAt(Pos(1, 1));
|
||||
eq(found.length, 1);
|
||||
eq(found[0], mark);
|
||||
eq(c.findMarksAt(Pos(1, 1)).length, 1);
|
||||
eqPos(mark.find(), Pos(1, 1));
|
||||
b.replaceRange("x\ny\n", Pos(0, 0));
|
||||
eqPos(mark.find(), Pos(3, 1));
|
||||
var cleared = 0;
|
||||
CodeMirror.on(mark, "clear", function() {++cleared;});
|
||||
b.operation(function() {mark.clear();});
|
||||
eq(a.findMarks(Pos(0, 0), Pos(5)).length, 0);
|
||||
eq(b.findMarks(Pos(0, 0), Pos(5)).length, 0);
|
||||
eq(c.findMarks(Pos(0, 0), Pos(5)).length, 0);
|
||||
eq(mark.find(), null);
|
||||
eq(cleared, 1);
|
||||
});
|
||||
|
||||
testDoc("undoInSubview", "A='line 0\nline 1\nline 2\nline 3\nline 4' B<A/1-4", function(a, b) {
|
||||
b.replaceRange("x", Pos(2, 0));
|
||||
a.undo();
|
||||
eq(a.getValue(), "line 0\nline 1\nline 2\nline 3\nline 4");
|
||||
eq(b.getValue(), "line 1\nline 2\nline 3");
|
||||
});
|
||||
})();
|
138
public/filemanager/scripts/CodeMirror/test/driver.js
vendored
Normal file
138
public/filemanager/scripts/CodeMirror/test/driver.js
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
var tests = [], filters = [], allNames = [];
|
||||
|
||||
function Failure(why) {this.message = why;}
|
||||
Failure.prototype.toString = function() { return this.message; };
|
||||
|
||||
function indexOf(collection, elt) {
|
||||
if (collection.indexOf) return collection.indexOf(elt);
|
||||
for (var i = 0, e = collection.length; i < e; ++i)
|
||||
if (collection[i] == elt) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
function test(name, run, expectedFail) {
|
||||
// Force unique names
|
||||
var originalName = name;
|
||||
var i = 2; // Second function would be NAME_2
|
||||
while (indexOf(allNames, name) !== -1){
|
||||
name = originalName + "_" + i;
|
||||
i++;
|
||||
}
|
||||
allNames.push(name);
|
||||
// Add test
|
||||
tests.push({name: name, func: run, expectedFail: expectedFail});
|
||||
return name;
|
||||
}
|
||||
var namespace = "";
|
||||
function testCM(name, run, opts, expectedFail) {
|
||||
return test(namespace + name, function() {
|
||||
var place = document.getElementById("testground"), cm = window.cm = CodeMirror(place, opts);
|
||||
var successful = false;
|
||||
try {
|
||||
run(cm);
|
||||
successful = true;
|
||||
} finally {
|
||||
if (!successful || verbose) {
|
||||
place.style.visibility = "visible";
|
||||
} else {
|
||||
place.removeChild(cm.getWrapperElement());
|
||||
}
|
||||
}
|
||||
}, expectedFail);
|
||||
}
|
||||
|
||||
function runTests(callback) {
|
||||
var totalTime = 0;
|
||||
function step(i) {
|
||||
for (;;) {
|
||||
if (i === tests.length) {
|
||||
running = false;
|
||||
return callback("done");
|
||||
}
|
||||
var test = tests[i], skip = false;
|
||||
if (filters.length) {
|
||||
skip = true;
|
||||
for (var j = 0; j < filters.length; j++)
|
||||
if (test.name.match(filters[j])) skip = false;
|
||||
}
|
||||
if (skip) {
|
||||
callback("skipped", test.name, message);
|
||||
i++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
var expFail = test.expectedFail, startTime = +new Date, threw = false;
|
||||
try {
|
||||
var message = test.func();
|
||||
} catch(e) {
|
||||
threw = true;
|
||||
if (expFail) callback("expected", test.name);
|
||||
else if (e instanceof Failure) callback("fail", test.name, e.message);
|
||||
else {
|
||||
var pos = /(?:\bat |@).*?([^\/:]+):(\d+)/.exec(e.stack);
|
||||
if (pos) console["log"](e.stack);
|
||||
callback("error", test.name, e.toString() + (pos ? " (" + pos[1] + ":" + pos[2] + ")" : ""));
|
||||
}
|
||||
}
|
||||
if (!threw) {
|
||||
if (expFail) callback("fail", test.name, message || "expected failure, but succeeded");
|
||||
else callback("ok", test.name, message);
|
||||
}
|
||||
if (!quit) { // Run next test
|
||||
var delay = 0;
|
||||
totalTime += (+new Date) - startTime;
|
||||
if (totalTime > 500){
|
||||
totalTime = 0;
|
||||
delay = 50;
|
||||
}
|
||||
setTimeout(function(){step(i + 1);}, delay);
|
||||
} else { // Quit tests
|
||||
running = false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
step(0);
|
||||
}
|
||||
|
||||
function label(str, msg) {
|
||||
if (msg) return str + " (" + msg + ")";
|
||||
return str;
|
||||
}
|
||||
function eq(a, b, msg) {
|
||||
if (a != b) throw new Failure(label(a + " != " + b, msg));
|
||||
}
|
||||
function near(a, b, margin, msg) {
|
||||
if (Math.abs(a - b) > margin)
|
||||
throw new Failure(label(a + " is not close to " + b + " (" + margin + ")", msg));
|
||||
}
|
||||
function eqPos(a, b, msg) {
|
||||
function str(p) { return "{line:" + p.line + ",ch:" + p.ch + "}"; }
|
||||
if (a == b) return;
|
||||
if (a == null) throw new Failure(label("comparing null to " + str(b), msg));
|
||||
if (b == null) throw new Failure(label("comparing " + str(a) + " to null", msg));
|
||||
if (a.line != b.line || a.ch != b.ch) throw new Failure(label(str(a) + " != " + str(b), msg));
|
||||
}
|
||||
function is(a, msg) {
|
||||
if (!a) throw new Failure(label("assertion failed", msg));
|
||||
}
|
||||
|
||||
function countTests() {
|
||||
if (!filters.length) return tests.length;
|
||||
var sum = 0;
|
||||
for (var i = 0; i < tests.length; ++i) {
|
||||
var name = tests[i].name;
|
||||
for (var j = 0; j < filters.length; j++) {
|
||||
if (name.match(filters[j])) {
|
||||
++sum;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
function parseTestFilter(s) {
|
||||
if (/_\*$/.test(s)) return new RegExp("^" + s.slice(0, s.length - 2), "i");
|
||||
else return new RegExp(s, "i");
|
||||
}
|
138
public/filemanager/scripts/CodeMirror/test/emacs_test.js
vendored
Normal file
138
public/filemanager/scripts/CodeMirror/test/emacs_test.js
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
var Pos = CodeMirror.Pos;
|
||||
namespace = "emacs_";
|
||||
|
||||
var eventCache = {};
|
||||
function fakeEvent(keyName) {
|
||||
var event = eventCache[key];
|
||||
if (event) return event;
|
||||
|
||||
var ctrl, shift, alt;
|
||||
var key = keyName.replace(/\w+-/g, function(type) {
|
||||
if (type == "Ctrl-") ctrl = true;
|
||||
else if (type == "Alt-") alt = true;
|
||||
else if (type == "Shift-") shift = true;
|
||||
return "";
|
||||
});
|
||||
var code;
|
||||
for (var c in CodeMirror.keyNames)
|
||||
if (CodeMirror.keyNames[c] == key) { code = c; break; }
|
||||
if (c == null) throw new Error("Unknown key: " + key);
|
||||
|
||||
return eventCache[keyName] = {
|
||||
type: "keydown", keyCode: code, ctrlKey: ctrl, shiftKey: shift, altKey: alt,
|
||||
preventDefault: function(){}, stopPropagation: function(){}
|
||||
};
|
||||
}
|
||||
|
||||
function sim(name, start /*, actions... */) {
|
||||
var keys = Array.prototype.slice.call(arguments, 2);
|
||||
testCM(name, function(cm) {
|
||||
for (var i = 0; i < keys.length; ++i) {
|
||||
var cur = keys[i];
|
||||
if (cur instanceof Pos) cm.setCursor(cur);
|
||||
else if (cur.call) cur(cm);
|
||||
else cm.triggerOnKeyDown(fakeEvent(cur));
|
||||
}
|
||||
}, {keyMap: "emacs", value: start, mode: "javascript"});
|
||||
}
|
||||
|
||||
function at(line, ch) { return function(cm) { eqPos(cm.getCursor(), Pos(line, ch)); }; }
|
||||
function txt(str) { return function(cm) { eq(cm.getValue(), str); }; }
|
||||
|
||||
sim("motionHSimple", "abc", "Ctrl-F", "Ctrl-F", "Ctrl-B", at(0, 1));
|
||||
sim("motionHMulti", "abcde",
|
||||
"Ctrl-4", "Ctrl-F", at(0, 4), "Ctrl--", "Ctrl-2", "Ctrl-F", at(0, 2),
|
||||
"Ctrl-5", "Ctrl-B", at(0, 0));
|
||||
|
||||
sim("motionHWord", "abc. def ghi",
|
||||
"Alt-F", at(0, 3), "Alt-F", at(0, 8),
|
||||
"Ctrl-B", "Alt-B", at(0, 5), "Alt-B", at(0, 0));
|
||||
sim("motionHWordMulti", "abc. def ghi ",
|
||||
"Ctrl-3", "Alt-F", at(0, 12), "Ctrl-2", "Alt-B", at(0, 5),
|
||||
"Ctrl--", "Alt-B", at(0, 8));
|
||||
|
||||
sim("motionVSimple", "a\nb\nc\n", "Ctrl-N", "Ctrl-N", "Ctrl-P", at(1, 0));
|
||||
sim("motionVMulti", "a\nb\nc\nd\ne\n",
|
||||
"Ctrl-2", "Ctrl-N", at(2, 0), "Ctrl-F", "Ctrl--", "Ctrl-N", at(1, 1),
|
||||
"Ctrl--", "Ctrl-3", "Ctrl-P", at(4, 1));
|
||||
|
||||
sim("killYank", "abc\ndef\nghi",
|
||||
"Ctrl-F", "Ctrl-Space", "Ctrl-N", "Ctrl-N", "Ctrl-W", "Ctrl-E", "Ctrl-Y",
|
||||
txt("ahibc\ndef\ng"));
|
||||
sim("killRing", "abcdef",
|
||||
"Ctrl-Space", "Ctrl-F", "Ctrl-W", "Ctrl-Space", "Ctrl-F", "Ctrl-W",
|
||||
"Ctrl-Y", "Alt-Y",
|
||||
txt("acdef"));
|
||||
sim("copyYank", "abcd",
|
||||
"Ctrl-Space", "Ctrl-E", "Alt-W", "Ctrl-Y",
|
||||
txt("abcdabcd"));
|
||||
|
||||
sim("killLineSimple", "foo\nbar", "Ctrl-F", "Ctrl-K", txt("f\nbar"));
|
||||
sim("killLineEmptyLine", "foo\n \nbar", "Ctrl-N", "Ctrl-K", txt("foo\nbar"));
|
||||
sim("killLineMulti", "foo\nbar\nbaz",
|
||||
"Ctrl-F", "Ctrl-F", "Ctrl-K", "Ctrl-K", "Ctrl-K", "Ctrl-A", "Ctrl-Y",
|
||||
txt("o\nbarfo\nbaz"));
|
||||
|
||||
sim("moveByParagraph", "abc\ndef\n\n\nhij\nklm\n\n",
|
||||
"Ctrl-F", "Ctrl-Down", at(2, 0), "Ctrl-Down", at(6, 0),
|
||||
"Ctrl-N", "Ctrl-Up", at(3, 0), "Ctrl-Up", at(0, 0),
|
||||
Pos(1, 2), "Ctrl-Down", at(2, 0), Pos(4, 2), "Ctrl-Up", at(3, 0));
|
||||
sim("moveByParagraphMulti", "abc\n\ndef\n\nhij\n\nklm",
|
||||
"Ctrl-U", "2", "Ctrl-Down", at(3, 0),
|
||||
"Shift-Alt-.", "Ctrl-3", "Ctrl-Up", at(1, 0));
|
||||
|
||||
sim("moveBySentence", "sentence one! sentence\ntwo\n\nparagraph two",
|
||||
"Alt-E", at(0, 13), "Alt-E", at(1, 3), "Ctrl-F", "Alt-A", at(0, 13));
|
||||
|
||||
sim("moveByExpr", "function foo(a, b) {}",
|
||||
"Ctrl-Alt-F", at(0, 8), "Ctrl-Alt-F", at(0, 12), "Ctrl-Alt-F", at(0, 18),
|
||||
"Ctrl-Alt-B", at(0, 12), "Ctrl-Alt-B", at(0, 9));
|
||||
sim("moveByExprMulti", "foo bar baz bug",
|
||||
"Ctrl-2", "Ctrl-Alt-F", at(0, 7),
|
||||
"Ctrl--", "Ctrl-Alt-F", at(0, 4),
|
||||
"Ctrl--", "Ctrl-2", "Ctrl-Alt-B", at(0, 11));
|
||||
sim("delExpr", "var x = [\n a,\n b\n c\n];",
|
||||
Pos(0, 8), "Ctrl-Alt-K", txt("var x = ;"), "Ctrl-/",
|
||||
Pos(4, 1), "Ctrl-Alt-Backspace", txt("var x = ;"));
|
||||
sim("delExprMulti", "foo bar baz",
|
||||
"Ctrl-2", "Ctrl-Alt-K", txt(" baz"),
|
||||
"Ctrl-/", "Ctrl-E", "Ctrl-2", "Ctrl-Alt-Backspace", txt("foo "));
|
||||
|
||||
sim("justOneSpace", "hi bye ",
|
||||
Pos(0, 4), "Alt-Space", txt("hi bye "),
|
||||
Pos(0, 4), "Alt-Space", txt("hi b ye "),
|
||||
"Ctrl-A", "Alt-Space", "Ctrl-E", "Alt-Space", txt(" hi b ye "));
|
||||
|
||||
sim("openLine", "foo bar", "Alt-F", "Ctrl-O", txt("foo\n bar"))
|
||||
|
||||
sim("transposeChar", "abcd\n\ne",
|
||||
"Ctrl-F", "Ctrl-T", "Ctrl-T", txt("bcad\n\ne"), at(0, 3),
|
||||
"Ctrl-F", "Ctrl-T", "Ctrl-T", "Ctrl-T", txt("bcda\n\ne"), at(0, 4),
|
||||
"Ctrl-F", "Ctrl-T", txt("bcd\na\ne"), at(1, 1));
|
||||
|
||||
sim("manipWordCase", "foo BAR bAZ",
|
||||
"Alt-C", "Alt-L", "Alt-U", txt("Foo bar BAZ"),
|
||||
"Ctrl-A", "Alt-U", "Alt-L", "Alt-C", txt("FOO bar Baz"));
|
||||
sim("manipWordCaseMulti", "foo Bar bAz",
|
||||
"Ctrl-2", "Alt-U", txt("FOO BAR bAz"),
|
||||
"Ctrl-A", "Ctrl-3", "Alt-C", txt("Foo Bar Baz"));
|
||||
|
||||
sim("upExpr", "foo {\n bar[];\n baz(blah);\n}",
|
||||
Pos(2, 7), "Ctrl-Alt-U", at(2, 5), "Ctrl-Alt-U", at(0, 4));
|
||||
sim("transposeExpr", "do foo[bar] dah",
|
||||
Pos(0, 6), "Ctrl-Alt-T", txt("do [bar]foo dah"));
|
||||
|
||||
sim("clearMark", "abcde", Pos(0, 2), "Ctrl-Space", "Ctrl-F", "Ctrl-F",
|
||||
"Ctrl-G", "Ctrl-W", txt("abcde"));
|
||||
|
||||
testCM("save", function(cm) {
|
||||
var saved = false;
|
||||
CodeMirror.commands.save = function(cm) { saved = cm.getValue(); };
|
||||
cm.triggerOnKeyDown(fakeEvent("Ctrl-X"));
|
||||
cm.triggerOnKeyDown(fakeEvent("Ctrl-S"));
|
||||
is(saved, "hi");
|
||||
}, {value: "hi", keyMap: "emacs"});
|
||||
})();
|
224
public/filemanager/scripts/CodeMirror/test/index.html
Normal file
224
public/filemanager/scripts/CodeMirror/test/index.html
Normal file
@@ -0,0 +1,224 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Test Suite</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<link rel="stylesheet" href="mode_test.css">
|
||||
<script src="../doc/activebookmark.js"></script>
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../addon/mode/overlay.js"></script>
|
||||
<script src="../addon/mode/multiplex.js"></script>
|
||||
<script src="../addon/search/searchcursor.js"></script>
|
||||
<script src="../addon/dialog/dialog.js"></script>
|
||||
<script src="../addon/edit/matchbrackets.js"></script>
|
||||
<script src="../addon/comment/comment.js"></script>
|
||||
<script src="../mode/javascript/javascript.js"></script>
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<script src="../keymap/vim.js"></script>
|
||||
<script src="../keymap/emacs.js"></script>
|
||||
<script src="../keymap/sublime.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>
|
||||
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Test suite</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Test Suite</h2>
|
||||
|
||||
<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="driver.js"></script>
|
||||
<script src="test.js"></script>
|
||||
<script src="doc_test.js"></script>
|
||||
<script src="multi_test.js"></script>
|
||||
<script src="comment_test.js"></script>
|
||||
<script src="search_test.js"></script>
|
||||
<script src="mode_test.js"></script>
|
||||
<script src="../mode/javascript/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/css/less_test.js"></script>
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<script src="../mode/xml/test.js"></script>
|
||||
<script src="../mode/htmlmixed/htmlmixed.js"></script>
|
||||
<script src="../mode/ruby/ruby.js"></script>
|
||||
<script src="../mode/ruby/test.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 src="vim_test.js"></script>
|
||||
<script src="emacs_test.js"></script>
|
||||
<script src="sublime_test.js"></script>
|
||||
<script>
|
||||
window.onload = runHarness;
|
||||
CodeMirror.on(window, 'hashchange', runHarness);
|
||||
|
||||
function esc(str) {
|
||||
return str.replace(/[<&]/, function(ch) { return ch == "<" ? "<" : "&"; });
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
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 (verbose && !customMessage) customMessage = message;
|
||||
setStatus(message, type);
|
||||
if (customMessage && customMessage.length > 0) {
|
||||
addOutput(name, type, customMessage);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
</article>
|
1782
public/filemanager/scripts/CodeMirror/test/lint/acorn.js
vendored
Normal file
1782
public/filemanager/scripts/CodeMirror/test/lint/acorn.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
161
public/filemanager/scripts/CodeMirror/test/lint/lint.js
vendored
Normal file
161
public/filemanager/scripts/CodeMirror/test/lint/lint.js
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
Simple linter, based on the Acorn [1] parser module
|
||||
|
||||
All of the existing linters either cramp my style or have huge
|
||||
dependencies (Closure). So here's a very simple, non-invasive one
|
||||
that only spots
|
||||
|
||||
- missing semicolons and trailing commas
|
||||
- variables or properties that are reserved words
|
||||
- assigning to a variable you didn't declare
|
||||
- access to non-whitelisted globals
|
||||
(use a '// declare global: foo, bar' comment to declare extra
|
||||
globals in a file)
|
||||
|
||||
[1]: https://github.com/marijnh/acorn/
|
||||
*/
|
||||
|
||||
var topAllowedGlobals = Object.create(null);
|
||||
("Error RegExp Number String Array Function Object Math Date undefined " +
|
||||
"parseInt parseFloat Infinity NaN isNaN " +
|
||||
"window document navigator prompt alert confirm console " +
|
||||
"FileReader Worker postMessage importScripts " +
|
||||
"setInterval clearInterval setTimeout clearTimeout " +
|
||||
"CodeMirror " +
|
||||
"test exports require module define")
|
||||
.split(" ").forEach(function(n) { topAllowedGlobals[n] = true; });
|
||||
|
||||
var fs = require("fs"), acorn = require("./acorn.js"), walk = require("./walk.js");
|
||||
|
||||
var scopePasser = walk.make({
|
||||
ScopeBody: function(node, prev, c) { c(node, node.scope); }
|
||||
});
|
||||
|
||||
function checkFile(fileName) {
|
||||
var file = fs.readFileSync(fileName, "utf8"), notAllowed;
|
||||
if (notAllowed = file.match(/[\x00-\x08\x0b\x0c\x0e-\x19\uFEFF\t]|[ \t]\n/)) {
|
||||
var msg;
|
||||
if (notAllowed[0] == "\t") msg = "Found tab character";
|
||||
else if (notAllowed[0].indexOf("\n") > -1) msg = "Trailing whitespace";
|
||||
else msg = "Undesirable character " + notAllowed[0].charCodeAt(0);
|
||||
var info = acorn.getLineInfo(file, notAllowed.index);
|
||||
fail(msg + " at line " + info.line + ", column " + info.column, {source: fileName});
|
||||
}
|
||||
|
||||
var globalsSeen = Object.create(null);
|
||||
|
||||
try {
|
||||
var parsed = acorn.parse(file, {
|
||||
locations: true,
|
||||
ecmaVersion: 3,
|
||||
strictSemicolons: true,
|
||||
allowTrailingCommas: false,
|
||||
forbidReserved: "everywhere",
|
||||
sourceFile: fileName
|
||||
});
|
||||
} catch (e) {
|
||||
fail(e.message, {source: fileName});
|
||||
return;
|
||||
}
|
||||
|
||||
var scopes = [];
|
||||
|
||||
walk.simple(parsed, {
|
||||
ScopeBody: function(node, scope) {
|
||||
node.scope = scope;
|
||||
scopes.push(scope);
|
||||
}
|
||||
}, walk.scopeVisitor, {vars: Object.create(null)});
|
||||
|
||||
var ignoredGlobals = Object.create(null);
|
||||
|
||||
function inScope(name, scope) {
|
||||
for (var cur = scope; cur; cur = cur.prev)
|
||||
if (name in cur.vars) return true;
|
||||
}
|
||||
function checkLHS(node, scope) {
|
||||
if (node.type == "Identifier" && !(node.name in ignoredGlobals) &&
|
||||
!inScope(node.name, scope)) {
|
||||
ignoredGlobals[node.name] = true;
|
||||
fail("Assignment to global variable", node.loc);
|
||||
}
|
||||
}
|
||||
|
||||
walk.simple(parsed, {
|
||||
UpdateExpression: function(node, scope) {checkLHS(node.argument, scope);},
|
||||
AssignmentExpression: function(node, scope) {checkLHS(node.left, scope);},
|
||||
Identifier: function(node, scope) {
|
||||
if (node.name == "arguments") return;
|
||||
// Mark used identifiers
|
||||
for (var cur = scope; cur; cur = cur.prev)
|
||||
if (node.name in cur.vars) {
|
||||
cur.vars[node.name].used = true;
|
||||
return;
|
||||
}
|
||||
globalsSeen[node.name] = node.loc;
|
||||
},
|
||||
FunctionExpression: function(node) {
|
||||
if (node.id) fail("Named function expression", node.loc);
|
||||
},
|
||||
ForStatement: function(node) {
|
||||
checkReusedIndex(node);
|
||||
},
|
||||
MemberExpression: function(node) {
|
||||
if (node.object.type == "Identifier" && node.object.name == "console" && !node.computed)
|
||||
fail("Found console." + node.property.name, node.loc);
|
||||
},
|
||||
DebuggerStatement: function(node) {
|
||||
fail("Found debugger statement", node.loc);
|
||||
}
|
||||
}, scopePasser);
|
||||
|
||||
function checkReusedIndex(node) {
|
||||
if (!node.init || node.init.type != "VariableDeclaration") return;
|
||||
var name = node.init.declarations[0].id.name;
|
||||
walk.recursive(node.body, null, {
|
||||
Function: function() {},
|
||||
VariableDeclaration: function(node, st, c) {
|
||||
for (var i = 0; i < node.declarations.length; i++)
|
||||
if (node.declarations[i].id.name == name)
|
||||
fail("redefined loop variable", node.declarations[i].id.loc);
|
||||
walk.base.VariableDeclaration(node, st, c);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var allowedGlobals = Object.create(topAllowedGlobals), m;
|
||||
if (m = file.match(/\/\/ declare global:\s+(.*)/))
|
||||
m[1].split(/,\s*/g).forEach(function(n) { allowedGlobals[n] = true; });
|
||||
for (var glob in globalsSeen)
|
||||
if (!(glob in allowedGlobals))
|
||||
fail("Access to global variable " + glob + ". Add a '// declare global: " + glob +
|
||||
"' comment or add this variable in test/lint/lint.js.", globalsSeen[glob]);
|
||||
|
||||
for (var i = 0; i < scopes.length; ++i) {
|
||||
var scope = scopes[i];
|
||||
for (var name in scope.vars) {
|
||||
var info = scope.vars[name];
|
||||
if (!info.used && info.type != "catch clause" && info.type != "function name" && name.charAt(0) != "_")
|
||||
fail("Unused " + info.type + " " + name, info.node.loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var failed = false;
|
||||
function fail(msg, pos) {
|
||||
if (pos.start) msg += " (" + pos.start.line + ":" + pos.start.column + ")";
|
||||
console.log(pos.source + ": " + msg);
|
||||
failed = true;
|
||||
}
|
||||
|
||||
function checkDir(dir) {
|
||||
fs.readdirSync(dir).forEach(function(file) {
|
||||
var fname = dir + "/" + file;
|
||||
if (/\.js$/.test(file)) checkFile(fname);
|
||||
else if (file != "dep" && fs.lstatSync(fname).isDirectory()) checkDir(fname);
|
||||
});
|
||||
}
|
||||
|
||||
exports.checkDir = checkDir;
|
||||
exports.checkFile = checkFile;
|
||||
exports.success = function() { return !failed; };
|
313
public/filemanager/scripts/CodeMirror/test/lint/walk.js
vendored
Normal file
313
public/filemanager/scripts/CodeMirror/test/lint/walk.js
vendored
Normal file
@@ -0,0 +1,313 @@
|
||||
// AST walker module for Mozilla Parser API compatible trees
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") return mod(exports); // CommonJS
|
||||
if (typeof define == "function" && define.amd) return define(["exports"], mod); // AMD
|
||||
mod((this.acorn || (this.acorn = {})).walk = {}); // Plain browser env
|
||||
})(function(exports) {
|
||||
"use strict";
|
||||
|
||||
// A simple walk is one where you simply specify callbacks to be
|
||||
// called on specific nodes. The last two arguments are optional. A
|
||||
// simple use would be
|
||||
//
|
||||
// walk.simple(myTree, {
|
||||
// Expression: function(node) { ... }
|
||||
// });
|
||||
//
|
||||
// to do something with all expressions. All Parser API node types
|
||||
// can be used to identify node types, as well as Expression,
|
||||
// Statement, and ScopeBody, which denote categories of nodes.
|
||||
//
|
||||
// The base argument can be used to pass a custom (recursive)
|
||||
// walker, and state can be used to give this walked an initial
|
||||
// state.
|
||||
exports.simple = function(node, visitors, base, state) {
|
||||
if (!base) base = exports.base;
|
||||
function c(node, st, override) {
|
||||
var type = override || node.type, found = visitors[type];
|
||||
base[type](node, st, c);
|
||||
if (found) found(node, st);
|
||||
}
|
||||
c(node, state);
|
||||
};
|
||||
|
||||
// A recursive walk is one where your functions override the default
|
||||
// walkers. They can modify and replace the state parameter that's
|
||||
// threaded through the walk, and can opt how and whether to walk
|
||||
// their child nodes (by calling their third argument on these
|
||||
// nodes).
|
||||
exports.recursive = function(node, state, funcs, base) {
|
||||
var visitor = funcs ? exports.make(funcs, base) : base;
|
||||
function c(node, st, override) {
|
||||
visitor[override || node.type](node, st, c);
|
||||
}
|
||||
c(node, state);
|
||||
};
|
||||
|
||||
function makeTest(test) {
|
||||
if (typeof test == "string")
|
||||
return function(type) { return type == test; };
|
||||
else if (!test)
|
||||
return function() { return true; };
|
||||
else
|
||||
return test;
|
||||
}
|
||||
|
||||
function Found(node, state) { this.node = node; this.state = state; }
|
||||
|
||||
// Find a node with a given start, end, and type (all are optional,
|
||||
// null can be used as wildcard). Returns a {node, state} object, or
|
||||
// undefined when it doesn't find a matching node.
|
||||
exports.findNodeAt = function(node, start, end, test, base, state) {
|
||||
test = makeTest(test);
|
||||
try {
|
||||
if (!base) base = exports.base;
|
||||
var c = function(node, st, override) {
|
||||
var type = override || node.type;
|
||||
if ((start == null || node.start <= start) &&
|
||||
(end == null || node.end >= end))
|
||||
base[type](node, st, c);
|
||||
if (test(type, node) &&
|
||||
(start == null || node.start == start) &&
|
||||
(end == null || node.end == end))
|
||||
throw new Found(node, st);
|
||||
};
|
||||
c(node, state);
|
||||
} catch (e) {
|
||||
if (e instanceof Found) return e;
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
// Find the innermost node of a given type that contains the given
|
||||
// position. Interface similar to findNodeAt.
|
||||
exports.findNodeAround = function(node, pos, test, base, state) {
|
||||
test = makeTest(test);
|
||||
try {
|
||||
if (!base) base = exports.base;
|
||||
var c = function(node, st, override) {
|
||||
var type = override || node.type;
|
||||
if (node.start > pos || node.end < pos) return;
|
||||
base[type](node, st, c);
|
||||
if (test(type, node)) throw new Found(node, st);
|
||||
};
|
||||
c(node, state);
|
||||
} catch (e) {
|
||||
if (e instanceof Found) return e;
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
// Find the outermost matching node after a given position.
|
||||
exports.findNodeAfter = function(node, pos, test, base, state) {
|
||||
test = makeTest(test);
|
||||
try {
|
||||
if (!base) base = exports.base;
|
||||
var c = function(node, st, override) {
|
||||
if (node.end < pos) return;
|
||||
var type = override || node.type;
|
||||
if (node.start >= pos && test(type, node)) throw new Found(node, st);
|
||||
base[type](node, st, c);
|
||||
};
|
||||
c(node, state);
|
||||
} catch (e) {
|
||||
if (e instanceof Found) return e;
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
// Find the outermost matching node before a given position.
|
||||
exports.findNodeBefore = function(node, pos, test, base, state) {
|
||||
test = makeTest(test);
|
||||
if (!base) base = exports.base;
|
||||
var max;
|
||||
var c = function(node, st, override) {
|
||||
if (node.start > pos) return;
|
||||
var type = override || node.type;
|
||||
if (node.end <= pos && (!max || max.node.end < node.end) && test(type, node))
|
||||
max = new Found(node, st);
|
||||
base[type](node, st, c);
|
||||
};
|
||||
c(node, state);
|
||||
return max;
|
||||
};
|
||||
|
||||
// Used to create a custom walker. Will fill in all missing node
|
||||
// type properties with the defaults.
|
||||
exports.make = function(funcs, base) {
|
||||
if (!base) base = exports.base;
|
||||
var visitor = {};
|
||||
for (var type in base) visitor[type] = base[type];
|
||||
for (var type in funcs) visitor[type] = funcs[type];
|
||||
return visitor;
|
||||
};
|
||||
|
||||
function skipThrough(node, st, c) { c(node, st); }
|
||||
function ignore(_node, _st, _c) {}
|
||||
|
||||
// Node walkers.
|
||||
|
||||
var base = exports.base = {};
|
||||
base.Program = base.BlockStatement = function(node, st, c) {
|
||||
for (var i = 0; i < node.body.length; ++i)
|
||||
c(node.body[i], st, "Statement");
|
||||
};
|
||||
base.Statement = skipThrough;
|
||||
base.EmptyStatement = ignore;
|
||||
base.ExpressionStatement = function(node, st, c) {
|
||||
c(node.expression, st, "Expression");
|
||||
};
|
||||
base.IfStatement = function(node, st, c) {
|
||||
c(node.test, st, "Expression");
|
||||
c(node.consequent, st, "Statement");
|
||||
if (node.alternate) c(node.alternate, st, "Statement");
|
||||
};
|
||||
base.LabeledStatement = function(node, st, c) {
|
||||
c(node.body, st, "Statement");
|
||||
};
|
||||
base.BreakStatement = base.ContinueStatement = ignore;
|
||||
base.WithStatement = function(node, st, c) {
|
||||
c(node.object, st, "Expression");
|
||||
c(node.body, st, "Statement");
|
||||
};
|
||||
base.SwitchStatement = function(node, st, c) {
|
||||
c(node.discriminant, st, "Expression");
|
||||
for (var i = 0; i < node.cases.length; ++i) {
|
||||
var cs = node.cases[i];
|
||||
if (cs.test) c(cs.test, st, "Expression");
|
||||
for (var j = 0; j < cs.consequent.length; ++j)
|
||||
c(cs.consequent[j], st, "Statement");
|
||||
}
|
||||
};
|
||||
base.ReturnStatement = function(node, st, c) {
|
||||
if (node.argument) c(node.argument, st, "Expression");
|
||||
};
|
||||
base.ThrowStatement = function(node, st, c) {
|
||||
c(node.argument, st, "Expression");
|
||||
};
|
||||
base.TryStatement = function(node, st, c) {
|
||||
c(node.block, st, "Statement");
|
||||
if (node.handler) c(node.handler.body, st, "ScopeBody");
|
||||
if (node.finalizer) c(node.finalizer, st, "Statement");
|
||||
};
|
||||
base.WhileStatement = function(node, st, c) {
|
||||
c(node.test, st, "Expression");
|
||||
c(node.body, st, "Statement");
|
||||
};
|
||||
base.DoWhileStatement = base.WhileStatement;
|
||||
base.ForStatement = function(node, st, c) {
|
||||
if (node.init) c(node.init, st, "ForInit");
|
||||
if (node.test) c(node.test, st, "Expression");
|
||||
if (node.update) c(node.update, st, "Expression");
|
||||
c(node.body, st, "Statement");
|
||||
};
|
||||
base.ForInStatement = function(node, st, c) {
|
||||
c(node.left, st, "ForInit");
|
||||
c(node.right, st, "Expression");
|
||||
c(node.body, st, "Statement");
|
||||
};
|
||||
base.ForInit = function(node, st, c) {
|
||||
if (node.type == "VariableDeclaration") c(node, st);
|
||||
else c(node, st, "Expression");
|
||||
};
|
||||
base.DebuggerStatement = ignore;
|
||||
|
||||
base.FunctionDeclaration = function(node, st, c) {
|
||||
c(node, st, "Function");
|
||||
};
|
||||
base.VariableDeclaration = function(node, st, c) {
|
||||
for (var i = 0; i < node.declarations.length; ++i) {
|
||||
var decl = node.declarations[i];
|
||||
if (decl.init) c(decl.init, st, "Expression");
|
||||
}
|
||||
};
|
||||
|
||||
base.Function = function(node, st, c) {
|
||||
c(node.body, st, "ScopeBody");
|
||||
};
|
||||
base.ScopeBody = function(node, st, c) {
|
||||
c(node, st, "Statement");
|
||||
};
|
||||
|
||||
base.Expression = skipThrough;
|
||||
base.ThisExpression = ignore;
|
||||
base.ArrayExpression = function(node, st, c) {
|
||||
for (var i = 0; i < node.elements.length; ++i) {
|
||||
var elt = node.elements[i];
|
||||
if (elt) c(elt, st, "Expression");
|
||||
}
|
||||
};
|
||||
base.ObjectExpression = function(node, st, c) {
|
||||
for (var i = 0; i < node.properties.length; ++i)
|
||||
c(node.properties[i].value, st, "Expression");
|
||||
};
|
||||
base.FunctionExpression = base.FunctionDeclaration;
|
||||
base.SequenceExpression = function(node, st, c) {
|
||||
for (var i = 0; i < node.expressions.length; ++i)
|
||||
c(node.expressions[i], st, "Expression");
|
||||
};
|
||||
base.UnaryExpression = base.UpdateExpression = function(node, st, c) {
|
||||
c(node.argument, st, "Expression");
|
||||
};
|
||||
base.BinaryExpression = base.AssignmentExpression = base.LogicalExpression = function(node, st, c) {
|
||||
c(node.left, st, "Expression");
|
||||
c(node.right, st, "Expression");
|
||||
};
|
||||
base.ConditionalExpression = function(node, st, c) {
|
||||
c(node.test, st, "Expression");
|
||||
c(node.consequent, st, "Expression");
|
||||
c(node.alternate, st, "Expression");
|
||||
};
|
||||
base.NewExpression = base.CallExpression = function(node, st, c) {
|
||||
c(node.callee, st, "Expression");
|
||||
if (node.arguments) for (var i = 0; i < node.arguments.length; ++i)
|
||||
c(node.arguments[i], st, "Expression");
|
||||
};
|
||||
base.MemberExpression = function(node, st, c) {
|
||||
c(node.object, st, "Expression");
|
||||
if (node.computed) c(node.property, st, "Expression");
|
||||
};
|
||||
base.Identifier = base.Literal = ignore;
|
||||
|
||||
// A custom walker that keeps track of the scope chain and the
|
||||
// variables defined in it.
|
||||
function makeScope(prev, isCatch) {
|
||||
return {vars: Object.create(null), prev: prev, isCatch: isCatch};
|
||||
}
|
||||
function normalScope(scope) {
|
||||
while (scope.isCatch) scope = scope.prev;
|
||||
return scope;
|
||||
}
|
||||
exports.scopeVisitor = exports.make({
|
||||
Function: function(node, scope, c) {
|
||||
var inner = makeScope(scope);
|
||||
for (var i = 0; i < node.params.length; ++i)
|
||||
inner.vars[node.params[i].name] = {type: "argument", node: node.params[i]};
|
||||
if (node.id) {
|
||||
var decl = node.type == "FunctionDeclaration";
|
||||
(decl ? normalScope(scope) : inner).vars[node.id.name] =
|
||||
{type: decl ? "function" : "function name", node: node.id};
|
||||
}
|
||||
c(node.body, inner, "ScopeBody");
|
||||
},
|
||||
TryStatement: function(node, scope, c) {
|
||||
c(node.block, scope, "Statement");
|
||||
if (node.handler) {
|
||||
var inner = makeScope(scope, true);
|
||||
inner.vars[node.handler.param.name] = {type: "catch clause", node: node.handler.param};
|
||||
c(node.handler.body, inner, "ScopeBody");
|
||||
}
|
||||
if (node.finalizer) c(node.finalizer, scope, "Statement");
|
||||
},
|
||||
VariableDeclaration: function(node, scope, c) {
|
||||
var target = normalScope(scope);
|
||||
for (var i = 0; i < node.declarations.length; ++i) {
|
||||
var decl = node.declarations[i];
|
||||
target.vars[decl.id.name] = {type: "var", node: decl.id};
|
||||
if (decl.init) c(decl.init, scope, "Expression");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
10
public/filemanager/scripts/CodeMirror/test/mode_test.css
vendored
Normal file
10
public/filemanager/scripts/CodeMirror/test/mode_test.css
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
.mt-output .mt-token {
|
||||
border: 1px solid #ddd;
|
||||
white-space: pre;
|
||||
font-family: "Consolas", monospace;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.mt-output .mt-style {
|
||||
font-size: x-small;
|
||||
}
|
168
public/filemanager/scripts/CodeMirror/test/mode_test.js
vendored
Normal file
168
public/filemanager/scripts/CodeMirror/test/mode_test.js
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
/**
|
||||
* Helper to test CodeMirror highlighting modes. It pretty prints output of the
|
||||
* highlighter and can check against expected styles.
|
||||
*
|
||||
* Mode tests are registered by calling test.mode(testName, mode,
|
||||
* tokens), where mode is a mode object as returned by
|
||||
* CodeMirror.getMode, and tokens is an array of lines that make up
|
||||
* the test.
|
||||
*
|
||||
* These lines are strings, in which styled stretches of code are
|
||||
* enclosed in brackets `[]`, and prefixed by their style. For
|
||||
* example, `[keyword if]`. Brackets in the code itself must be
|
||||
* duplicated to prevent them from being interpreted as token
|
||||
* boundaries. For example `a[[i]]` for `a[i]`. If a token has
|
||||
* multiple styles, the styles must be separated by ampersands, for
|
||||
* example `[tag&error </hmtl>]`.
|
||||
*
|
||||
* See the test.js files in the css, markdown, gfm, and stex mode
|
||||
* directories for examples.
|
||||
*/
|
||||
(function() {
|
||||
function findSingle(str, pos, ch) {
|
||||
for (;;) {
|
||||
var found = str.indexOf(ch, pos);
|
||||
if (found == -1) return null;
|
||||
if (str.charAt(found + 1) != ch) return found;
|
||||
pos = found + 2;
|
||||
}
|
||||
}
|
||||
|
||||
var styleName = /[\w&-_]+/g;
|
||||
function parseTokens(strs) {
|
||||
var tokens = [], plain = "";
|
||||
for (var i = 0; i < strs.length; ++i) {
|
||||
if (i) plain += "\n";
|
||||
var str = strs[i], pos = 0;
|
||||
while (pos < str.length) {
|
||||
var style = null, text;
|
||||
if (str.charAt(pos) == "[" && str.charAt(pos+1) != "[") {
|
||||
styleName.lastIndex = pos + 1;
|
||||
var m = styleName.exec(str);
|
||||
style = m[0].replace(/&/g, " ");
|
||||
var textStart = pos + style.length + 2;
|
||||
var end = findSingle(str, textStart, "]");
|
||||
if (end == null) throw new Error("Unterminated token at " + pos + " in '" + str + "'" + style);
|
||||
text = str.slice(textStart, end);
|
||||
pos = end + 1;
|
||||
} else {
|
||||
var end = findSingle(str, pos, "[");
|
||||
if (end == null) end = str.length;
|
||||
text = str.slice(pos, end);
|
||||
pos = end;
|
||||
}
|
||||
text = text.replace(/\[\[|\]\]/g, function(s) {return s.charAt(0);});
|
||||
tokens.push(style, text);
|
||||
plain += text;
|
||||
}
|
||||
}
|
||||
return {tokens: tokens, plain: plain};
|
||||
}
|
||||
|
||||
test.mode = function(name, mode, tokens, modeName) {
|
||||
var data = parseTokens(tokens);
|
||||
return test((modeName || mode.name) + "_" + name, function() {
|
||||
return compare(data.plain, data.tokens, mode);
|
||||
});
|
||||
};
|
||||
|
||||
function esc(str) {
|
||||
return str.replace('&', '&').replace('<', '<');
|
||||
}
|
||||
|
||||
function compare(text, expected, mode) {
|
||||
|
||||
var expectedOutput = [];
|
||||
for (var i = 0; i < expected.length; i += 2) {
|
||||
var sty = expected[i];
|
||||
if (sty && sty.indexOf(" ")) sty = sty.split(' ').sort().join(' ');
|
||||
expectedOutput.push(sty, expected[i + 1]);
|
||||
}
|
||||
|
||||
var observedOutput = highlight(text, mode);
|
||||
|
||||
var s = "";
|
||||
var diff = highlightOutputsDifferent(expectedOutput, observedOutput);
|
||||
if (diff != null) {
|
||||
s += '<div class="mt-test mt-fail">';
|
||||
s += '<pre>' + esc(text) + '</pre>';
|
||||
s += '<div class="cm-s-default">';
|
||||
s += 'expected:';
|
||||
s += prettyPrintOutputTable(expectedOutput, diff);
|
||||
s += 'observed:';
|
||||
s += prettyPrintOutputTable(observedOutput, diff);
|
||||
s += '</div>';
|
||||
s += '</div>';
|
||||
}
|
||||
if (observedOutput.indentFailures) {
|
||||
for (var i = 0; i < observedOutput.indentFailures.length; i++)
|
||||
s += "<div class='mt-test mt-fail'>" + esc(observedOutput.indentFailures[i]) + "</div>";
|
||||
}
|
||||
if (s) throw new Failure(s);
|
||||
}
|
||||
|
||||
function highlight(string, mode) {
|
||||
var state = mode.startState()
|
||||
|
||||
var lines = string.replace(/\r\n/g,'\n').split('\n');
|
||||
var st = [], pos = 0;
|
||||
for (var i = 0; i < lines.length; ++i) {
|
||||
var line = lines[i], newLine = true;
|
||||
if (mode.indent) {
|
||||
var ws = line.match(/^\s*/)[0];
|
||||
var indent = mode.indent(state, line.slice(ws.length));
|
||||
if (indent != CodeMirror.Pass && indent != ws.length)
|
||||
(st.indentFailures || (st.indentFailures = [])).push(
|
||||
"Indentation of line " + (i + 1) + " is " + indent + " (expected " + ws.length + ")");
|
||||
}
|
||||
var stream = new CodeMirror.StringStream(line);
|
||||
if (line == "" && mode.blankLine) mode.blankLine(state);
|
||||
/* Start copied code from CodeMirror.highlight */
|
||||
while (!stream.eol()) {
|
||||
var compare = mode.token(stream, state), substr = stream.current();
|
||||
if (compare && compare.indexOf(" ") > -1) compare = compare.split(' ').sort().join(' ');
|
||||
stream.start = stream.pos;
|
||||
if (pos && st[pos-2] == compare && !newLine) {
|
||||
st[pos-1] += substr;
|
||||
} else if (substr) {
|
||||
st[pos++] = compare; st[pos++] = substr;
|
||||
}
|
||||
// Give up when line is ridiculously long
|
||||
if (stream.pos > 5000) {
|
||||
st[pos++] = null; st[pos++] = this.text.slice(stream.pos);
|
||||
break;
|
||||
}
|
||||
newLine = false;
|
||||
}
|
||||
}
|
||||
|
||||
return st;
|
||||
}
|
||||
|
||||
function highlightOutputsDifferent(o1, o2) {
|
||||
var minLen = Math.min(o1.length, o2.length);
|
||||
for (var i = 0; i < minLen; ++i)
|
||||
if (o1[i] != o2[i]) return i >> 1;
|
||||
if (o1.length > minLen || o2.length > minLen) return minLen;
|
||||
}
|
||||
|
||||
function prettyPrintOutputTable(output, diffAt) {
|
||||
var s = '<table class="mt-output">';
|
||||
s += '<tr>';
|
||||
for (var i = 0; i < output.length; i += 2) {
|
||||
var style = output[i], val = output[i+1];
|
||||
s +=
|
||||
'<td class="mt-token"' + (i == diffAt * 2 ? " style='background: pink'" : "") + '>' +
|
||||
'<span class="cm-' + esc(String(style)) + '">' +
|
||||
esc(val.replace(/ /g,'\xb7')) +
|
||||
'</span>' +
|
||||
'</td>';
|
||||
}
|
||||
s += '</tr><tr>';
|
||||
for (var i = 0; i < output.length; i += 2) {
|
||||
s += '<td class="mt-style"><span>' + (output[i] || null) + '</span></td>';
|
||||
}
|
||||
s += '</table>';
|
||||
return s;
|
||||
}
|
||||
})();
|
285
public/filemanager/scripts/CodeMirror/test/multi_test.js
vendored
Normal file
285
public/filemanager/scripts/CodeMirror/test/multi_test.js
vendored
Normal file
@@ -0,0 +1,285 @@
|
||||
(function() {
|
||||
namespace = "multi_";
|
||||
|
||||
function hasSelections(cm) {
|
||||
var sels = cm.listSelections();
|
||||
var given = (arguments.length - 1) / 4;
|
||||
if (sels.length != given)
|
||||
throw new Failure("expected " + given + " selections, found " + sels.length);
|
||||
for (var i = 0, p = 1; i < given; i++, p += 4) {
|
||||
var anchor = Pos(arguments[p], arguments[p + 1]);
|
||||
var head = Pos(arguments[p + 2], arguments[p + 3]);
|
||||
eqPos(sels[i].anchor, anchor, "anchor of selection " + i);
|
||||
eqPos(sels[i].head, head, "head of selection " + i);
|
||||
}
|
||||
}
|
||||
function hasCursors(cm) {
|
||||
var sels = cm.listSelections();
|
||||
var given = (arguments.length - 1) / 2;
|
||||
if (sels.length != given)
|
||||
throw new Failure("expected " + given + " selections, found " + sels.length);
|
||||
for (var i = 0, p = 1; i < given; i++, p += 2) {
|
||||
eqPos(sels[i].anchor, sels[i].head, "something selected for " + i);
|
||||
var head = Pos(arguments[p], arguments[p + 1]);
|
||||
eqPos(sels[i].head, head, "selection " + i);
|
||||
}
|
||||
}
|
||||
|
||||
testCM("getSelection", function(cm) {
|
||||
select(cm, {anchor: Pos(0, 0), head: Pos(1, 2)}, {anchor: Pos(2, 2), head: Pos(2, 0)});
|
||||
eq(cm.getSelection(), "1234\n56\n90");
|
||||
eq(cm.getSelection(false).join("|"), "1234|56|90");
|
||||
eq(cm.getSelections().join("|"), "1234\n56|90");
|
||||
}, {value: "1234\n5678\n90"});
|
||||
|
||||
testCM("setSelection", function(cm) {
|
||||
select(cm, Pos(3, 0), Pos(0, 0), {anchor: Pos(2, 5), head: Pos(1, 0)});
|
||||
hasSelections(cm, 0, 0, 0, 0,
|
||||
2, 5, 1, 0,
|
||||
3, 0, 3, 0);
|
||||
cm.setSelection(Pos(1, 2), Pos(1, 1));
|
||||
hasSelections(cm, 1, 2, 1, 1);
|
||||
select(cm, {anchor: Pos(1, 1), head: Pos(2, 4)},
|
||||
{anchor: Pos(0, 0), head: Pos(1, 3)},
|
||||
Pos(3, 0), Pos(2, 2));
|
||||
hasSelections(cm, 0, 0, 2, 4,
|
||||
3, 0, 3, 0);
|
||||
cm.setSelections([{anchor: Pos(0, 1), head: Pos(0, 2)},
|
||||
{anchor: Pos(1, 1), head: Pos(1, 2)},
|
||||
{anchor: Pos(2, 1), head: Pos(2, 2)}], 1);
|
||||
eqPos(cm.getCursor("head"), Pos(1, 2));
|
||||
eqPos(cm.getCursor("anchor"), Pos(1, 1));
|
||||
eqPos(cm.getCursor("from"), Pos(1, 1));
|
||||
eqPos(cm.getCursor("to"), Pos(1, 2));
|
||||
cm.setCursor(Pos(1, 1));
|
||||
hasCursors(cm, 1, 1);
|
||||
}, {value: "abcde\nabcde\nabcde\n"});
|
||||
|
||||
testCM("somethingSelected", function(cm) {
|
||||
select(cm, Pos(0, 1), {anchor: Pos(0, 3), head: Pos(0, 5)});
|
||||
eq(cm.somethingSelected(), true);
|
||||
select(cm, Pos(0, 1), Pos(0, 3), Pos(0, 5));
|
||||
eq(cm.somethingSelected(), false);
|
||||
}, {value: "123456789"});
|
||||
|
||||
testCM("extendSelection", function(cm) {
|
||||
select(cm, Pos(0, 1), Pos(1, 1), Pos(2, 1));
|
||||
cm.setExtending(true);
|
||||
cm.extendSelections([Pos(0, 2), Pos(1, 0), Pos(2, 3)]);
|
||||
hasSelections(cm, 0, 1, 0, 2,
|
||||
1, 1, 1, 0,
|
||||
2, 1, 2, 3);
|
||||
cm.extendSelection(Pos(2, 4), Pos(2, 0));
|
||||
hasSelections(cm, 2, 4, 2, 0);
|
||||
}, {value: "1234\n1234\n1234"});
|
||||
|
||||
testCM("addSelection", function(cm) {
|
||||
select(cm, Pos(0, 1), Pos(1, 1));
|
||||
cm.addSelection(Pos(0, 0), Pos(0, 4));
|
||||
hasSelections(cm, 0, 0, 0, 4,
|
||||
1, 1, 1, 1);
|
||||
cm.addSelection(Pos(2, 2));
|
||||
hasSelections(cm, 0, 0, 0, 4,
|
||||
1, 1, 1, 1,
|
||||
2, 2, 2, 2);
|
||||
}, {value: "1234\n1234\n1234"});
|
||||
|
||||
testCM("replaceSelection", function(cm) {
|
||||
var selections = [{anchor: Pos(0, 0), head: Pos(0, 1)},
|
||||
{anchor: Pos(0, 2), head: Pos(0, 3)},
|
||||
{anchor: Pos(0, 4), head: Pos(0, 5)},
|
||||
{anchor: Pos(2, 1), head: Pos(2, 4)},
|
||||
{anchor: Pos(2, 5), head: Pos(2, 6)}];
|
||||
var val = "123456\n123456\n123456";
|
||||
cm.setValue(val);
|
||||
cm.setSelections(selections);
|
||||
cm.replaceSelection("ab", "around");
|
||||
eq(cm.getValue(), "ab2ab4ab6\n123456\n1ab5ab");
|
||||
hasSelections(cm, 0, 0, 0, 2,
|
||||
0, 3, 0, 5,
|
||||
0, 6, 0, 8,
|
||||
2, 1, 2, 3,
|
||||
2, 4, 2, 6);
|
||||
cm.setValue(val);
|
||||
cm.setSelections(selections);
|
||||
cm.replaceSelection("", "around");
|
||||
eq(cm.getValue(), "246\n123456\n15");
|
||||
hasSelections(cm, 0, 0, 0, 0,
|
||||
0, 1, 0, 1,
|
||||
0, 2, 0, 2,
|
||||
2, 1, 2, 1,
|
||||
2, 2, 2, 2);
|
||||
cm.setValue(val);
|
||||
cm.setSelections(selections);
|
||||
cm.replaceSelection("X\nY\nZ", "around");
|
||||
hasSelections(cm, 0, 0, 2, 1,
|
||||
2, 2, 4, 1,
|
||||
4, 2, 6, 1,
|
||||
8, 1, 10, 1,
|
||||
10, 2, 12, 1);
|
||||
cm.replaceSelection("a", "around");
|
||||
hasSelections(cm, 0, 0, 0, 1,
|
||||
0, 2, 0, 3,
|
||||
0, 4, 0, 5,
|
||||
2, 1, 2, 2,
|
||||
2, 3, 2, 4);
|
||||
cm.replaceSelection("xy", "start");
|
||||
hasSelections(cm, 0, 0, 0, 0,
|
||||
0, 3, 0, 3,
|
||||
0, 6, 0, 6,
|
||||
2, 1, 2, 1,
|
||||
2, 4, 2, 4);
|
||||
cm.replaceSelection("z\nf");
|
||||
hasSelections(cm, 1, 1, 1, 1,
|
||||
2, 1, 2, 1,
|
||||
3, 1, 3, 1,
|
||||
6, 1, 6, 1,
|
||||
7, 1, 7, 1);
|
||||
eq(cm.getValue(), "z\nfxy2z\nfxy4z\nfxy6\n123456\n1z\nfxy5z\nfxy");
|
||||
});
|
||||
|
||||
function select(cm) {
|
||||
var sels = [];
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var arg = arguments[i];
|
||||
if (arg.head) sels.push(arg);
|
||||
else sels.push({head: arg, anchor: arg});
|
||||
}
|
||||
cm.setSelections(sels, sels.length - 1);
|
||||
}
|
||||
|
||||
testCM("indentSelection", function(cm) {
|
||||
select(cm, Pos(0, 1), Pos(1, 1));
|
||||
cm.indentSelection(4);
|
||||
eq(cm.getValue(), " foo\n bar\nbaz");
|
||||
|
||||
select(cm, Pos(0, 2), Pos(0, 3), Pos(0, 4));
|
||||
cm.indentSelection(-2);
|
||||
eq(cm.getValue(), " foo\n bar\nbaz");
|
||||
|
||||
select(cm, {anchor: Pos(0, 0), head: Pos(1, 2)},
|
||||
{anchor: Pos(1, 3), head: Pos(2, 0)});
|
||||
cm.indentSelection(-2);
|
||||
eq(cm.getValue(), "foo\n bar\nbaz");
|
||||
}, {value: "foo\nbar\nbaz"});
|
||||
|
||||
testCM("killLine", function(cm) {
|
||||
select(cm, Pos(0, 1), Pos(0, 2), Pos(1, 1));
|
||||
cm.execCommand("killLine");
|
||||
eq(cm.getValue(), "f\nb\nbaz");
|
||||
cm.execCommand("killLine");
|
||||
eq(cm.getValue(), "fbbaz");
|
||||
cm.setValue("foo\nbar\nbaz");
|
||||
select(cm, Pos(0, 1), {anchor: Pos(0, 2), head: Pos(2, 1)});
|
||||
cm.execCommand("killLine");
|
||||
eq(cm.getValue(), "faz");
|
||||
}, {value: "foo\nbar\nbaz"});
|
||||
|
||||
testCM("deleteLine", function(cm) {
|
||||
select(cm, Pos(0, 0),
|
||||
{head: Pos(0, 1), anchor: Pos(2, 0)},
|
||||
Pos(4, 0));
|
||||
cm.execCommand("deleteLine");
|
||||
eq(cm.getValue(), "4\n6\n7");
|
||||
select(cm, Pos(2, 1));
|
||||
cm.execCommand("deleteLine");
|
||||
eq(cm.getValue(), "4\n6\n");
|
||||
}, {value: "1\n2\n3\n4\n5\n6\n7"});
|
||||
|
||||
testCM("deleteH", function(cm) {
|
||||
select(cm, Pos(0, 4), {anchor: Pos(1, 4), head: Pos(1, 5)});
|
||||
cm.execCommand("delWordAfter");
|
||||
eq(cm.getValue(), "foo bar baz\nabc ef ghi\n");
|
||||
cm.execCommand("delWordAfter");
|
||||
eq(cm.getValue(), "foo baz\nabc ghi\n");
|
||||
cm.execCommand("delCharBefore");
|
||||
cm.execCommand("delCharBefore");
|
||||
eq(cm.getValue(), "fo baz\nab ghi\n");
|
||||
select(cm, Pos(0, 3), Pos(0, 4), Pos(0, 5));
|
||||
cm.execCommand("delWordAfter");
|
||||
eq(cm.getValue(), "fo \nab ghi\n");
|
||||
}, {value: "foo bar baz\nabc def ghi\n"});
|
||||
|
||||
testCM("goLineStart", function(cm) {
|
||||
select(cm, Pos(0, 2), Pos(0, 3), Pos(1, 1));
|
||||
cm.execCommand("goLineStart");
|
||||
hasCursors(cm, 0, 0, 1, 0);
|
||||
select(cm, Pos(1, 1), Pos(0, 1));
|
||||
cm.setExtending(true);
|
||||
cm.execCommand("goLineStart");
|
||||
hasSelections(cm, 0, 1, 0, 0,
|
||||
1, 1, 1, 0);
|
||||
}, {value: "foo\nbar\nbaz"});
|
||||
|
||||
testCM("moveV", function(cm) {
|
||||
select(cm, Pos(0, 2), Pos(1, 2));
|
||||
cm.execCommand("goLineDown");
|
||||
hasCursors(cm, 1, 2, 2, 2);
|
||||
cm.execCommand("goLineUp");
|
||||
hasCursors(cm, 0, 2, 1, 2);
|
||||
cm.execCommand("goLineUp");
|
||||
hasCursors(cm, 0, 0, 0, 2);
|
||||
cm.execCommand("goLineUp");
|
||||
hasCursors(cm, 0, 0);
|
||||
select(cm, Pos(0, 2), Pos(1, 2));
|
||||
cm.setExtending(true);
|
||||
cm.execCommand("goLineDown");
|
||||
hasSelections(cm, 0, 2, 2, 2);
|
||||
}, {value: "12345\n12345\n12345"});
|
||||
|
||||
testCM("moveH", function(cm) {
|
||||
select(cm, Pos(0, 1), Pos(0, 3), Pos(0, 5), Pos(2, 3));
|
||||
cm.execCommand("goCharRight");
|
||||
hasCursors(cm, 0, 2, 0, 4, 1, 0, 2, 4);
|
||||
cm.execCommand("goCharLeft");
|
||||
hasCursors(cm, 0, 1, 0, 3, 0, 5, 2, 3);
|
||||
for (var i = 0; i < 15; i++)
|
||||
cm.execCommand("goCharRight");
|
||||
hasCursors(cm, 2, 4, 2, 5);
|
||||
}, {value: "12345\n12345\n12345"});
|
||||
|
||||
testCM("newlineAndIndent", function(cm) {
|
||||
select(cm, Pos(0, 5), Pos(1, 5));
|
||||
cm.execCommand("newlineAndIndent");
|
||||
hasCursors(cm, 1, 2, 3, 2);
|
||||
eq(cm.getValue(), "x = [\n 1];\ny = [\n 2];");
|
||||
cm.undo();
|
||||
eq(cm.getValue(), "x = [1];\ny = [2];");
|
||||
hasCursors(cm, 0, 5, 1, 5);
|
||||
select(cm, Pos(0, 5), Pos(0, 6));
|
||||
cm.execCommand("newlineAndIndent");
|
||||
hasCursors(cm, 1, 2, 2, 0);
|
||||
eq(cm.getValue(), "x = [\n 1\n];\ny = [2];");
|
||||
}, {value: "x = [1];\ny = [2];", mode: "javascript"});
|
||||
|
||||
testCM("goDocStartEnd", function(cm) {
|
||||
select(cm, Pos(0, 1), Pos(1, 1));
|
||||
cm.execCommand("goDocStart");
|
||||
hasCursors(cm, 0, 0);
|
||||
select(cm, Pos(0, 1), Pos(1, 1));
|
||||
cm.execCommand("goDocEnd");
|
||||
hasCursors(cm, 1, 3);
|
||||
select(cm, Pos(0, 1), Pos(1, 1));
|
||||
cm.setExtending(true);
|
||||
cm.execCommand("goDocEnd");
|
||||
hasSelections(cm, 1, 1, 1, 3);
|
||||
}, {value: "abc\ndef"});
|
||||
|
||||
testCM("selectionHistory", function(cm) {
|
||||
for (var i = 0; i < 3; ++i)
|
||||
cm.addSelection(Pos(0, i * 2), Pos(0, i * 2 + 1));
|
||||
cm.execCommand("undoSelection");
|
||||
eq(cm.getSelection(), "1\n2");
|
||||
cm.execCommand("undoSelection");
|
||||
eq(cm.getSelection(), "1");
|
||||
cm.execCommand("undoSelection");
|
||||
eq(cm.getSelection(), "");
|
||||
eqPos(cm.getCursor(), Pos(0, 0));
|
||||
cm.execCommand("redoSelection");
|
||||
eq(cm.getSelection(), "1");
|
||||
cm.execCommand("redoSelection");
|
||||
eq(cm.getSelection(), "1\n2");
|
||||
cm.execCommand("redoSelection");
|
||||
eq(cm.getSelection(), "1\n2\n3");
|
||||
}, {value: "1 2 3"});
|
||||
})();
|
31
public/filemanager/scripts/CodeMirror/test/phantom_driver.js
vendored
Normal file
31
public/filemanager/scripts/CodeMirror/test/phantom_driver.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
var page = require('webpage').create();
|
||||
|
||||
page.open("http://localhost:3000/test/index.html", function (status) {
|
||||
if (status != "success") {
|
||||
console.log("page couldn't be loaded successfully");
|
||||
phantom.exit(1);
|
||||
}
|
||||
waitFor(function () {
|
||||
return page.evaluate(function () {
|
||||
var output = document.getElementById('status');
|
||||
if (!output) { return false; }
|
||||
return (/^(\d+ failures?|all passed)/i).test(output.innerText);
|
||||
});
|
||||
}, function () {
|
||||
var failed = page.evaluate(function () { return window.failed; });
|
||||
var output = page.evaluate(function () {
|
||||
return document.getElementById('output').innerText + "\n" +
|
||||
document.getElementById('status').innerText;
|
||||
});
|
||||
console.log(output);
|
||||
phantom.exit(failed > 0 ? 1 : 0);
|
||||
});
|
||||
});
|
||||
|
||||
function waitFor (test, cb) {
|
||||
if (test()) {
|
||||
cb();
|
||||
} else {
|
||||
setTimeout(function () { waitFor(test, cb); }, 250);
|
||||
}
|
||||
}
|
38
public/filemanager/scripts/CodeMirror/test/run.js
vendored
Normal file
38
public/filemanager/scripts/CodeMirror/test/run.js
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var lint = require("./lint/lint");
|
||||
|
||||
lint.checkDir("mode");
|
||||
lint.checkDir("lib");
|
||||
lint.checkDir("addon");
|
||||
lint.checkDir("keymap");
|
||||
|
||||
var ok = lint.success();
|
||||
|
||||
var files = new (require('node-static').Server)();
|
||||
|
||||
var server = require('http').createServer(function (req, res) {
|
||||
req.addListener('end', function () {
|
||||
files.serve(req, res, function (err/*, result */) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}).resume();
|
||||
}).addListener('error', function (err) {
|
||||
throw err;
|
||||
}).listen(3000, function () {
|
||||
var childProcess = require('child_process');
|
||||
var phantomjs = require("phantomjs");
|
||||
var childArgs = [
|
||||
require("path").join(__dirname, 'phantom_driver.js')
|
||||
];
|
||||
childProcess.execFile(phantomjs.path, childArgs, function (err, stdout, stderr) {
|
||||
server.close();
|
||||
console.log(stdout);
|
||||
if (err) console.error(err);
|
||||
if (stderr) console.error(stderr);
|
||||
process.exit(err || stderr || !ok ? 1 : 0);
|
||||
});
|
||||
});
|
62
public/filemanager/scripts/CodeMirror/test/search_test.js
vendored
Normal file
62
public/filemanager/scripts/CodeMirror/test/search_test.js
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
function test(name) {
|
||||
var text = Array.prototype.slice.call(arguments, 1, arguments.length - 1).join("\n");
|
||||
var body = arguments[arguments.length - 1];
|
||||
return window.test("search_" + name, function() {
|
||||
body(new CodeMirror.Doc(text));
|
||||
});
|
||||
}
|
||||
|
||||
function run(doc, query, insensitive) {
|
||||
var cursor = doc.getSearchCursor(query, null, insensitive);
|
||||
for (var i = 3; i < arguments.length; i += 4) {
|
||||
var found = cursor.findNext();
|
||||
is(found, "not enough results (forward)");
|
||||
eqPos(Pos(arguments[i], arguments[i + 1]), cursor.from(), "from, forward, " + (i - 3) / 4);
|
||||
eqPos(Pos(arguments[i + 2], arguments[i + 3]), cursor.to(), "to, forward, " + (i - 3) / 4);
|
||||
}
|
||||
is(!cursor.findNext(), "too many matches (forward)");
|
||||
for (var i = arguments.length - 4; i >= 3; i -= 4) {
|
||||
var found = cursor.findPrevious();
|
||||
is(found, "not enough results (backwards)");
|
||||
eqPos(Pos(arguments[i], arguments[i + 1]), cursor.from(), "from, backwards, " + (i - 3) / 4);
|
||||
eqPos(Pos(arguments[i + 2], arguments[i + 3]), cursor.to(), "to, backwards, " + (i - 3) / 4);
|
||||
}
|
||||
is(!cursor.findPrevious(), "too many matches (backwards)");
|
||||
}
|
||||
|
||||
test("simple", "abcdefg", "abcdefg", function(doc) {
|
||||
run(doc, "cde", false, 0, 2, 0, 5, 1, 2, 1, 5);
|
||||
});
|
||||
|
||||
test("multiline", "hallo", "goodbye", function(doc) {
|
||||
run(doc, "llo\ngoo", false, 0, 2, 1, 3);
|
||||
run(doc, "blah\nhall", false);
|
||||
run(doc, "bye\neye", false);
|
||||
});
|
||||
|
||||
test("regexp", "abcde", "abcde", function(doc) {
|
||||
run(doc, /bcd/, false, 0, 1, 0, 4, 1, 1, 1, 4);
|
||||
run(doc, /BCD/, false);
|
||||
run(doc, /BCD/i, false, 0, 1, 0, 4, 1, 1, 1, 4);
|
||||
});
|
||||
|
||||
test("insensitive", "hallo", "HALLO", "oink", "hAllO", function(doc) {
|
||||
run(doc, "All", false, 3, 1, 3, 4);
|
||||
run(doc, "All", true, 0, 1, 0, 4, 1, 1, 1, 4, 3, 1, 3, 4);
|
||||
});
|
||||
|
||||
test("multilineInsensitive", "zie ginds komT", "De Stoomboot", "uit Spanje weer aan", function(doc) {
|
||||
run(doc, "komt\nde stoomboot\nuit", false);
|
||||
run(doc, "komt\nde stoomboot\nuit", true, 0, 10, 2, 3);
|
||||
run(doc, "kOMt\ndE stOOmboot\nuiT", true, 0, 10, 2, 3);
|
||||
});
|
||||
|
||||
test("expandingCaseFold", "<b>İİ İİ</b>", "<b>uu uu</b>", function(doc) {
|
||||
if (phantom) return; // A Phantom bug makes this hang
|
||||
run(doc, "</b>", true, 0, 8, 0, 12, 1, 8, 1, 12);
|
||||
run(doc, "İİ", true, 0, 3, 0, 5, 0, 6, 0, 8);
|
||||
});
|
||||
})();
|
297
public/filemanager/scripts/CodeMirror/test/sublime_test.js
vendored
Normal file
297
public/filemanager/scripts/CodeMirror/test/sublime_test.js
vendored
Normal file
@@ -0,0 +1,297 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
var Pos = CodeMirror.Pos;
|
||||
namespace = "sublime_";
|
||||
|
||||
function stTest(name) {
|
||||
var actions = Array.prototype.slice.call(arguments, 1);
|
||||
testCM(name, function(cm) {
|
||||
for (var i = 0; i < actions.length; i++) {
|
||||
var action = actions[i];
|
||||
if (typeof action == "string" && i == 0)
|
||||
cm.setValue(action);
|
||||
else if (typeof action == "string")
|
||||
cm.execCommand(action);
|
||||
else if (action instanceof Pos)
|
||||
cm.setCursor(action);
|
||||
else
|
||||
action(cm);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function at(line, ch, msg) {
|
||||
return function(cm) {
|
||||
eq(cm.listSelections().length, 1);
|
||||
eqPos(cm.getCursor("head"), Pos(line, ch), msg);
|
||||
eqPos(cm.getCursor("anchor"), Pos(line, ch), msg);
|
||||
};
|
||||
}
|
||||
|
||||
function val(content, msg) {
|
||||
return function(cm) { eq(cm.getValue(), content, msg); };
|
||||
}
|
||||
|
||||
function argsToRanges(args) {
|
||||
if (args.length % 4) throw new Error("Wrong number of arguments for ranges.");
|
||||
var ranges = [];
|
||||
for (var i = 0; i < args.length; i += 4)
|
||||
ranges.push({anchor: Pos(args[i], args[i + 1]),
|
||||
head: Pos(args[i + 2], args[i + 3])});
|
||||
return ranges;
|
||||
}
|
||||
|
||||
function setSel() {
|
||||
var ranges = argsToRanges(arguments);
|
||||
return function(cm) { cm.setSelections(ranges, 0); };
|
||||
}
|
||||
|
||||
function hasSel() {
|
||||
var ranges = argsToRanges(arguments);
|
||||
return function(cm) {
|
||||
var sels = cm.listSelections();
|
||||
if (sels.length != ranges.length)
|
||||
throw new Failure("Expected " + ranges.length + " selections, but found " + sels.length);
|
||||
for (var i = 0; i < sels.length; i++) {
|
||||
eqPos(sels[i].anchor, ranges[i].anchor, "anchor " + i);
|
||||
eqPos(sels[i].head, ranges[i].head, "head " + i);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
stTest("bySubword", "the foo_bar DooDahBah \n a",
|
||||
"goSubwordLeft", at(0, 0),
|
||||
"goSubwordRight", at(0, 3),
|
||||
"goSubwordRight", at(0, 7),
|
||||
"goSubwordRight", at(0, 11),
|
||||
"goSubwordRight", at(0, 15),
|
||||
"goSubwordRight", at(0, 18),
|
||||
"goSubwordRight", at(0, 21),
|
||||
"goSubwordRight", at(0, 22),
|
||||
"goSubwordRight", at(1, 0),
|
||||
"goSubwordRight", at(1, 2),
|
||||
"goSubwordRight", at(1, 2),
|
||||
"goSubwordLeft", at(1, 1),
|
||||
"goSubwordLeft", at(1, 0),
|
||||
"goSubwordLeft", at(0, 22),
|
||||
"goSubwordLeft", at(0, 18),
|
||||
"goSubwordLeft", at(0, 15),
|
||||
"goSubwordLeft", at(0, 12),
|
||||
"goSubwordLeft", at(0, 8),
|
||||
"goSubwordLeft", at(0, 4),
|
||||
"goSubwordLeft", at(0, 0));
|
||||
|
||||
stTest("splitSelectionByLine", "abc\ndef\nghi",
|
||||
setSel(0, 1, 2, 2),
|
||||
"splitSelectionByLine",
|
||||
hasSel(0, 1, 0, 3,
|
||||
1, 0, 1, 3,
|
||||
2, 0, 2, 2));
|
||||
|
||||
stTest("splitSelectionByLineMulti", "abc\ndef\nghi\njkl",
|
||||
setSel(0, 1, 1, 1,
|
||||
1, 2, 3, 2,
|
||||
3, 3, 3, 3),
|
||||
"splitSelectionByLine",
|
||||
hasSel(0, 1, 0, 3,
|
||||
1, 0, 1, 1,
|
||||
1, 2, 1, 3,
|
||||
2, 0, 2, 3,
|
||||
3, 0, 3, 2,
|
||||
3, 3, 3, 3));
|
||||
|
||||
stTest("selectLine", "abc\ndef\nghi",
|
||||
setSel(0, 1, 0, 1,
|
||||
2, 0, 2, 1),
|
||||
"selectLine",
|
||||
hasSel(0, 0, 1, 0,
|
||||
2, 0, 2, 3),
|
||||
setSel(0, 1, 1, 0),
|
||||
"selectLine",
|
||||
hasSel(0, 0, 2, 0));
|
||||
|
||||
stTest("insertLineAfter", "abcde\nfghijkl\nmn",
|
||||
setSel(0, 1, 0, 1,
|
||||
0, 3, 0, 3,
|
||||
1, 2, 1, 2,
|
||||
1, 3, 1, 5), "insertLineAfter",
|
||||
hasSel(1, 0, 1, 0,
|
||||
3, 0, 3, 0), val("abcde\n\nfghijkl\n\nmn"));
|
||||
|
||||
stTest("insertLineBefore", "abcde\nfghijkl\nmn",
|
||||
setSel(0, 1, 0, 1,
|
||||
0, 3, 0, 3,
|
||||
1, 2, 1, 2,
|
||||
1, 3, 1, 5), "insertLineBefore",
|
||||
hasSel(0, 0, 0, 0,
|
||||
2, 0, 2, 0), val("\nabcde\n\nfghijkl\nmn"));
|
||||
|
||||
stTest("selectNextOccurrence", "a foo bar\nfoobar foo",
|
||||
setSel(0, 2, 0, 5),
|
||||
"selectNextOccurrence", hasSel(0, 2, 0, 5,
|
||||
1, 0, 1, 3),
|
||||
"selectNextOccurrence", hasSel(0, 2, 0, 5,
|
||||
1, 0, 1, 3,
|
||||
1, 7, 1, 10),
|
||||
"selectNextOccurrence", hasSel(0, 2, 0, 5,
|
||||
1, 0, 1, 3,
|
||||
1, 7, 1, 10),
|
||||
Pos(0, 3), "selectNextOccurrence", hasSel(0, 2, 0, 5),
|
||||
"selectNextOccurrence", hasSel(0, 2, 0, 5,
|
||||
1, 7, 1, 10),
|
||||
setSel(0, 6, 0, 9),
|
||||
"selectNextOccurrence", hasSel(0, 6, 0, 9,
|
||||
1, 3, 1, 6));
|
||||
|
||||
stTest("selectScope", "foo(a) {\n bar[1, 2];\n}",
|
||||
"selectScope", hasSel(0, 0, 2, 1),
|
||||
Pos(0, 4), "selectScope", hasSel(0, 4, 0, 5),
|
||||
Pos(0, 5), "selectScope", hasSel(0, 4, 0, 5),
|
||||
Pos(0, 6), "selectScope", hasSel(0, 0, 2, 1),
|
||||
Pos(0, 8), "selectScope", hasSel(0, 8, 2, 0),
|
||||
Pos(1, 2), "selectScope", hasSel(0, 8, 2, 0),
|
||||
Pos(1, 6), "selectScope", hasSel(1, 6, 1, 10),
|
||||
Pos(1, 9), "selectScope", hasSel(1, 6, 1, 10));
|
||||
|
||||
stTest("goToBracket", "foo(a) {\n bar[1, 2];\n}",
|
||||
Pos(0, 0), "goToBracket", at(0, 0),
|
||||
Pos(0, 4), "goToBracket", at(0, 5), "goToBracket", at(0, 4),
|
||||
Pos(0, 8), "goToBracket", at(2, 0), "goToBracket", at(0, 8),
|
||||
Pos(1, 2), "goToBracket", at(2, 0),
|
||||
Pos(1, 7), "goToBracket", at(1, 10), "goToBracket", at(1, 6));
|
||||
|
||||
stTest("swapLine", "1\n2\n3---\n4\n5",
|
||||
"swapLineDown", val("2\n1\n3---\n4\n5"),
|
||||
"swapLineUp", val("1\n2\n3---\n4\n5"),
|
||||
"swapLineUp", val("1\n2\n3---\n4\n5"),
|
||||
Pos(4, 1), "swapLineDown", val("1\n2\n3---\n4\n5"),
|
||||
setSel(0, 1, 0, 1,
|
||||
1, 0, 2, 0,
|
||||
2, 2, 2, 2),
|
||||
"swapLineDown", val("4\n1\n2\n3---\n5"),
|
||||
hasSel(1, 1, 1, 1,
|
||||
2, 0, 3, 0,
|
||||
3, 2, 3, 2),
|
||||
"swapLineUp", val("1\n2\n3---\n4\n5"),
|
||||
hasSel(0, 1, 0, 1,
|
||||
1, 0, 2, 0,
|
||||
2, 2, 2, 2));
|
||||
|
||||
stTest("swapLineUpFromEnd", "a\nb\nc",
|
||||
Pos(2, 1), "swapLineUp",
|
||||
hasSel(1, 1, 1, 1), val("a\nc\nb"));
|
||||
|
||||
stTest("joinLines", "abc\ndef\nghi\njkl",
|
||||
"joinLines", val("abc def\nghi\njkl"), at(0, 4),
|
||||
"undo",
|
||||
setSel(0, 2, 1, 1), "joinLines",
|
||||
val("abc def ghi\njkl"), hasSel(0, 2, 0, 8),
|
||||
"undo",
|
||||
setSel(0, 1, 0, 1,
|
||||
1, 1, 1, 1,
|
||||
3, 1, 3, 1), "joinLines",
|
||||
val("abc def ghi\njkl"), hasSel(0, 4, 0, 4,
|
||||
0, 8, 0, 8,
|
||||
1, 3, 1, 3));
|
||||
|
||||
stTest("duplicateLine", "abc\ndef\nghi",
|
||||
Pos(1, 0), "duplicateLine", val("abc\ndef\ndef\nghi"), at(2, 0),
|
||||
"undo",
|
||||
setSel(0, 1, 0, 1,
|
||||
1, 1, 1, 1,
|
||||
2, 1, 2, 1), "duplicateLine",
|
||||
val("abc\nabc\ndef\ndef\nghi\nghi"), hasSel(1, 1, 1, 1,
|
||||
3, 1, 3, 1,
|
||||
5, 1, 5, 1));
|
||||
stTest("duplicateLineSelection", "abcdef",
|
||||
setSel(0, 1, 0, 1,
|
||||
0, 2, 0, 4,
|
||||
0, 5, 0, 5),
|
||||
"duplicateLine",
|
||||
val("abcdef\nabcdcdef\nabcdcdef"), hasSel(2, 1, 2, 1,
|
||||
2, 4, 2, 6,
|
||||
2, 7, 2, 7));
|
||||
|
||||
stTest("selectLinesUpward", "123\n345\n789\n012",
|
||||
setSel(0, 1, 0, 1,
|
||||
1, 1, 1, 3,
|
||||
2, 0, 2, 0,
|
||||
3, 0, 3, 0),
|
||||
"selectLinesUpward",
|
||||
hasSel(0, 1, 0, 1,
|
||||
0, 3, 0, 3,
|
||||
1, 0, 1, 0,
|
||||
1, 1, 1, 3,
|
||||
2, 0, 2, 0,
|
||||
3, 0, 3, 0));
|
||||
|
||||
stTest("selectLinesDownward", "123\n345\n789\n012",
|
||||
setSel(0, 1, 0, 1,
|
||||
1, 1, 1, 3,
|
||||
2, 0, 2, 0,
|
||||
3, 0, 3, 0),
|
||||
"selectLinesDownward",
|
||||
hasSel(0, 1, 0, 1,
|
||||
1, 1, 1, 3,
|
||||
2, 0, 2, 0,
|
||||
2, 3, 2, 3,
|
||||
3, 0, 3, 0));
|
||||
|
||||
stTest("sortLines", "c\nb\na\nC\nB\nA",
|
||||
"sortLines", val("A\nB\nC\na\nb\nc"),
|
||||
"undo",
|
||||
setSel(0, 0, 2, 0,
|
||||
3, 0, 5, 0),
|
||||
"sortLines", val("a\nb\nc\nA\nB\nC"),
|
||||
hasSel(0, 0, 2, 1,
|
||||
3, 0, 5, 1),
|
||||
"undo",
|
||||
setSel(1, 0, 4, 0), "sortLinesInsensitive", val("c\na\nB\nb\nC\nA"));
|
||||
|
||||
stTest("bookmarks", "abc\ndef\nghi\njkl",
|
||||
Pos(0, 1), "toggleBookmark",
|
||||
setSel(1, 1, 1, 2), "toggleBookmark",
|
||||
setSel(2, 1, 2, 2), "toggleBookmark",
|
||||
"nextBookmark", hasSel(0, 1, 0, 1),
|
||||
"nextBookmark", hasSel(1, 1, 1, 2),
|
||||
"nextBookmark", hasSel(2, 1, 2, 2),
|
||||
"prevBookmark", hasSel(1, 1, 1, 2),
|
||||
"prevBookmark", hasSel(0, 1, 0, 1),
|
||||
"prevBookmark", hasSel(2, 1, 2, 2),
|
||||
"prevBookmark", hasSel(1, 1, 1, 2),
|
||||
"toggleBookmark",
|
||||
"prevBookmark", hasSel(2, 1, 2, 2),
|
||||
"prevBookmark", hasSel(0, 1, 0, 1),
|
||||
"selectBookmarks", hasSel(0, 1, 0, 1,
|
||||
2, 1, 2, 2),
|
||||
"clearBookmarks",
|
||||
Pos(0, 0), "selectBookmarks", at(0, 0));
|
||||
|
||||
stTest("upAndDowncaseAtCursor", "abc\ndef x\nghI",
|
||||
setSel(0, 1, 0, 3,
|
||||
1, 1, 1, 1,
|
||||
1, 4, 1, 4), "upcaseAtCursor",
|
||||
val("aBC\nDEF x\nghI"), hasSel(0, 1, 0, 3,
|
||||
1, 3, 1, 3,
|
||||
1, 4, 1, 4),
|
||||
"downcaseAtCursor",
|
||||
val("abc\ndef x\nghI"), hasSel(0, 1, 0, 3,
|
||||
1, 3, 1, 3,
|
||||
1, 4, 1, 4));
|
||||
|
||||
stTest("mark", "abc\ndef\nghi",
|
||||
Pos(1, 1), "setSublimeMark",
|
||||
Pos(2, 1), "selectToSublimeMark", hasSel(2, 1, 1, 1),
|
||||
Pos(0, 1), "swapWithSublimeMark", at(1, 1), "swapWithSublimeMark", at(0, 1),
|
||||
"deleteToSublimeMark", val("aef\nghi"),
|
||||
"sublimeYank", val("abc\ndef\nghi"), at(1, 1));
|
||||
|
||||
stTest("findUnder", "foo foobar a",
|
||||
"findUnder", hasSel(0, 4, 0, 7),
|
||||
"findUnder", hasSel(0, 0, 0, 3),
|
||||
"findUnderPrevious", hasSel(0, 4, 0, 7),
|
||||
"findUnderPrevious", hasSel(0, 0, 0, 3),
|
||||
Pos(0, 4), "findUnder", hasSel(0, 4, 0, 10),
|
||||
Pos(0, 11), "findUnder", hasSel(0, 11, 0, 11));
|
||||
})();
|
1878
public/filemanager/scripts/CodeMirror/test/test.js
vendored
Normal file
1878
public/filemanager/scripts/CodeMirror/test/test.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3030
public/filemanager/scripts/CodeMirror/test/vim_test.js
vendored
Normal file
3030
public/filemanager/scripts/CodeMirror/test/vim_test.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user