This commit is contained in:
life committed 2014-05-07 13:06:24 +08:00
1 parent fac05a7b6c
commit 476ade10e7
1085 files changed
+259628

No files matched your search

@@ -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\");");
})();
@@ -0,0 +1,329 @@
(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("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");
});
})();
@@ -0,0 +1,131 @@
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) {
if (i === tests.length){
running = false;
return callback("done");
}
var test = tests[i], expFail = test.expectedFail, startTime = +new Date;
if (filters.length) {
for (var j = 0; j < filters.length; j++) {
if (test.name.match(filters[j])) {
break;
}
}
if (j == filters.length) {
callback("skipped", test.name, message);
return step(i + 1);
}
}
var 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);
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 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");
}
@@ -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"});
})();
@@ -0,0 +1,218 @@
<!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="../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>
<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="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/htmlmixed/htmlmixed.js"></script>
<script src="../mode/ruby/ruby.js"></script>
<script src="../mode/haml/haml.js"></script>
<script src="../mode/haml/test.js"></script>
<script src="../mode/markdown/markdown.js"></script>
<script src="../mode/markdown/test.js"></script>
<script src="../mode/gfm/gfm.js"></script>
<script src="../mode/gfm/test.js"></script>
<script src="../mode/stex/stex.js"></script>
<script src="../mode/stex/test.js"></script>
<script src="../mode/xquery/xquery.js"></script>
<script src="../mode/xquery/test.js"></script>
<script src="../addon/mode/multiplex_test.js"></script>
<script src="vim_test.js"></script>
<script src="emacs_test.js"></script>
<script>
window.onload = runHarness;
CodeMirror.on(window, 'hashchange', runHarness);
function esc(str) {
return str.replace(/[<&]/, function(ch) { return ch == "<" ? "&lt;" : "&amp;"; });
}
var output = document.getElementById("output"),
progress = document.getElementById("progress"),
progressRan = document.getElementById("progress_ran").childNodes[0],
progressTotal = document.getElementById("progress_total").childNodes[0];
var count = 0,
failed = 0,
skipped = 0,
bad = "",
running = false, // Flag that states tests are running
quit = false, // Flag to quit tests ASAP
verbose = false; // Adds message for *every* test to output
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>
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,139 @@
/*
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")
.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: true,
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);
}
}, scopePasser);
if (!globalsSeen.exports) {
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; };
@@ -0,0 +1,216 @@
// AST walker module for Mozilla Parser API compatible trees
(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;
function c(node, st, override) {
var type = override || node.type, found = visitors[type];
if (found) found(node, st);
base[type](node, st, c);
}
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 = exports.make(funcs, base);
function c(node, st, override) {
visitor[override || node.type](node, st, c);
}
c(node, state);
};
// 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;
var visitor = {};
for (var type in base)
visitor[type] = funcs.hasOwnProperty(type) ? funcs[type] : base[type];
return visitor;
};
function skipThrough(node, st, c) { c(node, st); }
function ignore(node, st, c) {}
// Node walkers.
exports.Program = exports.BlockStatement = function(node, st, c) {
for (var i = 0; i < node.body.length; ++i)
c(node.body[i], st, "Statement");
};
exports.Statement = skipThrough;
exports.EmptyStatement = ignore;
exports.ExpressionStatement = function(node, st, c) {
c(node.expression, st, "Expression");
};
exports.IfStatement = function(node, st, c) {
c(node.test, st, "Expression");
c(node.consequent, st, "Statement");
if (node.alternate) c(node.alternate, st, "Statement");
};
exports.LabeledStatement = function(node, st, c) {
c(node.body, st, "Statement");
};
exports.BreakStatement = exports.ContinueStatement = ignore;
exports.WithStatement = function(node, st, c) {
c(node.object, st, "Expression");
c(node.body, st, "Statement");
};
exports.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");
}
};
exports.ReturnStatement = function(node, st, c) {
if (node.argument) c(node.argument, st, "Expression");
};
exports.ThrowStatement = function(node, st, c) {
c(node.argument, st, "Expression");
};
exports.TryStatement = function(node, st, c) {
c(node.block, st, "Statement");
for (var i = 0; i < node.handlers.length; ++i)
c(node.handlers[i].body, st, "ScopeBody");
if (node.finalizer) c(node.finalizer, st, "Statement");
};
exports.WhileStatement = function(node, st, c) {
c(node.test, st, "Expression");
c(node.body, st, "Statement");
};
exports.DoWhileStatement = exports.WhileStatement;
exports.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");
};
exports.ForInStatement = function(node, st, c) {
c(node.left, st, "ForInit");
c(node.right, st, "Expression");
c(node.body, st, "Statement");
};
exports.ForInit = function(node, st, c) {
if (node.type == "VariableDeclaration") c(node, st);
else c(node, st, "Expression");
};
exports.DebuggerStatement = ignore;
exports.FunctionDeclaration = function(node, st, c) {
c(node, st, "Function");
};
exports.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");
}
};
exports.Function = function(node, st, c) {
c(node.body, st, "ScopeBody");
};
exports.ScopeBody = function(node, st, c) {
c(node, st, "Statement");
};
exports.Expression = skipThrough;
exports.ThisExpression = ignore;
exports.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");
}
};
exports.ObjectExpression = function(node, st, c) {
for (var i = 0; i < node.properties.length; ++i)
c(node.properties[i].value, st, "Expression");
};
exports.FunctionExpression = exports.FunctionDeclaration;
exports.SequenceExpression = function(node, st, c) {
for (var i = 0; i < node.expressions.length; ++i)
c(node.expressions[i], st, "Expression");
};
exports.UnaryExpression = exports.UpdateExpression = function(node, st, c) {
c(node.argument, st, "Expression");
};
exports.BinaryExpression = exports.AssignmentExpression = exports.LogicalExpression = function(node, st, c) {
c(node.left, st, "Expression");
c(node.right, st, "Expression");
};
exports.ConditionalExpression = function(node, st, c) {
c(node.test, st, "Expression");
c(node.consequent, st, "Expression");
c(node.alternate, st, "Expression");
};
exports.NewExpression = exports.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");
};
exports.MemberExpression = function(node, st, c) {
c(node.object, st, "Expression");
if (node.computed) c(node.property, st, "Expression");
};
exports.Identifier = exports.Literal = ignore;
// A custom walker that keeps track of the scope chain and the
// variables defined in it.
function makeScope(prev) {
return {vars: Object.create(null), prev: prev};
}
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 ? 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");
for (var i = 0; i < node.handlers.length; ++i) {
var handler = node.handlers[i], inner = makeScope(scope);
inner.vars[handler.param.name] = {type: "catch clause", node: handler.param};
c(handler.body, inner, "ScopeBody");
}
if (node.finalizer) c(node.finalizer, scope, "Statement");
},
VariableDeclaration: function(node, scope, c) {
for (var i = 0; i < node.declarations.length; ++i) {
var decl = node.declarations[i];
scope.vars[decl.id.name] = {type: "var", node: decl.id};
if (decl.init) c(decl.init, scope, "Expression");
}
}
});
})(typeof exports == "undefined" ? acorn.walk = {} : exports);
@@ -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;
}
@@ -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('&', '&amp;').replace('<', '&lt;');
}
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;
}
})();
@@ -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);
}
}
@@ -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);
});
});
@@ -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);
});
})();
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff