first commit
This commit is contained in:
134
codemirror/test/driver.js
Normal file
134
codemirror/test/driver.js
Normal file
@@ -0,0 +1,134 @@
|
||||
var tests = [], debug = null, debugUsed = new Array(), 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;
|
||||
}
|
||||
function testCM(name, run, opts, expectedFail) {
|
||||
return test("core_" + name, function() {
|
||||
var place = document.getElementById("testground"), cm = CodeMirror(place, opts);
|
||||
var successful = false;
|
||||
try {
|
||||
run(cm);
|
||||
successful = true;
|
||||
} finally {
|
||||
if ((debug && !successful) || verbose) {
|
||||
place.style.visibility = "visible";
|
||||
} else {
|
||||
place.removeChild(cm.getWrapperElement());
|
||||
}
|
||||
}
|
||||
}, expectedFail);
|
||||
}
|
||||
|
||||
function runTests(callback) {
|
||||
if (debug) {
|
||||
if (indexOf(debug, "verbose") === 0) {
|
||||
verbose = true;
|
||||
debug.splice(0, 1);
|
||||
}
|
||||
if (debug.length < 1) {
|
||||
debug = null;
|
||||
} else {
|
||||
if (totalTests > debug.length) {
|
||||
totalTests = debug.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
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 (debug !== null) {
|
||||
var debugIndex = indexOf(debug, test.name);
|
||||
if (debugIndex !== -1) {
|
||||
// Remove from array for reporting incorrect tests later
|
||||
debug.splice(debugIndex, 1);
|
||||
} else {
|
||||
var wildcardName = test.name.split("_").shift() + "_*";
|
||||
debugIndex = indexOf(debug, wildcardName);
|
||||
if (debugIndex !== -1) {
|
||||
// Remove from array for reporting incorrect tests later
|
||||
debug.splice(debugIndex, 1);
|
||||
debugUsed.push(wildcardName);
|
||||
} else {
|
||||
debugIndex = indexOf(debugUsed, wildcardName);
|
||||
if (debugIndex !== -1) {
|
||||
totalTests++;
|
||||
} else {
|
||||
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)));
|
||||
if (b == null) throw new Failure(label("comparing " + str(a) + " to null"));
|
||||
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));
|
||||
}
|
||||
186
codemirror/test/index.html
Normal file
186
codemirror/test/index.html
Normal file
@@ -0,0 +1,186 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>CodeMirror: Test Suite</title>
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<link rel="stylesheet" href="../doc/docs.css">
|
||||
<link rel="stylesheet" href="mode_test.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../lib/util/overlay.js"></script>
|
||||
<script src="../lib/util/searchcursor.js"></script>
|
||||
<script src="../mode/javascript/javascript.js"></script>
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<script src="../keymap/vim.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.ok {color: #090;}
|
||||
.fail {color: #e00;}
|
||||
.error {color: #c90;}
|
||||
.done {font-weight: bold;}
|
||||
#progress {
|
||||
background: #45d;
|
||||
color: white;
|
||||
text-shadow: 0 0 1px #45d, 0 0 2px #45d, 0 0 3px #45d;
|
||||
font-weight: bold;
|
||||
white-space: pre;
|
||||
}
|
||||
#testground {
|
||||
visibility: hidden;
|
||||
}
|
||||
#testground.offscreen {
|
||||
visibility: visible;
|
||||
position: absolute;
|
||||
left: -10000px;
|
||||
top: -10000px;
|
||||
}
|
||||
.CodeMirror { border: 1px solid black; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Test Suite</h1>
|
||||
|
||||
<p>A limited set of programmatic sanity tests for CodeMirror.</p>
|
||||
|
||||
<div style="border: 1px solid black; padding: 1px; max-width: 700px;">
|
||||
<div style="width: 0px;" id=progress><div style="padding: 3px;">Ran <span id="progress_ran">0</span><span id="progress_total"> of 0</span> tests</div></div>
|
||||
</div>
|
||||
<p id=status>Please enable JavaScript...</p>
|
||||
<div id=output></div>
|
||||
|
||||
<div id=testground></div>
|
||||
|
||||
<script src="driver.js"></script>
|
||||
<script src="test.js"></script>
|
||||
<script src="mode_test.js"></script>
|
||||
<script src="../mode/css/css.js"></script>
|
||||
<script src="../mode/css/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="vim_test.js"></script>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
runHarness();
|
||||
};
|
||||
CodeMirror.on(window, 'hashchange', function(){
|
||||
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,
|
||||
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;
|
||||
}
|
||||
if (window.location.hash.substr(1)){
|
||||
debug = window.location.hash.substr(1).split(",");
|
||||
} else {
|
||||
debug = null;
|
||||
}
|
||||
quit = false;
|
||||
running = true;
|
||||
setStatus("Loading tests...");
|
||||
count = 0;
|
||||
failed = 0;
|
||||
bad = "";
|
||||
verbose = false;
|
||||
debugUsed = Array();
|
||||
totalTests = tests.length;
|
||||
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") ++count;
|
||||
progress.style.width = (count * (progress.parentNode.clientWidth - 2) / totalTests) + "px";
|
||||
progressTotal.nodeValue = " of " + totalTests +
|
||||
(debugUsed.length && type != "done" ? "+" : "");
|
||||
progressRan.nodeValue = count;
|
||||
if (type == "ok") {
|
||||
message = "Test '" + name + "' succeeded";
|
||||
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 (debug && debug.length) {
|
||||
var bogusTests = totalTests - count;
|
||||
message += " — " + bogusTests + " nonexistent test" +
|
||||
(bogusTests > 1 ? "s" : "") + " requested by location.hash: " +
|
||||
"`" + debug.join("`, `") + "`";
|
||||
} else {
|
||||
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>
|
||||
</body>
|
||||
</html>
|
||||
1593
codemirror/test/lint/acorn.js
Normal file
1593
codemirror/test/lint/acorn.js
Normal file
File diff suppressed because it is too large
Load Diff
104
codemirror/test/lint/lint.js
Normal file
104
codemirror/test/lint/lint.js
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
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
|
||||
|
||||
[1]: https://github.com/marijnh/acorn/
|
||||
*/
|
||||
|
||||
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");
|
||||
var badChar = file.match(/[\x00-\x08\x0b\x0c\x0e-\x19\uFEFF]/);
|
||||
if (badChar)
|
||||
fail("Undesirable character " + badChar[0].charCodeAt(0) + " at position " + badChar.index,
|
||||
{source: fileName});
|
||||
|
||||
try {
|
||||
var parsed = acorn.parse(file, {
|
||||
locations: true,
|
||||
ecmaVersion: 3,
|
||||
strictSemicolons: true,
|
||||
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) {
|
||||
// Mark used identifiers
|
||||
for (var cur = scope; cur; cur = cur.prev)
|
||||
if (node.name in cur.vars) {
|
||||
cur.vars[node.name].used = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, scopePasser);
|
||||
|
||||
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.match(/[^\/]+$/)[0] + ": " + msg);
|
||||
failed = true;
|
||||
}
|
||||
|
||||
function checkDir(dir) {
|
||||
fs.readdirSync(dir).forEach(function(file) {
|
||||
var fname = dir + "/" + file;
|
||||
if (/\.js$/.test(file)) checkFile(fname);
|
||||
else if (fs.lstatSync(fname).isDirectory()) checkDir(fname);
|
||||
});
|
||||
}
|
||||
|
||||
exports.checkDir = checkDir;
|
||||
exports.checkFile = checkFile;
|
||||
exports.success = function() { return !failed; };
|
||||
1372
codemirror/test/lint/parse-js.js
Normal file
1372
codemirror/test/lint/parse-js.js
Normal file
File diff suppressed because it is too large
Load Diff
216
codemirror/test/lint/walk.js
Normal file
216
codemirror/test/lint/walk.js
Normal file
@@ -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);
|
||||
10
codemirror/test/mode_test.css
Normal file
10
codemirror/test/mode_test.css
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;
|
||||
}
|
||||
192
codemirror/test/mode_test.js
Normal file
192
codemirror/test/mode_test.js
Normal file
@@ -0,0 +1,192 @@
|
||||
/**
|
||||
* Helper to test CodeMirror highlighting modes. It pretty prints output of the
|
||||
* highlighter and can check against expected styles.
|
||||
*
|
||||
* See test.html in the stex mode for examples.
|
||||
*/
|
||||
ModeTest = {};
|
||||
|
||||
ModeTest.modeOptions = {};
|
||||
ModeTest.modeName = CodeMirror.defaults.mode;
|
||||
|
||||
/* keep track of results for printSummary */
|
||||
ModeTest.testCount = 0;
|
||||
ModeTest.passes = 0;
|
||||
|
||||
/**
|
||||
* Run a test; prettyprints the results using document.write().
|
||||
*
|
||||
* @param name Name of test
|
||||
* @param text String to highlight.
|
||||
* @param expected Expected styles and tokens: Array(style, token, [style, token,...])
|
||||
* @param modeName
|
||||
* @param modeOptions
|
||||
* @param expectedFail
|
||||
*/
|
||||
ModeTest.testMode = function(name, text, expected, modeName, modeOptions, expectedFail) {
|
||||
ModeTest.testCount += 1;
|
||||
|
||||
if (!modeName) modeName = ModeTest.modeName;
|
||||
|
||||
if (!modeOptions) modeOptions = ModeTest.modeOptions;
|
||||
|
||||
var mode = CodeMirror.getMode(modeOptions, modeName);
|
||||
|
||||
if (expected.length < 0) {
|
||||
throw "must have text for test (" + name + ")";
|
||||
}
|
||||
if (expected.length % 2 != 0) {
|
||||
throw "must have text for test (" + name + ") plus expected (style, token) pairs";
|
||||
}
|
||||
return test(
|
||||
modeName + "_" + name,
|
||||
function(){
|
||||
return ModeTest.compare(text, expected, mode);
|
||||
},
|
||||
expectedFail
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
ModeTest.compare = function (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 = ModeTest.highlight(text, mode);
|
||||
|
||||
var pass, passStyle = "";
|
||||
pass = ModeTest.highlightOutputsEqual(expectedOutput, observedOutput);
|
||||
passStyle = pass ? 'mt-pass' : 'mt-fail';
|
||||
ModeTest.passes += pass ? 1 : 0;
|
||||
|
||||
var s = '';
|
||||
if (pass) {
|
||||
s += '<div class="mt-test ' + passStyle + '">';
|
||||
s += '<pre>' + ModeTest.htmlEscape(text) + '</pre>';
|
||||
s += '<div class="cm-s-default">';
|
||||
s += ModeTest.prettyPrintOutputTable(observedOutput);
|
||||
s += '</div>';
|
||||
s += '</div>';
|
||||
return s;
|
||||
} else {
|
||||
s += '<div class="mt-test ' + passStyle + '">';
|
||||
s += '<pre>' + ModeTest.htmlEscape(text) + '</pre>';
|
||||
s += '<div class="cm-s-default">';
|
||||
s += 'expected:';
|
||||
s += ModeTest.prettyPrintOutputTable(expectedOutput);
|
||||
s += 'observed:';
|
||||
s += ModeTest.prettyPrintOutputTable(observedOutput);
|
||||
s += '</div>';
|
||||
s += '</div>';
|
||||
throw s;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emulation of CodeMirror's internal highlight routine for testing. Multi-line
|
||||
* input is supported.
|
||||
*
|
||||
* @param string to highlight
|
||||
*
|
||||
* @param mode the mode that will do the actual highlighting
|
||||
*
|
||||
* @return array of [style, token] pairs
|
||||
*/
|
||||
ModeTest.highlight = function(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;
|
||||
var stream = new CodeMirror.StringStream(line);
|
||||
if (line == "" && mode.blankLine) mode.blankLine(state);
|
||||
/* Start copied code from CodeMirror.highlight */
|
||||
while (!stream.eol()) {
|
||||
var style = mode.token(stream, state), substr = stream.current();
|
||||
if (style && style.indexOf(" ") > -1) style = style.split(' ').sort().join(' ');
|
||||
|
||||
stream.start = stream.pos;
|
||||
if (pos && st[pos-2] == style && !newLine) {
|
||||
st[pos-1] += substr;
|
||||
} else if (substr) {
|
||||
st[pos++] = style; 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two arrays of output from ModeTest.highlight.
|
||||
*
|
||||
* @param o1 array of [style, token] pairs
|
||||
*
|
||||
* @param o2 array of [style, token] pairs
|
||||
*
|
||||
* @return boolean; true iff outputs equal
|
||||
*/
|
||||
ModeTest.highlightOutputsEqual = function(o1, o2) {
|
||||
if (o1.length != o2.length) return false;
|
||||
for (var i = 0; i < o1.length; ++i)
|
||||
if (o1[i] != o2[i]) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print tokens and corresponding styles in a table. Spaces in the token are
|
||||
* replaced with 'interpunct' dots (·).
|
||||
*
|
||||
* @param output array of [style, token] pairs
|
||||
*
|
||||
* @return html string
|
||||
*/
|
||||
ModeTest.prettyPrintOutputTable = function(output) {
|
||||
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">' +
|
||||
'<span class="cm-' + String(style).replace(/ +/g, " cm-") + '">' +
|
||||
ModeTest.htmlEscape(val).replace(/ /g,'·') +
|
||||
'</span>' +
|
||||
'</td>';
|
||||
}
|
||||
s += '</tr><tr>';
|
||||
for (var i = 0; i < output.length; i += 2) {
|
||||
s += '<td class="mt-style"><span>' + output[i] + '</span></td>';
|
||||
}
|
||||
s += '</table>';
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print how many tests have run so far and how many of those passed.
|
||||
*/
|
||||
ModeTest.printSummary = function() {
|
||||
ModeTest.runTests(ModeTest.displayTest);
|
||||
document.write(ModeTest.passes + ' passes for ' + ModeTest.testCount + ' tests');
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic HTML escaping.
|
||||
*/
|
||||
ModeTest.htmlEscape = function(str) {
|
||||
str = str.toString();
|
||||
return str.replace(/[<&]/g,
|
||||
function(str) {return str == "&" ? "&" : "<";});
|
||||
}
|
||||
|
||||
31
codemirror/test/phantom_driver.js
Normal file
31
codemirror/test/phantom_driver.js
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);
|
||||
}
|
||||
}
|
||||
32
codemirror/test/run.js
Normal file
32
codemirror/test/run.js
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var lint = require("./lint/lint");
|
||||
|
||||
lint.checkDir("mode");
|
||||
lint.checkDir("lib");
|
||||
|
||||
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);
|
||||
});
|
||||
}).addListener('error', function (err) {
|
||||
throw err;
|
||||
}).listen(3000, function () {
|
||||
var child_process = require('child_process');
|
||||
child_process.exec("which phantomjs", function (err) {
|
||||
if (err) {
|
||||
console.error("PhantomJS is not installed. Download from http://phantomjs.org");
|
||||
process.exit(1);
|
||||
}
|
||||
var cmd = 'phantomjs test/phantom_driver.js';
|
||||
child_process.exec(cmd, function (err, stdout) {
|
||||
server.close();
|
||||
console.log(stdout);
|
||||
process.exit(err || !ok ? 1 : 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
1188
codemirror/test/test.js
Normal file
1188
codemirror/test/test.js
Normal file
File diff suppressed because it is too large
Load Diff
812
codemirror/test/vim_test.js
Normal file
812
codemirror/test/vim_test.js
Normal file
@@ -0,0 +1,812 @@
|
||||
var code = '' +
|
||||
' wOrd1 (#%\n' +
|
||||
' word3] \n' +
|
||||
'aopop pop 0 1 2 3 4\n' +
|
||||
' (a) [b] {c} \n' +
|
||||
'int getchar(void) {\n' +
|
||||
' static char buf[BUFSIZ];\n' +
|
||||
' static char *bufp = buf;\n' +
|
||||
' if (n == 0) { /* buffer is empty */\n' +
|
||||
' n = read(0, buf, sizeof buf);\n' +
|
||||
' bufp = buf;\n' +
|
||||
' }\n' +
|
||||
' return (--n >= 0) ? (unsigned char) *bufp++ : EOF;\n' +
|
||||
'}\n';
|
||||
|
||||
var lines = (function() {
|
||||
lineText = code.split('\n');
|
||||
var ret = [];
|
||||
for (var i = 0; i < lineText.length; i++) {
|
||||
ret[i] = {
|
||||
line: i,
|
||||
length: lineText[i].length,
|
||||
lineText: lineText[i],
|
||||
textStart: /^\s*/.exec(lineText[i])[0].length
|
||||
};
|
||||
}
|
||||
return ret;
|
||||
})();
|
||||
var endOfDocument = makeCursor(lines.length - 1,
|
||||
lines[lines.length - 1].length);
|
||||
var wordLine = lines[0];
|
||||
var bigWordLine = lines[1];
|
||||
var charLine = lines[2];
|
||||
var bracesLine = lines[3];
|
||||
|
||||
var word1 = {
|
||||
start: { line: wordLine.line, ch: 1 },
|
||||
end: { line: wordLine.line, ch: 5 }
|
||||
};
|
||||
var word2 = {
|
||||
start: { line: wordLine.line, ch: word1.end.ch + 2 },
|
||||
end: { line: wordLine.line, ch: word1.end.ch + 4 }
|
||||
};
|
||||
var word3 = {
|
||||
start: { line: bigWordLine.line, ch: 1 },
|
||||
end: { line: bigWordLine.line, ch: 5 }
|
||||
};
|
||||
var bigWord1 = word1;
|
||||
var bigWord2 = word2;
|
||||
var bigWord3 = {
|
||||
start: { line: bigWordLine.line, ch: 1 },
|
||||
end: { line: bigWordLine.line, ch: 7 }
|
||||
};
|
||||
var bigWord4 = {
|
||||
start: { line: bigWordLine.line, ch: bigWord1.end.ch + 3 },
|
||||
end: { line: bigWordLine.line, ch: bigWord1.end.ch + 7 }
|
||||
}
|
||||
var oChars = [ { line: charLine.line, ch: 1 },
|
||||
{ line: charLine.line, ch: 3 },
|
||||
{ line: charLine.line, ch: 7 } ];
|
||||
var pChars = [ { line: charLine.line, ch: 2 },
|
||||
{ line: charLine.line, ch: 4 },
|
||||
{ line: charLine.line, ch: 6 },
|
||||
{ line: charLine.line, ch: 8 } ];
|
||||
var numChars = [ { line: charLine.line, ch: 10 },
|
||||
{ line: charLine.line, ch: 12 },
|
||||
{ line: charLine.line, ch: 14 },
|
||||
{ line: charLine.line, ch: 16 },
|
||||
{ line: charLine.line, ch: 18 }];
|
||||
var parens1 = {
|
||||
start: { line: bracesLine.line, ch: 1 },
|
||||
end: { line: bracesLine.line, ch: 3 }
|
||||
};
|
||||
var squares1 = {
|
||||
start: { line: bracesLine.line, ch: 5 },
|
||||
end: { line: bracesLine.line, ch: 7 }
|
||||
};
|
||||
var curlys1 = {
|
||||
start: { line: bracesLine.line, ch: 9 },
|
||||
end: { line: bracesLine.line, ch: 11 }
|
||||
};
|
||||
|
||||
function copyCursor(cur) {
|
||||
return { ch: cur.ch, line: cur.line };
|
||||
}
|
||||
|
||||
function testVim(name, run, opts, expectedFail) {
|
||||
var vimOpts = {
|
||||
lineNumbers: true,
|
||||
mode: 'text/x-csrc',
|
||||
keyMap: 'vim',
|
||||
showCursorWhenSelecting: true,
|
||||
value: code
|
||||
};
|
||||
for (var prop in opts) {
|
||||
if (opts.hasOwnProperty(prop)) {
|
||||
vimOpts[prop] = opts[prop];
|
||||
}
|
||||
}
|
||||
return test('vim_' + name, function() {
|
||||
var place = document.getElementById("testground");
|
||||
var cm = CodeMirror(place, vimOpts);
|
||||
CodeMirror.Vim.maybeInitState(cm);
|
||||
var vim = cm.vimState;
|
||||
|
||||
function doKeysFn(cm) {
|
||||
return function(args) {
|
||||
if (args instanceof Array) {
|
||||
arguments = args;
|
||||
}
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
CodeMirror.Vim.handleKey(cm, arguments[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
function assertCursorAtFn(cm) {
|
||||
return function(line, ch) {
|
||||
var pos;
|
||||
if (ch == null && typeof line.line == 'number') {
|
||||
pos = line;
|
||||
} else {
|
||||
pos = makeCursor(line, ch);
|
||||
}
|
||||
eqPos(pos, cm.getCursor());
|
||||
}
|
||||
}
|
||||
function fakeOpenDialog(result) {
|
||||
return function(text, callback) {
|
||||
return callback(result);
|
||||
}
|
||||
}
|
||||
var helpers = {
|
||||
doKeys: doKeysFn(cm),
|
||||
assertCursorAt: assertCursorAtFn(cm),
|
||||
fakeOpenDialog: fakeOpenDialog,
|
||||
getRegisterController: function() {
|
||||
return CodeMirror.Vim.getRegisterController();
|
||||
}
|
||||
}
|
||||
CodeMirror.Vim.clearVimGlobalState_();
|
||||
var successful = false;
|
||||
try {
|
||||
run(cm, vim, helpers);
|
||||
successful = true;
|
||||
} finally {
|
||||
if ((debug && !successful) || verbose) {
|
||||
place.style.visibility = "visible";
|
||||
} else {
|
||||
place.removeChild(cm.getWrapperElement());
|
||||
}
|
||||
}
|
||||
}, expectedFail);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param name Name of the test
|
||||
* @param keys An array of keys or a string with a single key to simulate.
|
||||
* @param endPos The expected end position of the cursor.
|
||||
* @param startPos The position the cursor should start at, defaults to 0, 0.
|
||||
*/
|
||||
function testMotion(name, keys, endPos, startPos) {
|
||||
testVim(name, function(cm, vim, helpers) {
|
||||
if (!startPos) {
|
||||
startPos = { line: 0, ch: 0 };
|
||||
}
|
||||
cm.setCursor(startPos);
|
||||
helpers.doKeys(keys);
|
||||
helpers.assertCursorAt(endPos);
|
||||
});
|
||||
};
|
||||
|
||||
function makeCursor(line, ch) {
|
||||
return { line: line, ch: ch };
|
||||
};
|
||||
|
||||
function offsetCursor(cur, offsetLine, offsetCh) {
|
||||
return { line: cur.line + offsetLine, ch: cur.ch + offsetCh };
|
||||
};
|
||||
|
||||
// Motion tests
|
||||
testMotion('|', '|', makeCursor(0, 0), makeCursor(0,4));
|
||||
testMotion('|_repeat', ['3', '|'], makeCursor(0, 2), makeCursor(0,4));
|
||||
testMotion('h', 'h', makeCursor(0, 0), word1.start);
|
||||
testMotion('h_repeat', ['3', 'h'], offsetCursor(word1.end, 0, -3), word1.end);
|
||||
testMotion('l', 'l', makeCursor(0, 1));
|
||||
testMotion('l_repeat', ['2', 'l'], makeCursor(0, 2));
|
||||
testMotion('j', 'j', offsetCursor(word1.end, 1, 0), word1.end);
|
||||
testMotion('j_repeat', ['2', 'j'], offsetCursor(word1.end, 2, 0), word1.end);
|
||||
testMotion('k', 'k', offsetCursor(word3.end, -1, 0), word3.end);
|
||||
testMotion('k_repeat', ['2', 'k'], makeCursor(0, 4), makeCursor(2, 4));
|
||||
testMotion('w', 'w', word1.start);
|
||||
testMotion('w_repeat', ['2', 'w'], word2.start);
|
||||
testMotion('w_wrap', ['w'], word3.start, word2.start);
|
||||
testMotion('w_endOfDocument', 'w', endOfDocument, endOfDocument);
|
||||
testMotion('W', 'W', bigWord1.start);
|
||||
testMotion('W_repeat', ['2', 'W'], bigWord3.start, bigWord1.start);
|
||||
testMotion('e', 'e', word1.end);
|
||||
testMotion('e_repeat', ['2', 'e'], word2.end);
|
||||
testMotion('e_wrap', 'e', word3.end, word2.end);
|
||||
testMotion('e_endOfDocument', 'e', endOfDocument, endOfDocument);
|
||||
testMotion('b', 'b', word3.start, word3.end);
|
||||
testMotion('b_repeat', ['2', 'b'], word2.start, word3.end);
|
||||
testMotion('b_wrap', 'b', word2.start, word3.start);
|
||||
testMotion('b_startOfDocument', 'b', makeCursor(0, 0), makeCursor(0, 0));
|
||||
testMotion('ge', ['g', 'e'], word2.end, word3.end);
|
||||
testMotion('ge_repeat', ['2', 'g', 'e'], word1.end, word3.start);
|
||||
testMotion('ge_wrap', ['g', 'e'], word2.end, word3.start);
|
||||
testMotion('ge_startOfDocument', ['g', 'e'], makeCursor(0, 0),
|
||||
makeCursor(0, 0));
|
||||
testMotion('gg', ['g', 'g'], makeCursor(lines[0].line, lines[0].textStart),
|
||||
makeCursor(3, 1));
|
||||
testMotion('gg_repeat', ['3', 'g', 'g'],
|
||||
makeCursor(lines[2].line, lines[2].textStart));
|
||||
testMotion('G', 'G',
|
||||
makeCursor(lines[lines.length - 1].line, lines[lines.length - 1].textStart),
|
||||
makeCursor(3, 1));
|
||||
testMotion('G_repeat', ['3', 'G'], makeCursor(lines[2].line,
|
||||
lines[2].textStart));
|
||||
// TODO: Make the test code long enough to test Ctrl-F and Ctrl-B.
|
||||
testMotion('0', '0', makeCursor(0, 0), makeCursor(0, 8));
|
||||
testMotion('^', '^', makeCursor(0, lines[0].textStart), makeCursor(0, 8));
|
||||
testMotion('$', '$', makeCursor(0, lines[0].length - 1), makeCursor(0, 1));
|
||||
testMotion('$_repeat', ['2', '$'], makeCursor(1, lines[1].length - 1),
|
||||
makeCursor(0, 3));
|
||||
testMotion('f', ['f', 'p'], pChars[0], makeCursor(charLine.line, 0));
|
||||
testMotion('f_repeat', ['2', 'f', 'p'], pChars[2], pChars[0]);
|
||||
testMotion('f_num', ['f', '2'], numChars[2], makeCursor(charLine.line, 0));
|
||||
testMotion('t', ['t','p'], offsetCursor(pChars[0], 0, -1),
|
||||
makeCursor(charLine.line, 0));
|
||||
testMotion('t_repeat', ['2', 't', 'p'], offsetCursor(pChars[2], 0, -1),
|
||||
pChars[0]);
|
||||
testMotion('F', ['F', 'p'], pChars[0], pChars[1]);
|
||||
testMotion('F_repeat', ['2', 'F', 'p'], pChars[0], pChars[2]);
|
||||
testMotion('T', ['T', 'p'], offsetCursor(pChars[0], 0, 1), pChars[1]);
|
||||
testMotion('T_repeat', ['2', 'T', 'p'], offsetCursor(pChars[0], 0, 1), pChars[2]);
|
||||
testMotion('%_parens', ['%'], parens1.end, parens1.start);
|
||||
testMotion('%_squares', ['%'], squares1.end, squares1.start);
|
||||
testMotion('%_braces', ['%'], curlys1.end, curlys1.start);
|
||||
// Make sure that moving down after going to the end of a line always leaves you
|
||||
// at the end of a line, but preserves the offset in other cases
|
||||
testVim('Changing lines after Eol operation', function(cm, vim, helpers) {
|
||||
var startPos = { line: 0, ch: 0 };
|
||||
cm.setCursor(startPos);
|
||||
helpers.doKeys(['$']);
|
||||
helpers.doKeys(['j']);
|
||||
// After moving to Eol and then down, we should be at Eol of line 2
|
||||
helpers.assertCursorAt({ line: 1, ch: lines[1].length - 1 });
|
||||
helpers.doKeys(['j']);
|
||||
// After moving down, we should be at Eol of line 3
|
||||
helpers.assertCursorAt({ line: 2, ch: lines[2].length - 1 });
|
||||
helpers.doKeys(['h']);
|
||||
helpers.doKeys(['j']);
|
||||
// After moving back one space and then down, since line 4 is shorter than line 2, we should
|
||||
// be at Eol of line 2 - 1
|
||||
helpers.assertCursorAt({ line: 3, ch: lines[3].length - 1 });
|
||||
helpers.doKeys(['j']);
|
||||
helpers.doKeys(['j']);
|
||||
// After moving down again, since line 3 has enough characters, we should be back to the
|
||||
// same place we were at on line 1
|
||||
helpers.assertCursorAt({ line: 5, ch: lines[2].length - 2 });
|
||||
});
|
||||
|
||||
// Operator tests
|
||||
testVim('dl', function(cm, vim, helpers) {
|
||||
var curStart = makeCursor(0, 0);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('d', 'l');
|
||||
eq('word1 ', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq(' ', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(curStart, cm.getCursor());
|
||||
}, { value: ' word1 ' });
|
||||
testVim('dl_eol', function(cm, vim, helpers) {
|
||||
var curStart = makeCursor(0, 6);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('d', 'l');
|
||||
eq(' word1', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq(' ', register.text);
|
||||
is(!register.linewise);
|
||||
helpers.assertCursorAt(makeCursor(0, 6));
|
||||
}, { value: ' word1 ' });
|
||||
testVim('dl_repeat', function(cm, vim, helpers) {
|
||||
var curStart = makeCursor(0, 0);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('2', 'd', 'l');
|
||||
eq('ord1 ', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq(' w', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(curStart, cm.getCursor());
|
||||
}, { value: ' word1 ' });
|
||||
testVim('dh', function(cm, vim, helpers) {
|
||||
var curStart = makeCursor(0, 3);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('d', 'h');
|
||||
eq(' wrd1 ', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('o', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(offsetCursor(curStart, 0 , -1), cm.getCursor());
|
||||
}, { value: ' word1 ' });
|
||||
testVim('dj', function(cm, vim, helpers) {
|
||||
var curStart = makeCursor(0, 3);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('d', 'j');
|
||||
eq(' word3', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq(' word1\nword2\n', register.text);
|
||||
is(register.linewise);
|
||||
eqPos(makeCursor(0, 1), cm.getCursor());
|
||||
}, { value: ' word1\nword2\n word3' });
|
||||
testVim('dj_end_of_document', function(cm, vim, helpers) {
|
||||
var curStart = makeCursor(0, 3);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('d', 'j');
|
||||
eq(' word1 ', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('', register.text);
|
||||
is(!register.linewise);
|
||||
helpers.assertCursorAt(0, 3);
|
||||
}, { value: ' word1 ' });
|
||||
testVim('dk', function(cm, vim, helpers) {
|
||||
var curStart = makeCursor(1, 3);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('d', 'k');
|
||||
eq(' word3', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq(' word1\nword2\n', register.text);
|
||||
is(register.linewise);
|
||||
eqPos(makeCursor(0, 1), cm.getCursor());
|
||||
}, { value: ' word1\nword2\n word3' });
|
||||
testVim('dk_start_of_document', function(cm, vim, helpers) {
|
||||
var curStart = makeCursor(0, 3);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('d', 'k');
|
||||
eq(' word1 ', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('', register.text);
|
||||
is(!register.linewise);
|
||||
helpers.assertCursorAt(0, 3);
|
||||
}, { value: ' word1 ' });
|
||||
testVim('dw_space', function(cm, vim, helpers) {
|
||||
var curStart = makeCursor(0, 0);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('d', 'w');
|
||||
eq('word1 ', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq(' ', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(curStart, cm.getCursor());
|
||||
}, { value: ' word1 ' });
|
||||
testVim('dw_word', function(cm, vim, helpers) {
|
||||
var curStart = makeCursor(0, 1);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('d', 'w');
|
||||
eq(' word2', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('word1 ', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(curStart, cm.getCursor());
|
||||
}, { value: ' word1 word2' });
|
||||
testVim('dw_only_word', function(cm, vim, helpers) {
|
||||
// Test that if there is only 1 word left, dw deletes till the end of the
|
||||
// line.
|
||||
var curStart = makeCursor(0, 1);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('d', 'w');
|
||||
eq(' ', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('word1 ', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(curStart, cm.getCursor());
|
||||
}, { value: ' word1 ' });
|
||||
testVim('dw_eol', function(cm, vim, helpers) {
|
||||
// Assert that dw does not delete the newline if last word to delete is at end
|
||||
// of line.
|
||||
var curStart = makeCursor(0, 1);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('d', 'w');
|
||||
eq(' \nword2', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('word1', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(curStart, cm.getCursor());
|
||||
}, { value: ' word1\nword2' });
|
||||
testVim('dw_repeat', function(cm, vim, helpers) {
|
||||
// Assert that dw does delete newline if it should go to the next line, and
|
||||
// that repeat works properly.
|
||||
var curStart = makeCursor(0, 1);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('d', '2', 'w');
|
||||
eq(' ', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('word1\nword2', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(curStart, cm.getCursor());
|
||||
}, { value: ' word1\nword2' });
|
||||
testVim('d_inclusive', function(cm, vim, helpers) {
|
||||
// Assert that when inclusive is set, the character the cursor is on gets
|
||||
// deleted too.
|
||||
var curStart = makeCursor(0, 1);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('d', 'e');
|
||||
eq(' ', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('word1', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(curStart, cm.getCursor());
|
||||
}, { value: ' word1 ' });
|
||||
testVim('d_reverse', function(cm, vim, helpers) {
|
||||
// Test that deleting in reverse works.
|
||||
cm.setCursor(1, 0);
|
||||
helpers.doKeys('d', 'b');
|
||||
eq(' word2 ', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('word1\n', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(makeCursor(0, 1), cm.getCursor());
|
||||
}, { value: ' word1\nword2 ' });
|
||||
testVim('dd', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 3);
|
||||
var expectedBuffer = cm.getRange({ line: 0, ch: 0 },
|
||||
{ line: 1, ch: 0 });
|
||||
var expectedLineCount = cm.lineCount() - 1;
|
||||
helpers.doKeys('d', 'd');
|
||||
eq(expectedLineCount, cm.lineCount());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq(expectedBuffer, register.text);
|
||||
is(register.linewise);
|
||||
eqPos(makeCursor(0, lines[1].textStart), cm.getCursor());
|
||||
});
|
||||
testVim('dd_prefix_repeat', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 3);
|
||||
var expectedBuffer = cm.getRange({ line: 0, ch: 0 },
|
||||
{ line: 2, ch: 0 });
|
||||
var expectedLineCount = cm.lineCount() - 2;
|
||||
helpers.doKeys('2', 'd', 'd');
|
||||
eq(expectedLineCount, cm.lineCount());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq(expectedBuffer, register.text);
|
||||
is(register.linewise);
|
||||
eqPos(makeCursor(0, lines[2].textStart), cm.getCursor());
|
||||
});
|
||||
testVim('dd_motion_repeat', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 3);
|
||||
var expectedBuffer = cm.getRange({ line: 0, ch: 0 },
|
||||
{ line: 2, ch: 0 });
|
||||
var expectedLineCount = cm.lineCount() - 2;
|
||||
helpers.doKeys('d', '2', 'd');
|
||||
eq(expectedLineCount, cm.lineCount());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq(expectedBuffer, register.text);
|
||||
is(register.linewise);
|
||||
eqPos(makeCursor(0, lines[2].textStart), cm.getCursor());
|
||||
});
|
||||
testVim('dd_multiply_repeat', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 3);
|
||||
var expectedBuffer = cm.getRange({ line: 0, ch: 0 },
|
||||
{ line: 6, ch: 0 });
|
||||
var expectedLineCount = cm.lineCount() - 6;
|
||||
helpers.doKeys('2', 'd', '3', 'd');
|
||||
eq(expectedLineCount, cm.lineCount());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq(expectedBuffer, register.text);
|
||||
is(register.linewise);
|
||||
eqPos(makeCursor(0, lines[6].textStart), cm.getCursor());
|
||||
});
|
||||
// Yank commands should behave the exact same as d commands, expect that nothing
|
||||
// gets deleted.
|
||||
testVim('yw_repeat', function(cm, vim, helpers) {
|
||||
// Assert that yw does yank newline if it should go to the next line, and
|
||||
// that repeat works properly.
|
||||
var curStart = makeCursor(0, 1);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('y', '2', 'w');
|
||||
eq(' word1\nword2', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('word1\nword2', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(curStart, cm.getCursor());
|
||||
}, { value: ' word1\nword2' });
|
||||
testVim('yy_multiply_repeat', function(cm, vim, helpers) {
|
||||
var curStart = makeCursor(0, 3);
|
||||
cm.setCursor(curStart);
|
||||
var expectedBuffer = cm.getRange({ line: 0, ch: 0 },
|
||||
{ line: 6, ch: 0 });
|
||||
var expectedLineCount = cm.lineCount();
|
||||
helpers.doKeys('2', 'y', '3', 'y');
|
||||
eq(expectedLineCount, cm.lineCount());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq(expectedBuffer, register.text);
|
||||
is(register.linewise);
|
||||
eqPos(curStart, cm.getCursor());
|
||||
});
|
||||
// Change commands behave like d commands except that it also enters insert
|
||||
// mode. In addition, when the change is linewise, an additional newline is
|
||||
// inserted so that insert mode starts on that line.
|
||||
testVim('cw_repeat', function(cm, vim, helpers) {
|
||||
// Assert that cw does delete newline if it should go to the next line, and
|
||||
// that repeat works properly.
|
||||
var curStart = makeCursor(0, 1);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('c', '2', 'w');
|
||||
eq(' ', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('word1\nword2', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(curStart, cm.getCursor());
|
||||
eq('vim-insert', cm.getOption('keyMap'));
|
||||
}, { value: ' word1\nword2' });
|
||||
testVim('cc_multiply_repeat', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 3);
|
||||
var expectedBuffer = cm.getRange({ line: 0, ch: 0 },
|
||||
{ line: 6, ch: 0 });
|
||||
var expectedLineCount = cm.lineCount() - 5;
|
||||
helpers.doKeys('2', 'c', '3', 'c');
|
||||
eq(expectedLineCount, cm.lineCount());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq(expectedBuffer, register.text);
|
||||
is(register.linewise);
|
||||
eqPos(makeCursor(0, lines[0].textStart), cm.getCursor());
|
||||
eq('vim-insert', cm.getOption('keyMap'));
|
||||
});
|
||||
// Swapcase commands edit in place and do not modify registers.
|
||||
testVim('g~w_repeat', function(cm, vim, helpers) {
|
||||
// Assert that dw does delete newline if it should go to the next line, and
|
||||
// that repeat works properly.
|
||||
var curStart = makeCursor(0, 1);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('g', '~', '2', 'w');
|
||||
eq(' WORD1\nWORD2', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(curStart, cm.getCursor());
|
||||
}, { value: ' word1\nword2' });
|
||||
testVim('g~g~', function(cm, vim, helpers) {
|
||||
var curStart = makeCursor(0, 3);
|
||||
cm.setCursor(curStart);
|
||||
var expectedLineCount = cm.lineCount();
|
||||
var expectedValue = cm.getValue().toUpperCase();
|
||||
helpers.doKeys('2', 'g', '~', '3', 'g', '~');
|
||||
eq(expectedValue, cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(curStart, cm.getCursor());
|
||||
}, { value: ' word1\nword2\nword3\nword4\nword5\nword6' });
|
||||
testVim('>{motion}', function(cm, vim, helpers) {
|
||||
cm.setCursor(1, 3);
|
||||
var expectedLineCount = cm.lineCount();
|
||||
var expectedValue = ' word1\n word2\nword3 ';
|
||||
helpers.doKeys('>', 'k');
|
||||
eq(expectedValue, cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(makeCursor(0, 3), cm.getCursor());
|
||||
}, { value: ' word1\nword2\nword3 ', indentUnit: 2 });
|
||||
testVim('>>', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 3);
|
||||
var expectedLineCount = cm.lineCount();
|
||||
var expectedValue = ' word1\n word2\nword3 ';
|
||||
helpers.doKeys('2', '>', '>');
|
||||
eq(expectedValue, cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(makeCursor(0, 3), cm.getCursor());
|
||||
}, { value: ' word1\nword2\nword3 ', indentUnit: 2 });
|
||||
testVim('<{motion}', function(cm, vim, helpers) {
|
||||
cm.setCursor(1, 3);
|
||||
var expectedLineCount = cm.lineCount();
|
||||
var expectedValue = ' word1\nword2\nword3 ';
|
||||
helpers.doKeys('<', 'k');
|
||||
eq(expectedValue, cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(makeCursor(0, 1), cm.getCursor());
|
||||
}, { value: ' word1\n word2\nword3 ', indentUnit: 2 });
|
||||
testVim('<<', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 3);
|
||||
var expectedLineCount = cm.lineCount();
|
||||
var expectedValue = ' word1\nword2\nword3 ';
|
||||
helpers.doKeys('2', '<', '<');
|
||||
eq(expectedValue, cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(makeCursor(0, 1), cm.getCursor());
|
||||
}, { value: ' word1\n word2\nword3 ', indentUnit: 2 });
|
||||
|
||||
// Operator-motion tests
|
||||
testVim('D', function(cm, vim, helpers) {
|
||||
var curStart = makeCursor(0, 3);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('D');
|
||||
eq(' wo\nword2\n word3', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('rd1', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(makeCursor(0, 3), cm.getCursor());
|
||||
}, { value: ' word1\nword2\n word3' });
|
||||
testVim('C', function(cm, vim, helpers) {
|
||||
var curStart = makeCursor(0, 3);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('C');
|
||||
eq(' wo\nword2\n word3', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('rd1', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(makeCursor(0, 3), cm.getCursor());
|
||||
eq('vim-insert', cm.getOption('keyMap'));
|
||||
}, { value: ' word1\nword2\n word3' });
|
||||
testVim('Y', function(cm, vim, helpers) {
|
||||
var curStart = makeCursor(0, 3);
|
||||
cm.setCursor(curStart);
|
||||
helpers.doKeys('Y');
|
||||
eq(' word1\nword2\n word3', cm.getValue());
|
||||
var register = helpers.getRegisterController().getRegister();
|
||||
eq('rd1', register.text);
|
||||
is(!register.linewise);
|
||||
eqPos(makeCursor(0, 3), cm.getCursor());
|
||||
}, { value: ' word1\nword2\n word3' });
|
||||
|
||||
// Action tests
|
||||
testVim('a', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 1);
|
||||
helpers.doKeys('a');
|
||||
eqPos(makeCursor(0, 2), cm.getCursor());
|
||||
eq('vim-insert', cm.getOption('keyMap'));
|
||||
});
|
||||
testVim('a_eol', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, lines[0].length - 1);
|
||||
helpers.doKeys('a');
|
||||
helpers.assertCursorAt(makeCursor(0, lines[0].length));
|
||||
eq('vim-insert', cm.getOption('keyMap'));
|
||||
});
|
||||
testVim('i', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 1);
|
||||
helpers.doKeys('i');
|
||||
eqPos(makeCursor(0, 1), cm.getCursor());
|
||||
eq('vim-insert', cm.getOption('keyMap'));
|
||||
});
|
||||
testVim('A', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('A');
|
||||
eqPos(makeCursor(0, lines[0].length), cm.getCursor());
|
||||
eq('vim-insert', cm.getOption('keyMap'));
|
||||
});
|
||||
testVim('I', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 4);
|
||||
helpers.doKeys('I');
|
||||
eqPos(makeCursor(0, lines[0].textStart), cm.getCursor());
|
||||
eq('vim-insert', cm.getOption('keyMap'));
|
||||
});
|
||||
testVim('o', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 4);
|
||||
helpers.doKeys('o');
|
||||
eq('word1\n\nword2', cm.getValue());
|
||||
eqPos(makeCursor(1, 0), cm.getCursor());
|
||||
eq('vim-insert', cm.getOption('keyMap'));
|
||||
}, { value: 'word1\nword2' });
|
||||
testVim('O', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 4);
|
||||
helpers.doKeys('O');
|
||||
eq('\nword1\nword2', cm.getValue());
|
||||
eqPos(makeCursor(0, 0), cm.getCursor());
|
||||
eq('vim-insert', cm.getOption('keyMap'));
|
||||
}, { value: 'word1\nword2' });
|
||||
testVim('J', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 4);
|
||||
helpers.doKeys('J');
|
||||
var expectedValue = 'word1 word2\nword3\n word4';
|
||||
eq(expectedValue, cm.getValue());
|
||||
eqPos(makeCursor(0, expectedValue.indexOf('word2') - 1), cm.getCursor());
|
||||
}, { value: 'word1 \n word2\nword3\n word4' });
|
||||
testVim('J_repeat', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 4);
|
||||
helpers.doKeys('3', 'J');
|
||||
var expectedValue = 'word1 word2 word3\n word4';
|
||||
eq(expectedValue, cm.getValue());
|
||||
eqPos(makeCursor(0, expectedValue.indexOf('word3') - 1), cm.getCursor());
|
||||
}, { value: 'word1 \n word2\nword3\n word4' });
|
||||
testVim('p', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 1);
|
||||
helpers.getRegisterController().pushText('"', 'yank', 'abc\ndef', false);
|
||||
helpers.doKeys('p');
|
||||
eq('__abc\ndef_', cm.getValue());
|
||||
eqPos(makeCursor(1, 2), cm.getCursor());
|
||||
}, { value: '___' });
|
||||
testVim('p_register', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 1);
|
||||
helpers.getRegisterController().getRegister('a').set('abc\ndef', false);
|
||||
helpers.doKeys('"', 'a', 'p');
|
||||
eq('__abc\ndef_', cm.getValue());
|
||||
eqPos(makeCursor(1, 2), cm.getCursor());
|
||||
}, { value: '___' });
|
||||
testVim('p_wrong_register', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 1);
|
||||
helpers.getRegisterController().getRegister('a').set('abc\ndef', false);
|
||||
helpers.doKeys('p');
|
||||
eq('___', cm.getValue());
|
||||
eqPos(makeCursor(0, 1), cm.getCursor());
|
||||
}, { value: '___' });
|
||||
testVim('p_line', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 1);
|
||||
helpers.getRegisterController().pushText('"', 'yank', ' a\nd\n', true);
|
||||
helpers.doKeys('2', 'p');
|
||||
eq('___\n a\nd\n a\nd', cm.getValue());
|
||||
eqPos(makeCursor(1, 2), cm.getCursor());
|
||||
}, { value: '___' });
|
||||
testVim('P', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 1);
|
||||
helpers.getRegisterController().pushText('"', 'yank', 'abc\ndef', false);
|
||||
helpers.doKeys('P');
|
||||
eq('_abc\ndef__', cm.getValue());
|
||||
eqPos(makeCursor(1, 3), cm.getCursor());
|
||||
}, { value: '___' });
|
||||
testVim('P_line', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 1);
|
||||
helpers.getRegisterController().pushText('"', 'yank', ' a\nd\n', true);
|
||||
helpers.doKeys('2', 'P');
|
||||
eq(' a\nd\n a\nd\n___', cm.getValue());
|
||||
eqPos(makeCursor(0, 2), cm.getCursor());
|
||||
}, { value: '___' });
|
||||
testVim('r', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 1);
|
||||
helpers.doKeys('3', 'r', 'u');
|
||||
eq('wuuuet', cm.getValue());
|
||||
eqPos(makeCursor(0, 3), cm.getCursor());
|
||||
}, { value: 'wordet' });
|
||||
testVim('/ and n/N', function(cm, vim, helpers) {
|
||||
cm.openDialog = helpers.fakeOpenDialog('match');
|
||||
helpers.doKeys('/');
|
||||
helpers.assertCursorAt(makeCursor(0, 11));
|
||||
helpers.doKeys('n');
|
||||
helpers.assertCursorAt(makeCursor(1, 6));
|
||||
helpers.doKeys('N');
|
||||
helpers.assertCursorAt(makeCursor(0, 11));
|
||||
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('2', '/');
|
||||
helpers.assertCursorAt(makeCursor(1, 6));
|
||||
}, { value: 'match nope match \n nope Match' });
|
||||
testVim('/_case', function(cm, vim, helpers) {
|
||||
cm.openDialog = helpers.fakeOpenDialog('Match');
|
||||
helpers.doKeys('/');
|
||||
helpers.assertCursorAt(makeCursor(1, 6));
|
||||
}, { value: 'match nope match \n nope Match' });
|
||||
testVim('? and n/N', function(cm, vim, helpers) {
|
||||
cm.openDialog = helpers.fakeOpenDialog('match');
|
||||
helpers.doKeys('?');
|
||||
helpers.assertCursorAt(makeCursor(1, 6));
|
||||
helpers.doKeys('n');
|
||||
helpers.assertCursorAt(makeCursor(0, 11));
|
||||
helpers.doKeys('N');
|
||||
helpers.assertCursorAt(makeCursor(1, 6));
|
||||
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('2', '?');
|
||||
helpers.assertCursorAt(makeCursor(0, 11));
|
||||
}, { value: 'match nope match \n nope Match' });
|
||||
testVim(',/ clearSearchHighlight', function(cm, vim, helpers) {
|
||||
cm.openDialog = helpers.fakeOpenDialog('match');
|
||||
helpers.doKeys('?');
|
||||
helpers.doKeys(',', '/', 'n');
|
||||
helpers.assertCursorAt(0, 11);
|
||||
}, { value: 'match nope match \n nope Match' });
|
||||
testVim('*', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 9);
|
||||
helpers.doKeys('*');
|
||||
helpers.assertCursorAt(makeCursor(0, 22));
|
||||
|
||||
cm.setCursor(0, 9);
|
||||
helpers.doKeys('2', '*');
|
||||
helpers.assertCursorAt(makeCursor(1, 8));
|
||||
}, { value: 'nomatch match nomatch match \nnomatch Match' });
|
||||
testVim('*_no_word', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('*');
|
||||
helpers.assertCursorAt(0, 0);
|
||||
}, { value: ' \n match \n' });
|
||||
testVim('*_symbol', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('*');
|
||||
helpers.assertCursorAt(1, 0);
|
||||
}, { value: ' /}\n/} match \n' });
|
||||
testVim('#', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 9);
|
||||
helpers.doKeys('#');
|
||||
helpers.assertCursorAt(makeCursor(1, 8));
|
||||
|
||||
cm.setCursor(0, 9);
|
||||
helpers.doKeys('2', '#');
|
||||
helpers.assertCursorAt(makeCursor(0, 22));
|
||||
}, { value: 'nomatch match nomatch match \nnomatch Match' });
|
||||
testVim('*_seek', function(cm, vim, helpers) {
|
||||
// Should skip over space and symbols.
|
||||
cm.setCursor(0, 3);
|
||||
helpers.doKeys('*');
|
||||
helpers.assertCursorAt(makeCursor(0, 22));
|
||||
}, { value: ' := match nomatch match \nnomatch Match' });
|
||||
testVim('#', function(cm, vim, helpers) {
|
||||
// Should skip over space and symbols.
|
||||
cm.setCursor(0, 3);
|
||||
helpers.doKeys('#');
|
||||
helpers.assertCursorAt(makeCursor(1, 8));
|
||||
}, { value: ' := match nomatch match \nnomatch Match' });
|
||||
Reference in New Issue
Block a user